Search code examples
actionscript-3flashurlloaderloadvars

How to get URLLoader data dynamically in AS3?


In an AS3 Flash project I have a .txt file with 90 paramters like:

st75=15&st2=34&st14=3& ...and so on until 90.

They are not even sorted from st1 to st90.

I need to be able to get them in a for loop, like:

for(var i:Number=1; i<=90; i++) {
var stat = myLoader.data."st"+i;
trace("st"+i+" = "+stat);
}

Obviously this will not work, so anybody has any ideea on how to do this?

I've done some searching but I'm afraid I don't even know what keywords to search for.

Thank you.


Solution

  • Change it like this:

    var stats:Object = {};
    for(var i:Number=1; i<=90; i++) {
      if(myLoader.data["st"+i]){
        stats["st"+i] = myLoader.data["st"+i];
        trace("st"+ i + " is: "+stats["st"+i]);
      }
    }
    

    Note the syntax: myLoader.data["st"+i] and not myLoader.data."st"+i