0
最近、FlexでSQLiteデータベースを使用する方法を知りました。今、データを正しく表示するのに問題があります。私はいくつかのバインディング戦略を試してきました。私は未定義のプロパティー・エラー、使用不能なエラー、そしてついに!コードは間違いなく!また、表示されていない画像もコード化します。どんな助けもいつものように高く評価されます。 ここまで私のコードです。それをきちんとした状態に保つために、非同期で、私は使用しない変数を2つ残しました。どんな洞察もありがとう。ByteArrayから画像表示Flex - SQLite
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="NM1"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.data.SQLConnection;
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.filesystem.File;
import mx.collections.ArrayCollection;
private var conn:SQLConnection;
private var createStmt:SQLStatement;
private var selectStmt:SQLStatement;
[bindable] private var dataField:ArrayCollection;
[bindable] private var row:Object;
[bindable] private var pngIndex:int;
[bindable] public var pngTitle:String;
[bindable] private var pngByteArray:ByteArray;
private function init():void
{
conn = new SQLConnection();
conn.addEventListener (SQLEvent.OPEN, openSuccess);
conn.addEventListener (SQLErrorEvent.ERROR, openFailure);
var dbFile:File = File.applicationDirectory.resolvePath("assets/NM.sqlite");
conn.openAsync(dbFile);
}
private function openSuccess(event:SQLEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
getData();
}
private function openFailure(event:SQLErrorEvent):void
{
conn.removeEventListener(SQLEvent.OPEN, openSuccess);
conn.removeEventListener(SQLErrorEvent.ERROR, openFailure);
// Make an alert Dialog
// = "Error opening database";
trace("event.error.message:", event.error.message);
trace("event.error.details:", event.error.details);
}
private function getData():void
{
//status = "Loading data";
selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
var sql:String = "SELECT Picture FROM Data WHERE 'Index' = 0";
selectStmt.text = sql;
selectStmt.addEventListener(SQLEvent.RESULT, selectResult);
selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);
selectStmt.execute();
}
private function selectResult(event:SQLEvent):void
{
//status = "Data loaded";
selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
var result:SQLResult = selectStmt.getResult();
// dataField = new ArrayCollection(selectStmt.getResult().data);
if (result.data != null) {
row = result.data[0];
pngIndex = result.data[0].Index;
pngTitle = result.data[0].Title;
pngByteArray = result.data[0].Picture;
Pic.source = pngByteArray;
}
}
private function selectError(event:SQLErrorEvent):void
{
//status = "Error loading data";
selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
trace("SELECT error:", event.error);
trace("event.error.message:", event.error.message);
trace("event.error.details:", event.error.details);
}
]]>
</fx:Script>
<s:Image id="Pic" x="0" y="0" width="263" height="99"/>
<s:TextArea id="text1" x="0" y="313"
/>
EDIT私は自分の画像が表示されない完璧な、エラーのないコードで、今のコードを更新しました。助けて!!
以前にも同様の問題がありました。あなたのbytearrayはどんなフォーマットですか? Image.sourceプロパティは非常に具体的なものを探しています。 –
お返事ありがとうございます。私のイメージはdbの中にPNGとして保存されます。 私はデバッグを見て、2003年にエラーメッセージが表示されていたので、dbを読むのが問題だったと思います。 NS?とにかく、SELECT * FROM Dataに変更された "SELECT Index、title、Picture FROM Data"の行について、 "RangeError:Error#2006:指定されたインデックスが範囲外です"というエラーが発生しました。 – SQLiteNoob
Flash Builderでコードエラーが発生しないようにSQLite文を修正しましたが、dbからSELECT文で1つのフィールドだけを選択した場合でもテキストコントロールを設定することはできません。何か案は? – SQLiteNoob