Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : load variables and PHP, help!


TonyDevin
12/13/2005 8:57:53 PM
How do I load variables into Flash from a PHP page WITHOUT saving it to a
DYNAMIC TEXT FIELD? I want to use/call it as _root.variableName or something
similar. (Sorta like FlashVars)

It seems in order to load variables dynamically; I would have to know the
name of each and every variable stored in the text file and create a subsequent
dynamic text field for it. Without a text field, there would be no way to see
the value of the variable. The problem is that I don?t know how many variables
will be in my PHP result.

Even after the text field has been populated, I am unable to retrieve its
value using the text property.

I have also tried using the LoadVars class, but was unable to store the
variables into global variables during the onLoad() function.



Wolf van Ween
12/13/2005 11:57:14 PM
Tony, you must have misunderstood something.
There is no need to have a dynamic text field as long as you don't want to
show the information (in text form) to the user.
If your PHP sends time=830&place=my%20home then a loadVariables() or a
loadVars will construct two variables inside their parent: 'time' which will
contain a string "830" and 'place' with the string "my home". If the parent is
_root you have those variables in _root (but not in _global).
You don't need a text property. They're strings not fields!
Only if you want to show them to the user would you need something like
place_txt.text = place

jinushaun
12/14/2005 4:59:44 PM
This is actually my question that I asked Tony to post for me.

What do you mean 'construct two variables inside the parent?' I've attempted
to trace the loaded variables several times. If my_data is my LoadVar object,
trace(this.place) displays 'my home' during the onLoad() function. However,
when I try to trace my_data.place after the my_data.load() call, I get
undefined.

For clarity:

my_place = "";
my_data = new LoadVars();
my_data.onLoad = function(success)
{
if (success) {
trace(this.place); // displays 'my home'
_root.my_place = this.place;
trace(_root.my_place); // displays 'my home'
trace(this.toString()); // displays 'time=830&place=my%20home'
}
}

my_data.load("somepage.php"); // onLoad() gets called

trace(my_data.place); // dislays 'undefined'
trace(_root.my_place); // displays ''
trace(my_data.toString()); // displays 'onLoad=%5Btype%20Function%5D'
kaeptn-q
12/14/2005 7:29:57 PM
is that kinda your original code?

then no wonder that you get "undefined".
the onLoad-Event is not called when you tell your loadVars.load() - it?s
called after loading is finished and the received string is parsed to vars.

your trace-actions directly after your my_data.load(...) are executed BEFORE
the onLoad-Event fires, because loading is still in progress and the script
doesn?t wait for the loading to be complete before executing the next lines.

try that:

my_data = new LoadVars();
my_data.onLoad = function(success)
{
if (success) {
trace(this.place); // displays 'my home'
_root.my_place = this.place;
trace(_root.my_place); // displays 'my home'
trace(this.toString()); // displays 'time=830&place=my%20home'
}
checkmydata();
}

my_data.load("somepage.php");

checkmydata = function(){
trace(my_data.place);
trace(_root.my_place);
trace(my_data.toString());
}
jinushaun
12/15/2005 12:30:14 AM
Yeah, that's my original code.

Cool. I thought that might've been an issue, but was too lazy to code a
setInterval to repeatedly check for the status of the load. Didn't think
ActionScript was multi-threaded like that
AddThis Social Bookmark Button