How to load external files in Flash

Source: Internet
Author: User

Flash can call external files through frames, buttons, and video clips. The called external files include: External text files, external program files, external *. swf files, external image files, external music files, and external script files. The following is a summary:
[LoadMovieNum () function]
[Usage]: loadMovieNum ("url", level [, variables])
[Function]: function. When playing the originally loaded SWF file, it loads the SWF file or JPEG file to a certain level in Flash Player.
[Parameter]: first, we can see that the function has three parameters: url, target, and variables. The last parameter variables is an optional parameter.
1. Parameter url: the absolute or relative URL (PATH) of the SWF or JPEG file to be loaded ).
This parameter of this function is exactly the same as the usage of this parameter in loadMovie above, and will not be explained here.
2. Parameter level: an integer that specifies the level in which the SWF file will be loaded to Flash Player. When loading, you can write as follows:
LoadMovieNum ("01.swf", 1 );
LoadMovieNum ("02.swf", 2 );
LoadMovieNum ("03.swf", 3 );
[LoadMovieNum control after loading]
It can be used as follows:
_ Level1. _ x = 10;
_ Level2.aa. _ alpha = 50;
_ Level3.aa. bb. _ width = 110;
_ Level4.mysound. stop (); // loads to an object of Level 4 MC: mysound stop (playing music)
Note that only one SWF or JPEG file can exist at each level. If the two SWF or JPEG files have the same level, the latter will replace the former. If the level is different, the level of the level will overwrite the level of the small, that is, the number is larger than the number (for example, 03.swfis above 02.swfand 01.swf, and 02.swfis above 01.swf ).
Note: If the SWF file is loaded to level 0, each level in Flash Player is detached and level 0 is replaced with the new file. The SWF file at level 0 sets the frame frequency, background color, and frame size for all other loaded SWF files. For example:
LoadMovieNum ("00.swf", 0); // The image is not displayed at the bottom. This sample only has a 00.swf
LoadMovieNum ("01.swf", 1 );
LoadMovieNum ("02.swf", 2 );
LoadMovieNum ("03.swf", 3 );
3. parameter variables: an optional parameter that specifies the HTTP method used to send the variable. This parameter must be a string of GET or POST. This parameter is omitted if no variable is to be sent. The GET method appends a variable to the end of the URL, which is used to send a small number of variables. The POST method sends a variable in a separate HTTP header, which is used to send a large number of variables.
[LoadMovieNum () uninstallation]
You can use unloadMovieNum () to delete SWF files or images loaded with loadMovieNum.
Usage: unloadMovieNum (level)
Parameter: The level (_ levelN) of the video to which the level is loaded ).
For example, on (release ){
UnloadMovieNum (1200); // as follows: unloadMovieNum (_ level1200); undetachable
LoadMovieNum ("sje.swf", 1200)
}
[LoadMovieNum () Positioning]
As we have already learned, the loadMovieNum function loads SWF or JPEG files to a level. And it is located by _ level1. _ x, _ level2. _ x, _ level1.aa. _ x, and so on. For example, to load 02.swf to the coordinate system (50,100) of the main scenario, the Code is as follows:
LoadMovieNum ("02.swf", 1); // it is very likely that it cannot be located as expected
_ Level1. _ x = 50;
_ Level1. _ y = 100;
But at the test time, everyone will find that the imported 02.swf does not appear in the (50,100) Coordinate System of the main scene as we expected. Why?
It turns out that before loadMovieNum was used, all graphics, MC, and so on were in _ level0. We usually use _ root instead of _ level0. You can perform a test: trace (_ root = _ level0). You will find that the return value is "true ".
Then, when we use loadMovieNum to load SWF or JPEG files, the program will create the _ level you specified, and then load the SWF or JPEG files. If the attribute is called without determining whether _ level exists, as I wrote in the code just now, it is bound to be reactive.
The solution is also very simple, that is, to use a loop to determine whether the specified _ level exists. Once _ level is generated, all its attributes can be called. The Code is as follows:
LoadMovieNum ("02.swf", 1); // locate as expected
OnEnterFrame = function (){
If (_ level1 ){
With (_ level1 ){
_ X = 50;
_ Y = 100;
}
Delete onEnterFrame;
}
};
Or: (The above is better)
LoadMovieNum ("02.swf", 1 );
Function go (){
If (_ level1 ){
With (_ level1 ){
_ X = 50;
_ Y = 100;
}
ClearInterval (fps); // clear the call to setInterval ()
}
}
Fps = setInterval (go, 100); // call a function, method, or object at a specified time
Alternatively, you can use the movi1_loader class in Macromedia Flash MX 2004 to determine the loading status.
[Note] the greater the value of depth, the more content it loads, that is, the lower it is, and the lower it is, and it is overwritten. This is opposite to level identifier _ levelN, in _ levelN, the greater the value of N, the more forward the loaded content, that is, the more at the upper layer and above.
[LoadMovieNum () protects your work-use different extensions]
But what should be better off is that the extension of the film to be loaded does not have to be named in. swf! Although the loaded film is also in the temporary IE folder, it is already in a custom file format, which can protect it!
For example:
LoadMovieNum ("feng.exe", 0); // change the extension to ---> feng.exe
/*
LoadMovieNum ("feng.txt", 0); // change the extension to ---> feng.txt
LoadMovieNum ("feng.doc", 0); // change the extension to ---> feng.doc to load
LoadMovieNum ("feng. abcde", 0); // change the feng.swf extension to ---> feng. abcde Load
LoadMovieNum ("feng", 0); // Delete the extension ---> feng Load
*/
Another one!
<<
1. Call an external text file: (the text file must start with the variable name of the dynamic text box in flash, as shown in
Msg = "......" in this format, it should be placed in the same directory as the Flash file to be edited)
1. Use the text tool in the toolbox to select Dynamic text and give the dynamic text a variable name, for example, msg. Drag a text box in the editing area.
2. Create two buttons (one call and one clear) and drag and drop them to the scene.
3. Call the button to add:
On (release) {// release the mouse and execute the following code;
LoadVariables ("msg.txt", msg); // call the msg.txt text file in the same directory as your edited FLASH file to the dynamic text msg;
System. useCodepage = true; // display the Chinese characters of the external file correctly;
}
4. Clear the AS on the button:
On (release) {// clear the content in the dynamic text box after you release the mouse;
Msg = "";
}
5. Ctrl + Enter test.
Of course, the code can also be written on the frame: (call the Instance name of the twist is bt1, and clear the Instance name of the twist is bt2)
Add the following code to the first frame:
Stop ();
_ Root. bt1.onRelease = function (){
LoadVariables ("msg.txt", msg );
System. useCodepage = true;
}
_ Root. bt2.onRelease = function (){
_ Root. msg = "";
}
Ctrl + Enter test.
The called external text file can be rolled:
1. Use the text tool in the toolbox to select Dynamic text and give the dynamic text a variable name, for example, msg. Drag a text box in the editing area.
2. Create a new layer, create two buttons (one call, one clear), and drag and drop them to this layer.
3. create a new layer, and draw a vertical bar on the right of the dynamic text box with a rectangular tool. The height is the same as that of the dynamic text box. then create an upward direction "Arrow" and press F8 to convert it into a torsion element; copy an arrow and vertical image to align the two buttons with the two sides of the vertical bar.
4. Call the AS on the button:
On (release) {// release the mouse and execute the following code;
LoadVariables ("msg1.txt", msg); // call the msg1.txt text file to the dynamic text box msg;
System. useCodepage = true; // display the Chinese characters of the external file correctly;
}
Clear the AS on the button:
On (release ){
_ Root. msg = ""; // clear the content in the dynamic text box;
}
AS on the Up button:
On (press) {// execute the following code every time you press the mouse in the twisted sensing area;
_ Root. msg. scroll = _ root. msg. scroll-1; // scroll down a line;
}
AS:
On (press) {// execute the following code every time you press the mouse in the twisted sensing area;
_ Root. msg. scroll = _ root. msg. scroll + 1; // scroll up a line;
}
Ctrl + Enter test.
Of course, the code can also be written on the frame: (the name of the instance to which the call is twisted is bt1, the name of the instance to which the call is twisted is bt2, and the name of the instance to be twisted is up, the instance name is down)
Add the following code to the first frame:
_ Root. bt1.onRelease = function () {// release the mouse and execute the following code;
LoadVariables ("msg1.txt", msg); // call the msg1.txt text file to the dynamic text box msg;
System. useCodepage = true; // display the Chinese characters of the external file correctly;
}
_ Root. bt2.onRelease = function () {// release the mouse and execute
_ Root. msg = ""; // clear the content in the dynamic text box;
}
_ Root. up. onPress = function () {// execute the following code every time you press the mouse to the top of the page;
_ Root. msg. scroll = _ root. msg. scroll-1; // scroll down a line;
}
_ Root. down. onPress = function () {// execute the following code every time you press the mouse down;
_ Root. msg. scroll = _ root. msg. scroll + 1; // scroll up a line;
}
Ctrl + Enter test.
2. Call the external *. swf file (loaded to the video clip ):
The external *. swf file and the edited Flash file should be placed in the same directory
1. Create an empty video clip mymc and place it in the scenario. The instance name is mymc.
2. Create a new layer, create two buttons (one call, one clear), and drag and drop them to this layer.
3. Call the AS on the button:
On (release) {// execute the following code after the mouse leaves the button;
LoadMovie ("flash8.swf", "mymc"); // load the external "flash8.swf" file to the "mymc" Empty video clip;
Mymc. _ x = 70; // load the x axis coordinate of the video;
Mymc. _ y = 20; // load the y axis of the video;
Mymc. _ xscale = 70; // load the width of the video;
Mymc. _ yscale = 70; // The height of the loaded video;
}
Clear the AS on the button:
On (release) {// run the following code after the mouse leaves the button
UnloadMovie (mymc); // Delete the *. swf file loaded with loadMovie;
}
Ctrl + Enter Test
3. Call the external *. swf file (loaded to the timeline ):
The external *. swf file and the edited Flash file should be placed in the same directory
1. Create two buttons (one call, one clear) and drag and drop them to the scene.
2. Call the AS on the button:
On (release) {// run the following code after the mouse leaves the button
LoadMovie ("flash8.swf", 1); // load the external "flash8.swf" file to the scene, layer depth 1;
}
Clear the AS on the button:
On (release) {// run the following code after the mouse leaves the button
UnloadMovie (1); // Delete layer depth 1 The "flash8.swf" file loaded with loadMovie
}
Ctrl + Enter test.
Of course, two and three codes can be written on frames.
4. Call external images (loaded into video clips)
The external image and the Flash file being edited must be placed in the same directory.
1. Create two buttons (one call, one clear) and drag and drop them to the scene.
2. Create an empty video clip and drag it to the scene. The instance name is mymc;
3. AS on the first frame of the timeline:
I = 0; // defines a variable I and assigns an initial value of 0;
Call the AS on the button:
On (release) {// execute the following code after the mouse leaves the button;
I ++;
If (I> 9) {// else );
I = 1;
}
LoadMovie ("j" + I) + ". jgp", mymc); // load the image from j1.jpg to mymc;
Mymc. _ x = 110; // set the attributes of the image to be loaded.
Mymc. _ y = 35;
Mymc. _ xscale = 130;
Mymc. _ yscale = 130;
}
Clear the AS on the button:
On (release ){
UnloadMovie (mymc); // Delete the image loaded to the video clip with loadMovie;
}
Ctrl + Enter test.
Of course, AS can be written on frames.
5. Call an external sound file (load the file to the scene)
The external sound file must be in the same directory as the Flash file being edited.
1. Create two buttons (one call, one clear) and drag and drop them to the scene.
2. Call the AS on the button:
On (release) {// execute the following code after the mouse leaves the button;
MySound = new Sound (); // create a new Sound object mySound;
MySound. loadSound ("zaihunivity", true); // Load External *. mp3 audio files are transmitted to the mySound object and played in the stream mode (when the parameter is false, it is played after loading );
}
Clear the AS on the button:
On (release ){
MySound. stop (); // when you press the Clear button to stop playing the sound
}
Ctrl + Enter test.

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.