Hey!
i’m pretty new to AS3 and i’m having a problem with accessing an array from the timeline. What I’m trying to do is to add sprites from the array that is being created in a class. It goes like this
package
{
import flash.display.MovieClip;
import flash.net.*;
import flash.events.Event;
import flash.display.*;
import flash.events.MouseEvent;
public class ladda extends MovieClip
{
public var xmlLoader:URLLoader;
public var xmlRequest:URLRequest;
public var dataXML:XML;
public var xmlLista:XMLList;
public var picThURL:String;
public var picLaURL:String;
public var infil:String;
public var picThArray:Array = new Array();
public var picLaArray:Array = new Array();
var Container:MovieClip = new MovieClip();
public function ladda(a:String, c:MovieClip):void
{
Container=c;
infil=a;
xmlLoader = new URLLoader();
ladda1();
}
public function ladda1():void
{
xmlRequest = new URLRequest(infil);
xmlLoader.load(xmlRequest);
xmlLoader.addEventListener(Event.COMPLETE, readXML);
}
public function readXML(event:Event):void
{
dataXML = new XML(xmlLoader.data);
xmlLista = dataXML.*;
displayXML();
}
public function displayXML():void
{
for (var i:uint=0; i<xmlLista.length(); i++)
{
var picTh:Sprite = new Sprite();
var picLa:Sprite = new Sprite();
picThURL = xmlLista*.file;
picLaURL = xmlLista*.filela;
var picThLoader:Loader = new Loader();
var picLaLoader:Loader = new Loader();
var picThRequest:URLRequest = new URLRequest(picThURL);
var picLaRequest:URLRequest = new URLRequest(picLaURL);
picThLoader.load(picThRequest);
picLaLoader.load(picLaRequest);
picTh.addChild(picThLoader);
picLa.addChild(picLaLoader);
picThArray*=picTh;
picLaArray*=picLa;
picThArray*.x=80*i+80;
picLaArray*.x=80*i+80;
}
picThLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, klar);
}
public function klar(event:Event):void
{
for (var i:int=0; i<xmlLista.length(); i++)
{
Container.addChild(picThArray*);
}
}
}
}
This class successfully adds the sprites in the picThArray to the stage. But when I try to access a separate sprite in the array from the fla I get a message that its null. The code in the fla is
var test:ladda = new ladda(“data.xml”, container);
trace(test.picThArray[1]);
Cheers