0
我最近想出瞭如何在Flex中使用SQLite數據庫。現在我無法正確顯示數據。我已經嘗試了幾種綁定策略,而且我已經很少提及。我有未定義的屬性錯誤,無法使用的錯誤,最後!代碼沒有錯誤!此外,沒有顯示圖像的代碼。任何幫助一如既往地受到讚賞。 這是我的代碼到目前爲止;試圖保持它的整潔,異步,我已經留下了一個未使用的變量或兩個從我搞亂它。感謝您的任何見解。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"
/>
編輯我現在已經更新了代碼,具有完善的,沒有錯誤的代碼,不顯示我的形象。幫幫我!!
我以前有過類似的問題。你的bytearray進來的格式是什麼? Image.source屬性正在尋找非常具體的東西。 –
感謝您的回覆。我的圖像在數據庫中保存爲PNG。 我認爲這是一個閱讀數據庫的問題,因爲我看着調試,並有一個錯誤消息,2003年 - 一個接近錯誤? NS?無論如何,這是關於「SELECT索引,標題,圖片從數據」行,我改爲SELECT * FROM數據,現在錯誤是「RangeError:Error#2006:提供的索引超出範圍。」 – SQLiteNoob
我修改了SQLite語句,以便在Flash Builder中沒有代碼錯誤,但是當我從數據庫的SELECT語句中只選擇一個字段時,我甚至無法填充文本控件。有任何想法嗎? – SQLiteNoob