Groups | Blog | Home
all groups > flash data integration > march 2007 >

flash data integration : passing variables from a php file into an array


leaguer44
3/21/2007 2:12:57 AM
hey guys,

i have successfully created a php file that reads and echoes the contents of a
directory in the string

var1=value2&var2-value2...

how would i got about passing these values into an array?
BorosAdam
3/21/2007 4:52:32 PM
you pass all the values as a huge string each value separated with a special
'separator' like '****' for example and then you can split the string in
flash... like this:
in php you have this string to pass to flash:
mydata=value1****value2****value3****value4 (and so on)
than in flash:
var myArray:Array = mydata.split("****");

is it enough? clear now?

adam
leaguer44
3/21/2007 5:29:26 PM
thanks for the tip but when i try to trace the array to see if it was created
it says "undefined"


_root.createTextField("txtPos", 1, 5, 40, 100, 20);

var myData:LoadVars = new LoadVars();

myData.onLoad = function(success:Boolean){

if(success) {

var myArray:Array = this.split("****");
trace(myArray);

} else {

txtPos.text = "Error loading data";

}

}

myData.load("http://localhost/readdir.php");
BorosAdam
3/22/2007 12:00:00 AM
yes, because you try to split the LoadVars object! watch, you write:
myData.onLoad.... and then: this.split... in this case the word 'this' refers
to myData but your string is INSIDE myData! for example if you write in php:
stringed=value1****value2****value3... and so on, then in flash:

myData.onLoad = function (ok){
if (ok){
trace(myData.stringed);
var myArray:Array = myData.stringed.split("****"); //or you can use:
this.stringed...
}
}

because the received variable ("stringed" in the example) is placed INSIDE the
LoadVars object!!! clear? :)

adam
leaguer44
3/22/2007 3:04:54 PM
makes sense...thanks...and i got it working but i have another question

so the only way i can reference that array data is by putting the code that
needs to use that data inside that If statement that checks if it was loaded
successfully?...or is there away to make the array global?
AddThis Social Bookmark Button