Urgent! php with flash arrays

i’m not familiar with php at all and require help from you experts over here asap!

How can i use flash to read variables from a php page, and put them into an array? How must the variables be defined on the php page? Any example codes? Thanks.

use split

for example:


print "&var=hi;bye;cya";

flash:



//ought to work, though untested
var my_lv = new LoadVars();
my_lv.onLoad = function(){
_root.theArr = this.var.split(";");
}
my_lv.load("thePage");

then the variable theArr will have hi at position 0, bye at position 1 and cya at index 2 :slight_smile:

Hi, I’ve done the following

[AS]
playList_lv = new LoadVars();
playList_lv.load(“playlist.txt”);
playList_lv.onLoad = function(){
_root.playList1 = this.playlist.split(";");

}
trace(_root.playList1);
[/AS]

and for playlist.txt:
playlist=a;b;c

trace returns undefined.
but when i place trace inside the onload function,…
[AS]
playList_lv = new LoadVars();
playList_lv.load(“playlist.txt”);
playList_lv.onLoad = function(){
_root.playList1 = this.playlist.split(";");
trace(_root.playList1);
}
[/AS]

trace gives me a,b,c. am i missing out something? i cant seem to access the array from outside onLoad() …

Don’t you have to declare an Array in the flash movie to do this?

Take a look here:


playList_lv = new LoadVars();
playList_lv.load("playlist.txt");
playList_lv.onLoad = function(success){
if(success){
//to make things a little more
//understandable do it like this...
        myPlaylist = this.playlist;
//instead of using a ";" use
//a "|" just to be safe...
_root.playList1 = myPlaylist.split("|");
//this will display the contents of the array...        
trace(_root.playList1);
//this will display the contents of
// each element of the array...
trace("first element is: "+_root.playList1[0]);
trace("first element is: "+_root.playList1[1]);
trace("first element is: "+_root.playList1[2]);
}
}

Also your text file should be something similar to this:


&playlist=fisrtentry|secondentry|thirdentry;

The problem you encoutered with was due to the fact that you placed it outside the LoadVars object. Since you are tracing the _root.playList1, you have to place trace inside the LoadVars object. Flash reads all the code from top to bottom and when trace was executed the LoadVars object was not yet able to completely load the text file thus you get undefined.