Skip to main content
May 9, 2010
Question

Issue with retrieving variables

  • May 9, 2010
  • 1 reply
  • 351 views

Hi.  Got help with some code on here before.  Basically, it retrieves values from my php page and displays them in my flash movie.  The code I am using is

var n:uint=1;
var tl:MovieClip=this;


try {
     var keyStr:String;
     var valueStr1:String;
     var valueStr2:String;
     var paramObj:Object=LoaderInfo(this.root.loaderInfo).parameters;
     for (keyStr in paramObj) {
          tl["valueStr"+n]=String(paramObj[keyStr]);
          n++;
     }
} catch (error:Error) {
}


myString=valueStr1;
myString1=valueStr2;

The problem is this.  On my html page, I type in two values for the first name and last name, say "Nick" and "Price".  The above method retrieves these values and stores them in two Strings.  I then display them using a text field.  Now sometimes, everything works normal, and variable 1 holds "Nick" and variable 2 holds "Price".  On other occassions however, its the opposite, and variable 1 holds "Price" and variable 2 holds "Nick".  This is a big problem when I come to display them, as they are back to front.

My adding to the text field is straight forward (not all code included, but two text fields are created and each variable added to one of these)

tf.text="To "+myString;

addChild(tf);

tf1.text="Love "+myString1;
addChild(tf1);

I was wondering if this error could be caused by what I am doing above, or how I am assigning the variables to myString and myString1?

cheers

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 9, 2010

use trace(keyStr) to see what flashvars your php is returning.

May 11, 2010

Kool.  Heres a good example.  I switched the variables round so that myString and myString1 are passed the opposite values.  Then, when I uploaded it to the server, it worked how it should.  Now, a few days later, I tried it again on the website, and the names are now back to front again.  Does the code in the first post return them from my php always in the order they are obtained?  From what is going on, it would appear they are being called randomly.  However, I dont know the workings behind it so might be wrong.

kglad
Community Expert
Community Expert
May 11, 2010

for-in loops iterate through an object in random order.

but you should know the keyStr for your variables so this is not an issue.  for example, your flashvars might assigning:

var1="foo";

var2="bar";

and you would use:

tf.text = String(paramObj[var1])+" "+String(paramObj[var2])