variable as POST key with URLVariables in AS3?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thesmithman
    New Member
    • Aug 2008
    • 37

    variable as POST key with URLVariables in AS3?

    Hello,
    I have an array of data objects that I would like to send from my .swf to a server-side script. I would like to loop through the array and assign a variable key name to each name-value pair, for example:

    Code:
    myVars = new URLVariables;
    for(i in objectArray){
    var keyName = 'obj_' + i;
    myVars.keyName = objectArray[i].data;
    }
    But when I try to use this method, the parser treats 'keyName' as a string.

    Is it possible to do this? or do I have to write a very long switch/case statement?

    Your insight is appreciated!
    many thanks,
    thesmithman
  • Ihsan Faisal
    New Member
    • Dec 2010
    • 1

    #2
    Hi thesmithman,

    So, have you found the solution?
    (I know it's an old thread, hehe.. But I ended up here from google.)

    I didn't find the solution within flash itself, but here is what I did to get it works.

    Instead of setting URLVariables object property, I use its constructor. Since the constructor can only hold one name/value pair, I make a single tricky name/value pair (v) containing all variables.

    Code:
    var fvParameters:Object = LoaderInfo(this.loaderInfo).parameters;
    var key:String;
    var val:String;
    var flashVars:String = "v=";
    
    for (key in fvParameters) {
    	flashVars += key + ":" + String(fvParameters[key]) + ";";
    }
    
    // length-1 to remove last ; character
    urlVariables = new URLVariables(substr.(0, (flashVars.length - 1)));

    On server side I can extract the 'v' variable content, using php:

    Code:
    $v = split(';', $_GET['v']);
    while (list($key, $val) = each($v)) {
        $tmp = split(":", $val);
        $vars[$tmp[0]] = $tmp[1];
    }

    Regards,
    Ihsan.

    Comment

    Working...