Flash calls external array

Source: Internet
Author: User
Tags php file php code php script

There are several tutorials on this website, including how to load data from external locations. However, there is no reference to this guide website to discuss how to format and process your data using any text that is greater than displaying them as a string.

Different XML data can be formatted and widely used with built-in access from Flash memory. I will focus on the structure that will be lower than the output. When you encounter the most variable, load from a text file or a simple PHP script.

The following URL is an example of data that you will import to the flash.

These data are separated by commas (,) from the above URLs. All the data is allocated to the variable filelist. If you use a simple LoadVars call, the data is displayed as the default value of a string. Strings are perfect 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 to store our strings and values separately in the array and use flash memory. Let's do this! First, create a new animation in the flash, copy and paste the following code to the first frame of the animation

Files = new Array ();
Lv = new LoadVars ();
Lv. onLoad = function (){
Fl = this. filelist;
Files = fl. split (",");
C = files. length-1;
For (I = 0; I <c; I ++ ){
Trace (files [I]);
}
};
Lv. load ("http://www.kirupa.com/developer/mx2004/pg/files.php ");
Press Ctrl + Enter to test the Flash movies in the range. Please note that a long string of data you see from the previously Accessed URL is now subdivided and displayed in your personal flash output window.

The format code should be familiar with your tutorial from earlier external data, so I will only focus on some tutorials directly related to this:

Stream = this. filelist;
If you still remember, our data is stored from the PHP file in a variable called filelist. Therefore, this. filelist loads all the data that calls the storage function, and I am allocated to the Florida variable.


--------------------------------------------------------------------------------

FILE = fl. split (",");
In this line of code, my text is converted from our data stream variable to an array with the split function. The split function, in our case, considers the argument character or string that decides to split our data. Since our data is separated by commas (,), I enter a comma to split the data.
The storage array is called a file from our split function to the new array variable. Please note that I declare the variable file as an array higher than our loadVars () function.


--------------------------------------------------------------------------------

C = files. length-1;
I received the length of our archive array using the Flash length function. I ignored the last project. In our array, its value is '0 '. You will see the following explanation of why PHP code is invalid.
For (I = 0; I <c; I ++ ){
Trace (files [I]);
}
This line of code is just a for loop. The data I use shows that the PHP script based on our text is indeed parsed and displays individual flash memory. The various parts of the remaining traces use the representative index position in our array to change the island

Ideally, you will use changes in your code to access data from your array for a more useful purpose in addition to simply tracing to the flash output window.

PHP code shows the file directory
This php file I used (files. php) to retrieve the directories of all the files and output them in the format of [data1, data2, data3,..., Ditan]. You have seen it before.
The PHP file for this code is
<? Php
If ($ handle = opendir ('.')){
Echo "filelist = ";
While (false! ==( $ File = readdir ($ handle ))){
$ Ext = substr (strrchr ($ file, "."), 1 );
If ($ file! = "." & $ File! = ".." & $ Ext = "jpg "){
Echo "$ file ";
Echo ",";
}
}
Closedir ($ handle );
Echo "null ";
}
?>
The code is mainly based on Example 2 from php file: http://www.php.net/manual/en/function.readdir.php. The only difference is that I also convert the dollar value based on the filtering file extension, and I added some Echo commands, our data format method, we need to format it.

When the flash does not look at the actual PHP code, you call the PHP file. It is not only concerned with the output, so it effectively tricks into the production of PHP output Echo commands, it looks like the data type of flash memory can be easily understood.

If you are interested in displaying all files, just delete the $ extension command, if declared, or if you are interested, display another extension of the file, extend "image" to another one.

Finally, I must explain why I echo the data when the null value ends. Note that after I add a comma, the script output for each file name is used. The problem is that the name of the last file is output, and a comma is displayed again.

Your data looks like this:

Variable = [data1, data2, data3,..., Ditan]

Pay attention to the taitan after the comma. Therefore, a null value is added, and the leading comma is not the data below it. The rest safely ignores all items with null value counts, but last year's value flashed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.