0 Replies Latest reply on Jan 12, 2011 1:57 PM by Rob-2007



      Hello guys,

      I being trying to populate a dropdown list from a database with no luck. Here is the code I'm working with.



      import flash.data.SQLStatement;
      import flash.errors.SQLError;
      import flash.events.Event;
      import flash.events.SQLErrorEvent;
      import flash.events.SQLEvent;
      import flash.events.TimerEvent;
      import flash.filesystem.File;
      import flash.utils.Timer;
      import mx.collections.ArrayCollection;
      import mx.controls.Alert;
      import mx.utils.ObjectUtil;
      import org.osmf.events.TimeEvent;
      private var sqlc:SQLConnection = new SQLConnection();
      private var sqls:SQLStatement = new SQLStatement();
      private var schedule_dp:ArrayCollection = new ArrayCollection();
      private function start():void{
           var db:File = File.applicationStorageDirectory.resolvePath("softball.db");
           sqlc.addEventListener(SQLEvent.OPEN, db_opened);
           sqlc.addEventListener(SQLErrorEvent.ERROR, error);
           sqls.addEventListener(SQLErrorEvent.ERROR, error);
           sqls.addEventListener(SQLEvent.RESULT, result);
      private function db_opened(e:SQLEvent):void{
           sqls.sqlConnection = sqlc;
           sqls.text = "CREATE TABLE IF NOT EXISTS schedule(scheduleId INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "hTeam INTEGER, vTeam INTEGER, gameDate TEXT, gameTime TEXT);";
      private function addSchedule():void{
           sqls.text = "INSERT INTO schedule(gameDate, gameTime, status) " +
                "VALUES('"+a_gameDate.text+"', '"+a_gameTime.selectedItem+"', '"+a_status.selectedItem+"');";
      private function getSchedule(e:TimerEvent = null):void{
           var timer:Timer = new Timer(10,1);
           timer.addEventListener(TimerEvent.TIMER, getSchedule);
           if ( !sqls.executing ){
                sqls.text = "SELECT t1.tNumber AS hNumber, t2.tNumber AS vNumber, t1.tName AS hTeam, t2.tName AS vTeam, " +
                     "sc.gameDate, sc.gameTime, sc.status " +
                     "FROM schedule sc " +
                     "INNER JOIN teams t1 ON sc.hTeam = t1.teamsId " +
                     "INNER JOIN teams t2 ON sc.vTeam = t2.teamsId " +
                     "ORDER BY gameDate ASC" //TODO - Status
      private function deleteSchedule():void
           sqls.text = "DELETE FROM schedule WHERE scheduleId="+schedule_dp[schedule_dg.selectedIndex].scheduleId;
      private function result(e:SQLEvent):void{
           var schedule:Array = sqls.getResult().data;
           schedule_dp = new ArrayCollection(schedule);
      private function error(e:SQLErrorEvent):void{



      <fx:Script source="../valueObjects/_Schedule.as"/>
      <s:SkinnableContainer id="aForm" styleName="bgBox" y="245">
                          <s:HorizontalLayout gap="5"/>
                     <mx:DateField id="a_gameDate" yearNavigationEnabled="true" color="0x000000"/>
                     <s:DropDownList id="a_gameTime" width="70">
                               <s:ArrayList source="[09:00 AM, 10:00 AM, 11:00 AM]" />
                     <s:DropDownList id="a_vTeam" width="50" dataProvider="{teams_dp}" labelField="tName" />                              
                     <s:DropDownList id="a_hTeam" width="50" dataProvider="{teams_dp}" labelField="tName" />
                     <s:DropDownList id="a_status" width="50">
                               <s:ArrayList source="[TBP, W, L, T, C]" />
                     <s:Button id="a_submit" click="addSchedule()" x="60" y="10" label="H" width="40" height="20"/>
           <s:SkinnableContainer id="dg" height="100%" width="450" y="15">
                     <mx:DataGrid id="schedule_dg" dataProvider="{schedule_dp}" showHeaders="false" height="100%" width="100%">
                               <mx:DataGridColumn width="80" textAlign="left" dataField="gameDate"/>
                               <mx:DataGridColumn width="70" textAlign="left" dataField="gameTime"/>
                               <mx:DataGridColumn width="15" textAlign="left" dataField="vNumber"/>
                               <mx:DataGridColumn width="105" textAlign="left" dataField="vTeam"/>
                               <mx:DataGridColumn width="15" textAlign="left" dataField="hNumber"/>
                               <mx:DataGridColumn width="115" textAlign="left" dataField="hTeam"/>
                               <mx:DataGridColumn width="50" textAlign="left" dataField="status"/>


      Ok, everything works fine but I'm trying to populate two DropDownList from a different table and I can't. teams_dp does not exist yet.

      The table name is teams and I will use it to populate both  DropDownLists a_vTeam and a_hTeam to insert the id in the schedule tables.


      Please Help, thanks