Model not updating...please help.


the class below model in mvc triad. works fine when businessunits array populated manually( see commented block in constructor). however, when data downloaded mysql database using php script, businessarray not being populated , error(see attached screenshot) thrown. know 'listening/waiting'  download complete before populating businessunits array have no idea how it. please help.

 

package
{
import flash.events.eventdispatcher;
import flash.net.urlloader;
import flash.net.urlrequest;
import flash.events.event;
import flash.net.urlvariables;
import flash.net.urlrequestmethod;
import flash.net.urlloaderdataformat;
public class model extends eventdispatcher implements imodel
{
  protected static var befields:uint = 7;
  private var businessunitsloader:urlloader;
  private var businesz:array;
  protected var businessunits:array;
  protected var chosenbusinessunit:uint;
  //constructor 
  public function model()
  {
   /*
   businessunits = new array();
   businessunits.push({be:0,en:9,cod:"r&d",bem:"research & development",bel:"r&d long",bex:"r&d explanation",beh:"r&d help"});
   businessunits.push({be:0,en:10,cod:"e&t",bem:"educaction & training",bel:"e&t long",bex:"e&t explanation",beh:"e&t help"});
   businessunits.push({be:0,en:2,cod:"binc",bem:"business incubation",bel:"binc long",bex:"binc explanation",beh:"binc help"});
   */
   businessunitsloader = new urlloader();
   businessunitsloader.load(new urlrequest("http://localhost/interactivestrategy/businessunits.php"));
   businessunitsloader.dataformat = urlloaderdataformat.variables;
   businessunitsloader.addeventlistener(event.complete, oncomplete);
   function oncomplete(event:event):void
   {
    businesz = businessunits.data.businessunits.split("*");
    businessunits = new array();
    (var i=0; i<(businesz.length-1)/befields; i++)
    {
     businessunits.push({be:businesz[befields*i+0],en:businesz[befields*i+1],cod:businesz[befi elds*i+2],bem:businesz[befields*i+3],bel:businesz[befields*i+4],bex:businesz[befields*i+5] ,beh:businesz[befields*i+6]});
    }
    businessunits.sorton(["be","cod"],[array.numeric,array.caseinsensitive]);
   }
   this.chosenbusinessunit = 0;
  }
  //methods
  public function getbusinessunitslist():array
  {
   return businessunits;
  }
  public function getbusinessunit( ):uint
  {
   return this.businessunits[chosenbusinessunit].en;
  }
  public function setbusinessunit(index:uint):void
  {
   this.chosenbusinessunit = index;
   this.update( );
  }
  public function getbusinessunitname( ):string
  {
   return this.businessunits[chosenbusinessunit].bem;
  }
  //model updater
  private function update():void
  {
   dispatchevent(new event(event.change));
  }
}
}

the first problem load method executing before add listener , assigning dataformat property:

 


 

package
{
import flash.events.eventdispatcher;
import flash.net.urlloader;
import flash.net.urlrequest;
import flash.events.event;
import flash.net.urlvariables;
import flash.net.urlrequestmethod;
import flash.net.urlloaderdataformat;
public class model extends eventdispatcher implements imodel
{
  protected static var befields:uint = 7;
  private var businessunitsloader:urlloader;
  private var businesz:array;
  protected var businessunits:array;
  protected var chosenbusinessunit:uint;
  //constructor 
  public function model()
  {
   /*
   businessunits = new array();
   businessunits.push({be:0,en:9,cod:"r&d",bem:"research & development",bel:"r&d long",bex:"r&d explanation",beh:"r&d help"});
   businessunits.push({be:0,en:10,cod:"e&t",bem:"educaction & training",bel:"e&t long",bex:"e&t explanation",beh:"e&t help"});
   businessunits.push({be:0,en:2,cod:"binc",bem:"business incubation",bel:"binc long",bex:"binc explanation",beh:"binc help"});
   */
   businessunitsloader = new urlloader();
//   businessunitsloader.load(new urlrequest("http://localhost/interactivestrategy/businessunits.php"));
   businessunitsloader.dataformat = urlloaderdataformat.variables;
   businessunitsloader.addeventlistener(event.complete, oncomplete);  


businessunitsloader.load(new urlrequest("http://localhost/interactivestrategy/businessunits.php"));


   function oncomplete(event:event):void
   {
    businesz = businessunits.data.businessunits.split("*");
    businessunits = new array();
    (var i=0; i<(businesz.length-1)/befields; i++)
    {
     businessunits.push({be:businesz[befields*i+0],en:businesz[befields*i+1],cod:bus inesz[befields*i+2],bem:businesz[befields*i+3],bel:businesz[befields*i+4],bex:bu sinesz[befields*i+5],beh:businesz[befields*i+6]});
    }
    businessunits.sorton(["be","cod"],[array.numeric,array.caseinsensitive]);
   }
   this.chosenbusinessunit = 0;
  }
  //methods
  public function getbusinessunitslist():array
  {
   return businessunits;
  }
  public function getbusinessunit( ):uint
  {
   return this.businessunits[chosenbusinessunit].en;
  }
  public function setbusinessunit(index:uint):void
  {
   this.chosenbusinessunit = index;
   this.update( );
  }
  public function getbusinessunitname( ):string
  {
   return this.businessunits[chosenbusinessunit].bem;
  }
  //model updater
  private function update():void
  {
   dispatchevent(new event(event.change));
  }
}
}



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???