There are several tutorials in this site that cover how to load data from an external location. But, there are no tutorials on this site that discuss how to format and process your data for any use greater than displaying them as a string in a textField.
Unlike XML data which can be formatted extensively in Flash using Flash's own built-in accessors, the data I will focus on will be for less structured output that you would encounter most when loading variables from a text file or simple PHP scripts.
The following URL is an example of data that you will import into Flash: http://www.kirupa.com/developer/mx2004/pg/files.php Beyond just importing the data, I want to take the series of filenames produced by the above PHP file and store those individual filenames in an array in Flash.
The data from the above URL is a series of images separated by a comma, and all of that data is assigned to the variable, filelist. If you use a simple LoadVars call, the data will be displayed as a string by default. A string is great for simply displaying data, but it doesn't help us when we are trying to organize our data in some way.
What we need to do is take our string and separate it into values that can be stored in an array for use in Flash. Let's do that! First, create a new animation in Flash, and copy and paste the following code into the first frame of your animation:
Press Ctrl + Enter to test the movie within Flash. Notice that the long list of data you saw from visiting the earlier URL is now broken down and displayed individually in your Flash Output window.
The format of the code should be familiar to you from the earlier external data tutorial, so I will only focus only the portions that are directly relevant to this tutorial:
If you recall, our data from the PHP file is stored in a variable called filelist. Therefore, this.filelist contained inside the onLoad function stores all of that data, which I assign to the fl variable.
I store the array from our split function into the new array variable called files. Notice that I declare the variable files as an array above our loadVars() function.
This line of code is simply a for loop that I use to demonstrate that data from our text-based PHP script is indeed being parsed and displayed individually in Flash. I trace the individual elements in our array using the representation of the index position, the variable i.
Ideally, you would use your own variation of code to access the data from your array for more useful purposes besides simply tracing to the Flash output window.
|
|
PHP Code for Displaying Files in a Directory | |
|
||
That is all there is to this tutorial. The main thing I want you to understand is that Flash only cares about the final output of the data you are loading. It does not have a way of actually accessing the underlying code that makes up your cgi/php/etc. scripts. To Flash, a PHP file is the same as TXT file.
What complicates your job is to ensure that the output produced by the scripts is in a form that Flash can read. The variable=[data1,data2,data3,...,dataN] format is great for storing the variable information as an array. Since Flash loads the data as a string, you can use all of Flash's string manipulation functions to process that data, and that is what we did!
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

:: Copyright KIRUPA 2026 //--