The debut of FLASH MX (FLASH6) gives flashers another reason to faint, because her new face makes us excited.
1. Let’s start with the new functions of MX.
After entering the MX development interface, click Help=>Samples in the menu bar, and a web page will open. These Samples in the leaves can let us feel the new functions of MX. Next, click the "Feature highlight: Load images" link in the leaf. We saw 5 pictures of marine life in this animation (Passenger A: So what if we saw it?). The difference from the past is that these 5 pictures were not compiled together with this swf file (Passenger B: Definitely It is the external swf of "loadMovie", which is rare and strange), and it is not the external swf called, but the 5 external jpg image files of "loadMovie". It is precisely because MX has expanded the "loadMovie" command that I have the honor to write this tutorial ^_^.
Open MX's online help and you can find MX's detailed description of "loadMovie". The first sentence of the "Parameters" section, "url The absolute or relative URL of the SWF file or JPEG file to be loaded." is the finishing touch. Pointed out: The current "loadMovie" can not only load external swf, but also load external jpg image files. Today, when jpg format images are very popular on the Internet, we must say that this is excellent news.
Let's go back and look at MX's Description of this "Sea Life" animation example: "This sample demonstrates how you can load images from a drive or server into a movie at runtime. There are no images in the library of the source file for "This sample." Yes, the "loadMovie" of this "marine life" image browser are all jpg images of the local "drive", and the file name list of the jpg images has been defined in advance.
A small problem arises from this: If there is a "daliang.jpg" file in the defined file name list, but one day, this file unfortunately disappears in the "drive or server", when "loadMovie" is used again, how can Nothing can go wrong, so what? !:~(, don’t cry, let’s find a solution together:)
(Lurenbing: If a current file name list can be dynamically generated every time "loadMovie" is used, everything will be fine. Daliang: That’s right) Every time When running animation, a list of current jpg image file names can be dynamically generated, which can solve the above problem.
However, it is not easy to dynamically generate a list of file names in the local "drive". However, we can also know from the Description of this "Sea Life" animation: MX's "loadMovie" can also dynamically load images from the server side. into a "Movie Chip". So, we will think again: using some "server" side languages, we can easily and dynamically generate a "server" side jpg image file name list.
2. Concept
In summary, we know that this MX image browser will run on the network, and there must be a background program on the "server" side that dynamically generates a list of jpg image file names on the "server" side. , these jpg image files must also be placed on the "server" side.
Whenever this MX image browser is run, it will always use the "loadVariables" method to request the SERVER to return a list of current image files on the "server" side, and then the MX image browser can "loadMovie" these jpg files in sequence. image file.
We will choose ASP as the backend support because it is very convenient to use it to traverse the "server" side files.
In order to make this tutorial easy to understand, the background ASP files and all jpg image files are placed in the same directory on the "server" side.
This is the concept of the entire program. Below we will implement the MX image browser in detail.
3. Specific implementation
1. The ASP part
starts with the ASP in the background, because the MX image browser we are going to develop will know the jpg file list of the current directory on the "server" side through ASP. The following imagebrowse.asp file can realize the function of dynamically generating a list of jpg file names:
|
This ASP only has a dozen or so sentences, so it's very simple. I believe that experienced flashers will be able to understand this ASP quickly.
Assume that the directory where the ASP file is located contains two jpg files "one.jpg" and "two.jpg". If you run this ASP program alone, in the web browser, the following file name list will be returned:
&image1= two.jpg&image2=one.jpg&total=2Everything
starting with "&" is a variable name, and "=" is followed by the value of the variable, because this is the format specified by Flash using "loadVariables" to read external variables.
The ASP part of the background has been completed. Let's take a look at how to make things in FLASH.
2. Inthe FLASH part
, first open FLASH MX, place two Dynamic Text variables named "text" and "test" in the main scene, and enter the "loading..." string in "test" (indicating that it is reading take the list). Among them, "text" is used to display the name of the jpg file being browsed, and "test" is used to display some other related information.
Then create a Movie Chip instance named "imageview" and a button instance named "display" in the main scene. Each time this button is pressed, the "loadMovie" incoming jpg image will be displayed in "imageview".
Then create a Movie Chip consisting of 3 frames named "finder" in the main scene. Its function is to ask the server for a list of jpg image file names in the current directory. It will not stop at the second frame until the answer is obtained. run. The Action Scripts of these three frames are:
Action Script of the first frame:
|
Action Script of the second frame:
|
Action Script of the third frame:
gotoAndPlay(2); //How to control the display of the image
|
Next, it's time to give the "display" button a soul.
Return to the main scene and add the following Action Script to the first frame of the main scene (the main scene has only one frame):
|
So far, the things in the FLASH part have been completed. After compiling and outputting the swf file, the entire program is declared complete!
3. Test
This article assumes that the ASP file and all jpg files are in the root directory of the WEB server.
I don’t know how this program runs? Let's test it:
first place some jpg image files randomly in the root directory of the WEB server, then use Flash Player or a web browser to open the swf file you just made, and wait until the "loading" button appears in the "test" text box. ..." After the string disappears, we can browse these jpg images by clicking the "display" button.
4. Summary
The new technology of FLASH MX can be combined with some programs like ASP to make FLASH more dazzling.
This article is just a tutorial after all. In order for readers to quickly master its essentials, the function of this MX image browser cannot be simpler. If you want to use it in practice, you need to make some improvements to this program. For example: due to bandwidth limitations, when "loadMovie" a large image, you need to add the image preloader program in FLASH so that the "silly waiting" phenomenon no longer occurs; when "loadMovie" comes in When the size of the image is large or small, you need to add a program that automatically adjusts its size; make appropriate improvements to the ASP program and FLASH parts so that they are not limited to browsing the directory where the "imagebrowse.asp" file is located. images; by making appropriate improvements to the FLASH part, it can perform some simple processing on the images coming in from "loadMovie", such as size scaling, color adjustment, simple deformation, etc. (After verification, the above ideas can be realized, but Daliang is too lazy to do it. Everyone must work hard! Work hard! Don’t be lazy with Daliang^_^)
Finally, after reading this article, I wish you all to create the most dazzling FLASH MX online image browser on the Internet. Don’t forget to tell Da Liang your good news and ideas.
Okay, that’s all, see you later!
Due to the limited level of Da Liang, there are inevitably some omissions. Friends are welcome to criticize and correct them.