# Urgent! php with flash arrays

**URL:** <https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832>\
**Category:** Uncategorized\
**Created:** [December 30, 2003, 12:32pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832 "2003-12-30T12:32:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lira](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lira](https://forum.kirupa.com/u/lira)\
**Post date:** [December 30, 2003, 12:32pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832/1 "2003-12-30T12:32:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2003, 12:53pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832/2 "2003-12-30T12:53:43Z")

</div>

use split

for example:

```php

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

```

flash:

```auto

//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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2003, 2:14pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832/3 "2003-12-30T14:14:53Z")

</div>

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() …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 30, 2003, 3:57pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832/4 "2003-12-30T15:57:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 31, 2003, 5:27pm UTC](https://forum.kirupa.com/t/urgent-php-with-flash-arrays/38832/5 "2003-12-31T17:27:23Z")

</div>

Take a look here:

```auto

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:

```php

&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.
