0

I've searched averywhere, but can't find an answer that specifically applies to me. I have a AS3 array that is currentely populated manually inside the script and the rest of the code that does something with this array. How can I 'convert' this array to populate using XML without affecting the rest of the code. Code:

var my_info_array:Array = new Array("Info-pdf.swf", "Info2-pdf.swf");
//This first line I want to populate using XML without affecting the code below
var infoURLnow:Number = 0;
var myTimer2:Timer = new Timer(5000);
myTimer2.addEventListener(TimerEvent.TIMER, timerListener);
 function timerListener (e:TimerEvent):void{    
if(infoURLnow != totalInfo) {
    loadINFO();
} 
else {
    infoURLnow = 0;
    loadINFO();
}
}
myTimer2.start();
loadINFO();
function loadINFO(){
var infoLoader:Loader = new Loader();
var infoURL:String = my_info_array[infoURLnow];
var infourl:URLRequest = new URLRequest(infoURL); 
infoLoader.load(infourl);
info_kozel.addChild(infoLoader); 
infoLoader.x = 20;                                        
infoLoader.y = 20; 
infoLoader.scaleX = infoLoader.scaleY =1.25;
infoURLnow = infoURLnow +1;
}

Something like this:

var data:XML = new XML();

var xml_Loader:URLLoader = new URLLoader();
xml_Loader.load(new URLRequest("Info.xml"));

xml_Loader.addEventListener(Event.COMPLETE, do_XML);

Then how do I integrate the above code into do_XML function??

1
  • Can someone show me the complete code? I have tried adjusting different AS3 code from the internet but nothing works. I havee a feeling that it is very simple, but I can't quite get it. Commented Jan 31, 2014 at 18:13

1 Answer 1

1

Try this :

var xml:XML =
    <list>
        <link>Info-pdf.swf</link>
        <link>Info2-pdf.swf</link>
    </list>;

var my_info_array:Array=[];

xml..link.(my_info_array.push(text()));

trace(my_info_array) // Info-pdf.swf,Info2-pdf.swf
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for quick response, but what If I have more than 2 external swfs and need to populate this array without ever opening fla file?
Don't I need to load XML first then parse it so that data is pushed to this array?
@user3258032 Sure , put it all in an external XML and add links as much as you want!
What will the final AS3 code look like? The code above doesn't seem to have an XML loader nor parser.
@user3258032 it is impossible to not affect the rest of the code , cause XML loading is async process , so ideally is to put some stuff in XML' "ready" event' handler
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.