I’m trying to get my local sqlite db to display the next record on the click of a button.
I’ve looked at posts like Getting next record in SQLite database for mobile application, but their code has offered little solution for me. Here is a sample of my code:
AS3:
private function getNext():void
{
nextRecordId = targetRecordId + 1;
selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
var sql:String = "SELECT [Index], Title, CAST(Picture AS ByteArray) AS Picture FROM Data WHERE [Index] = 1" ;
/* selectStmt.parameters[@nextRecordId] = nextRecordId; */ // Id of next record
selectStmt.text = sql;
selectStmt.addEventListener(SQLEvent.RESULT, selectResult2);
selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError2);
selectStmt.execute();
}
private function selectResult2(event:SQLEvent):void
{
selectStmt.removeEventListener(SQLEvent.RESULT, selectResult2);
selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError2);
var result2:SQLResult = selectStmt.getResult();
dataField2 = new ArrayCollection(result2.data);
dp2 = ArrayCollection(dataField);
if (result2.data != null)
{
pngIndex = result2.data[0].Index;
pngTitle = result2.data[0].Title;
pngByteArray = result2.data[0].Picture;
displayPic.source = pngByteArray;
}
}
UI MXML:
<s:Scroller interactionMode="touch"
width="640"
height="830">
<s:Group>
<s:Image id="displayPic"
x="0" y="16"
width="640"
scaleMode="stretch"
smooth="true" smoothingQuality="high"
/>
<!--<s:TextArea x="9" y="731" text="@{pngTitle}"/>-->
</s:Group>
</s:Scroller>
Thanks a lot for the help/advice
I don’t see where you’re having problems with this. Have you tried this thing called google?
As long as you keep that index variable as a class var set at 0 for default, you should be fine until it runs out of rows. Of course, there are other ways of doing this, like getting an array of all rows and have actionscript manage it. This is easier if you don’t have a very large database of information.