Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 4 of 4

Thread: why is my array empty?

  1. #1
    Junior Member Settled In malaclypse is on a distinguished road
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Question why is my array empty?

    amazing Flash templates
    hello everybody

    my problem is realy annoying, i wrote a script and it runs good in the general script of my fla file but now , i wrote a class with this algorythm but the array i need is empty...

    ..here is the script

    PHP Code:
     
    package
    {
     
    import flash.display.Stage;
     
    import flash.net.URLLoader;
     
    import flash.net.URLRequest;
     
    import flash.events.Event;
     
     public class 
    xmlReader
     
    {
      public function 
    xmlReader(FilePath:String)
      {
      
    xmlLDR = new URLLoader();
      
    xmlREQ = new URLRequest(FilePath);
      
    xmlArray = new Array();
     
      
    getFile(xmlLDRxmlREQ);
      }
    //
     
      
    private var xmlLDR:URLLoader;
      private var 
    xmlREQ:URLRequest;
     
      public var 
    xmlArray:Array;  //<<< i need this array as a result of this class 
     
      
    private function getFile(LDR:URLLoaderREQ:URLRequest):void
      
    {
       
    LDR.addEventListener(Event.COMPLETExmlLOADED);
       
    LDR.load(REQ); 
      }
    //getFile
     
      
    private function xmlLOADED(event:Event):void
      
    {
       var 
    hxmlFile:XML = new XML();
       
    hxmlFile XML(event.target.data);
       
    readXML(hxmlFile);
       
    //trace(xmlFile); << xml file is loaded without errors
      
    }//xmlLOADED
     
      
    private function readXML(ixmlFile:XML):void
      
    {
      var 
    hxmlFile:XML ixmlFile;
     
       for(var 
    i:Number 0hxmlFile.child("values").length(); i++)
        {
        
    xmlArray.push([ihxmlFile.values[i].cname.text(), 
                                  
    hxmlFile.values[i].path.text(), 
                                  
    hxmlFile.values[i].desc.text() ]);
        }
    //for
      //trace(xmlArray);  //<<<and the array is filled with the entrys of the xml entrys
      
    }//readXML
     
    }//public class  xmlReader
    }//package 
    PHP Code:
    var xmlFILE:xmlReader = new xmlReader("xml/gallery.xml");
    trace(xmlFILE.xmlArray); //<<< i get no errors or something, he just empty _:confused: 
    puuh! does anyone have an idea whats going wrong, whats the major differences between the classes and the normal script in flash?

    thanks for any advice or hints .. bye

  2. #2
    Member Flash Addict hard_overclocker is on a distinguished road hard_overclocker's Avatar
    Join Date
    Jul 2007
    Posts
    50
    Rep Power
    3

    Re: why is my array empty?

    Hey malaclypse,
    you array is empty because you are accessing it before the xml has been loaded.
    What I do in this case is dispatch an event to know when the xml has been loaded and then you can read your array.

    PHP Code:
    package
    {
    import flash.display.Stage;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.EventDispatcher;

    public class 
    xmlReader extends EventDispatcher
    {
      public function 
    xmlReader(FilePath:String)
      {
      
    xmlLDR = new URLLoader();
      
    xmlREQ = new URLRequest(FilePath);
      
    xmlArray = new Array();

      
    getFile(xmlLDRxmlREQ);
      }
    //

      
    private var xmlLDR:URLLoader;
      private var 
    xmlREQ:URLRequest;

      public var 
    xmlArray:Array;  //<<< i need this array as a result of this class

      
    private function getFile(LDR:URLLoaderREQ:URLRequest):void
      
    {
       
    LDR.addEventListener(Event.COMPLETExmlLOADED);
       
    LDR.load(REQ);
      }
    //getFile

      
    private function xmlLOADED(event:Event):void
      
    {
       var 
    hxmlFile:XML = new XML();
       
    hxmlFile XML(event.target.data);
       
    readXML(hxmlFile);
       
    dispatchEvent(new Event("xmlReady"true));
       
    //trace(xmlFile); << xml file is loaded without errors
      
    }//xmlLOADED

      
    private function readXML(ixmlFile:XML):void
      
    {
      var 
    hxmlFile:XML ixmlFile;
        
    xmlArray.push(ixmlFile);
       
      
    //trace(xmlArray);  //<<<and the array is filled with the entrys of the xml entrys
      
    }//readXML
    }//public class  xmlReader
    }//package 
    PHP Code:
    var xmlFILE:xmlReader = new xmlReader("file.xml");

    xmlFILE.addEventListener("xmlReady"traceXML);

    function 
    traceXML(event:Event):void
    {
        
    trace(xmlFILE.xmlArray); //<<< i get no errors or something, he just empty _:confused: 


  3. #3
    Member Flash Addict hard_overclocker is on a distinguished road hard_overclocker's Avatar
    Join Date
    Jul 2007
    Posts
    50
    Rep Power
    3

    Re: why is my array empty?

    I don't know if this is the best aproach, but it works

  4. #4
    Junior Member Settled In malaclypse is on a distinguished road
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Thumbs up Re: why is my array empty?

    hi ...

    ...thanks alot, you win 10000 internets, the advice with the dispatcher is great! runs perfect!

    mfg

+ Reply to Thread

Similar Threads

  1. array di pulsanti che chiamano array di funzioni
    By chil8 in forum Actionscript 3.0 base
    Replies: 0
    Last Post: 4 Weeks Ago, 17:01
  2. Array
    By domdurakov in forum Actionscript 3.0 base
    Replies: 23
    Last Post: 05-11-09, 11:26
  3. Loading XML file....empty
    By alphasil in forum Actionscript 3.0 newbies
    Replies: 2
    Last Post: 05-10-09, 10:05
  4. Dynamic field empty....help
    By alphasil in forum HELP free utilities
    Replies: 4
    Last Post: 02-10-09, 09:19
  5. Empty shoutbox for comments?
    By jdgrud in forum HELP free utilities
    Replies: 0
    Last Post: 19-12-08, 23:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO