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?
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
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");
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
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?
Don't see what you're looking for? Try a search.
|