A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Incrementin variable names and FlashVars

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2

    Incrementin variable names and FlashVars

    Ok, i know it sounds like the problem that had been done over and over again, but none of the search results helped me solve it.

    I send flashvars to flash. Those variables are one user id variable and unknown number of corresponding friend and relation vars (friend1, friend2, relation1, relation and so on, all the items from DB).

    I get the of course from an object:
    Code:
    var flashVars=this.root.loaderInfo.parameters;
    and check how many friends did the php send to me . There is one user id variable and an even number of friends and relations so the way i check how many mates do i have is:
    Code:
    			for each (var prop in flashVars) {
    				varValueArray.push(prop);
    			}
    			var helpNum = varValueArray.length;
    			mates = (helpNum-1)/2;
    Simple so far. Now, what i need from you guys is help in creating a loop, which would assign meaningful names to those variables. I already have the mates variable which would be used to control the loop, and I want it to look (work?) something like that:
    Code:
    for (var count=1 ; count<=mates ; count++){
         friend>count< = this.root.loaderInfo.parameters.friend>count<
         relation>count<= this.root.loaderInfo.parameters.relation>count<
    }
    Where of course the >count< would be a number incrementing each time the loop is ran.

    Can't get over this one. Please help

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I don't know exactly what your looking for but this may help get you started:

    PHP Code:
    var flashVars this.root.loaderInfo.parameters;
    var 
    mates:Array = [];

    for 
    each (var prop in flashVars)
    {
        
    varValueArray.push(prop);
    }

    var 
    helpNum:int varValueArray.length;
    var 
    nummates:int = (helpNum-1)/2;

    for (var 
    count=count<=nummates count++)
    {
        
    mates['friend'][count] = this.root.loaderInfo.parameters.friend[count];
        
    mates['relation'][count] = this.root.loaderInfo.parameters.relation[count];
    }

    // Then you can reference as so:
    mates['friend'][0// First mates friend
    mates['relation'][0// First mates relation 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center