Reputation: 1076
I'm new to OOP AS 3.0, so.. I have a question.
I have two files Main.as
and LoadTheXML.as
in the LoadTheXML
class I have loadTheXML
function, in there sortXML
function and in there an array picturePathList
that I want to use in Main.as
in Main.as
I have a code that launches the loadTheXML function:
var loadedXML:LoadTheXML = new LoadTheXML(urlVar);
so... In Main.as I'd like to write:
var rand:Number = Math.round(Math.random() * (a - 1));
var mainLoader:Loader = new Loader();
var mainRequest:URLRequest = new URLRequest(picturePathList[rand]);
mainLoader.load(mainRequest);
mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, mainLoaded);
function mainLoaded(e:Event):void {
mainPicPlacementX = (stage.stageWidth / 2) - (mainLoader.width / 2);
so on and so on....
}
How should I call the picturePathList array from LoadTheXML class.
Thanks!!!
HERE I'll put the files - please see, because I didn't get what to do and how... The Files
I want the above mentioned code to be moved to Mainc.as I guess this will have more logic, and anyway I'd like to see how it's done.. If you find some tutorial I'd like to see that too.. Thanks!
Upvotes: 1
Views: 91
Reputation: 2228
In general AS3 is asynchronous; it means, it should not wait for to complete the first statement before it go to the 2nd statement.
So u should listen an event object to check whether the task has been completed or not. You can attain this EventDispatcher object.
So u should dispatch an event object in sortXML
function.
dispatchEvent ( new Event ( Event.COMPLETE ) );
and in the Main.as
.
private function init():void
{
loadedXML = new LoadTheXML(urlVar);
loadedXML.addEventListener ( Event.COMPLETE, handleXMLLoaded );
}
private function handleXMLLoaded (e:Event):void
{
var rand:Number = Math.round(Math.random() * (a - 1));
var mainLoader:Loader = new Loader();
var mainRequest:URLRequest = new URLRequest(loadedXML.picturePathList[rand]);
mainLoader.load(mainRequest);
.....
.....
}
Upvotes: 1
Reputation: 3207
Make your LoadToXML
object's picturePathList
property publicly accesible via a getter method:
public class LoadTheXML
{
private var _picturePathList:Array;
public function get picturePathList():Array
{
return _picturePathList;
}// end function
// ...
}// end class
Upvotes: 2