How to load external files in Flash _flash as

Source: Internet
Author: User
Tags setinterval
Flash can invoke external files through frames, buttons, and movie clips. The external files that are invoked include external text files, external program files, external *.swf files, external picture files, external music files, and external script files. The summary is as follows:
"Loadmovienum () function"
[Usage]:loadmovienum ("url", level [, variables])
[function]: a function that loads a SWF file or a JPEG file to a level in Flash player while playing a previously loaded SWF file.
[Parameters]: First we can see that the function has 3 parameters: URL, target, variables. Where the last parameter variables is an optional parameter.
1. Parameter URL: The absolute or relative URL (path) of the SWF file or JPEG file to be loaded.
This parameter of the function is identical to the usage of this parameter in Loadmovie above, and is no longer explained here.
2. Parameter level: An integer that specifies which levels of the SWF file will be loaded into Flash player. When loading, you can write this:
Loadmovienum ("01.swf", 1);
Loadmovienum ("02.swf", 2);
Loadmovienum ("03.swf", 3);
"Loadmovienum-Loaded Control"
You can use this:
_level1._x=10;
_level2.aa._alpha=50;
_level3.aa.bb._width=110;
_level4.mysound.stop ();//load to Level 4 object Mc:mysound stop (play music)
It should be noted that each level can only have one SWF or JPEG file at a time. If two SWF or JPEG files have the same level, the latter replaces the former. Different levels of _level, the level of the large will be covered by the small, that is: the number of large will be in the small number above (as in the example: 03.swf in 02.swf and 01.swf above, 02.swf in the top of 01.swf).
Note: If you load the SWF file to level 0, each level in Flash Player is unloaded, and level 0 is replaced with the new file. A SWF file at level 0 sets the frame frequency, background color, and frame size for all other loaded SWF files. Such as:
Loadmovienum ("00.swf", 0); None of the following are displayed, so there is only one 00.swf
Loadmovienum ("01.swf", 1);
Loadmovienum ("02.swf", 2);
Loadmovienum ("03.swf", 3);
3. Parameter variables: Optional parameter specifying the HTTP method used to send the variable. The parameter must be a string get or POST. If there are no variables to send, this argument is omitted. 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.
Uninstall of "Loadmovienum ()"
Use Unloadmovienum () to delete a SWF file or image loaded with Loadmovienum ().
Usage: Unloadmovienum (level)
Parameters: Level (_leveln) of the movie that is loaded.
For example: On (release) {
Unloadmovienum (1200);//as follows: Unloadmovienum (_level1200); cannot unload
Loadmovienum ("sje.swf", 1200)
}
"Positioning of the Loadmovienum ()"
As we know from the front, the function loadmovienum is to load the SWF or JPEG file into the _level (level). and is used _level1._x, _level2._x, _level1.aa._x and so on to locate. For example, to load 02.swf into the main scene coordinate system (50,100), the code is as follows:
Loadmovienum ("02.swf", 1); Most likely not to be positioned.
_level1. _x = 50;
_level1. _y = 100;
But in the test, you will find that the loaded 02.swf did not appear as we expected in the Home View coordinate system (50,100) position, this is why?
Originally, in the absence of the use of Loadmovienum before, all graphics, MC, etc. are in the _level0, we usually use the _root is actually _level0. You can make a test: trace (_root==_level0), you will find that the return value is "true".
Then, when we use Loadmovienum to load the SWF or JPEG file, the program will create the _level you specify, then load the SWF or JPEG file immediately thereafter. If, as in the code, it is not judged whether _level exists and calls its properties, 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 produced, its properties can naturally be invoked. The code is as follows:
Loadmovienum ("02.swf", 1); Position as desired
Onenterframe = function () {
if (_level1) {
With (_level1) {
_x = 50;
_y = 100;
}
Delete Onenterframe;
}
};
Or: (Better on top)
Loadmovienum ("02.swf", 1);
function Go () {
if (_level1) {
With (_level1) {
_x = 50;
_y = 100;
}
Clearinterval (fps); Clear calls to SetInterval ()
}
}
fps = setinterval (go,100);//Call function, method, or object at every interval
Or you can use the Moviecliploader class in Macromedia Flash MX 2004 to determine the loading status.
"Note" The greater the value of the depth depth, the more the content of its load, that is, the more in the lower, under, is obscured; this is the same as the level identifier _leveln, in _leveln, the greater the N value, the more forward the contents of the load, that is, the higher the upper,
"Loadmovienum () protects your work-using a different extension"
But the bigger thing is that loading the movie's extension does not have to be named with the. swf! Although the loaded movie is also in the temporary folder of IE, but it is a custom file format, which can play a protective role!
For example:
Loadmovienum ("Feng.exe", 0);//load feng.swf change the extension to---> Feng.exe load
/*
Loadmovienum ("Feng.txt", 0); Load feng.swf change extension to---> feng.txt load
Loadmovienum ("Feng.doc", 0); Load feng.swf change extension to---> Feng.doc load
Loadmovienum ("Feng.abcde", 0); Load feng.swf change extension to---> FENG.ABCDE load
Loadmovienum ("Feng", 0); Load feng.swf Remove extension---> Feng load
*/
Another!
<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<
A. Invoke external text file: (The beginning of the text file begins with the variable name of the dynamic text box in Flash, as
Msg= "..." in this form, to be placed in the same directory as the edited Flash file
1. Use the Text tool in the Toolbox, select dynamic text, give dynamic text a variable name, such as: MSG, drag a text box in the edit area
2. Make two press buttons (one call, one purge) and drop them into the scene.
3. Call on the button to add as:
On (release) {//loosen the mouse to execute the following code;
Loadvariables ("Msg.txt", msg)//Invoke the Msg.txt text file in the same directory as the one you edited to the dynamic text msg;
system.usecodepage=true;//to make the Chinese characters in the external file display correctly;
}
4. Clear the button on the as:
On (release) {//loosen the mouse to clear the contents of the dynamic text box;
Msg= "";
}
5.ctrl+enter test.
Of course, the code can also be written on the frame: (call the instance name of the button is BT1, clear the button instance name 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 calling external text file can be scrolled:
1. Use the Text tool in the Toolbox, select dynamic text, give dynamic text a variable name, such as: MSG, drag a text box in the edit area
2. Create a new layer, make two press buttons (one call, one purge) and drop it into this layer
3. Create a new layer and draw a vertical bar with a rectangular tool on the right side of the dynamic text box. The height is the same as the dynamic text; then make an upward direction "arrow" press F8 to press the torsion element; Copy an arrow to press the twist, the vertical mirror image, so that the two buttons and the ends of the vertical bar are aligned.
4. Call the As on the twist:
On (release) {//loosen the mouse to execute the following code;
Loadvariables ("Msg1.txt", msg);//Call Msg1.txt text file to msg in dynamic text box;
system.usecodepage=true;//to make the Chinese characters in the external file display correctly;
}
Clear the As on the button:
On (release) {
_root.msg= to clear the contents of the dynamic text box;
}
Up the button on the as:
On (Press) {///press the button on the sensor area to execute the following code every time;
_root.msg.scroll=_root.msg.scroll-1;//text scrolls down one line;
}
As on the down button:
On (Press) {///press the button on the sensor area to execute the following code every time;
_root.msg.scroll=_root.msg.scroll+1;//text scrolls up one line;
}
Ctrl+enter test.
Of course, the code can also be written on the frame: (call the instance name of the button is BT1, clear the button instance name is BT2, the instance name of the button up is: Up, the instance name on the button down is down)
Add the following code to the first frame:
_root.bt1.onrelease=function () {//release the mouse to execute the following code;
Loadvariables ("Msg1.txt", msg);//Call Msg1.txt text file to msg in dynamic text box;
system.usecodepage=true;//to make the Chinese characters in the external file display correctly;
}
_root.bt2.onrelease=function () {//After releasing the mouse to perform
_root.msg= to clear the contents of the dynamic text box;
}
_root.up.onpress=function () {//press the button up button to execute the following code every time;
_root.msg.scroll=_root.msg.scroll-1;//text scrolls down one line;
}
_root.down.onpress=function () {//On press down button for each mouse to execute the following code;
_root.msg.scroll=_root.msg.scroll+1;//text scrolls up one line;
}
Ctrl+enter test.
Two. Call the external *.swf file (loaded into the movie clip):
External *.swf file to be placed in the same directory as the edited Flash file
1. Create a new empty movie clip mymc, put it in the scene, the instance name is: MYMC.
2. Create a new layer, make two press buttons (one call, one purge) and drop it into this layer
3. Call the As on the twist:
On (release) {//mouse left button to execute the following code;
Loadmovie ("flash8.swf", "MYMC");/load external "flash8.swf" file into "mymc" empty movie clip;
mymc._x=70;//the x-axis coordinates of the movie to load;
mymc._y=20;//load the y-coordinate of the movie;
mymc._xscale=70;//load the width of the movie;
mymc._yscale=70;//load the height of the movie;
}
Clear the As on the button:
On (release) {//mouse left button to execute the following code
Unloadmovie (MYMC);//delete *.swf file loaded with Loadmovie;
}
Ctrl+enter Test
Three. Call the external *.swf file (loaded onto the timeline):
External *.swf file to be placed in the same directory as the edited Flash file
1. Make two presses (one call, one purge) drag and drop into the scene
2. Call the As on the twist:
On (release) {//mouse left button to execute the following code
Loadmovie ("flash8.swf", 1)//Loading external "flash8.swf" file into the scene, layer deep 1;
}
Clear the As on the button:
On (release) {//mouse left button to execute the following code
Unloadmovie (1)//delete layer deep 1 "flash8.swf" File loaded with Loadmovie
}
Ctrl+enter test.
Of course two and three of the code can be written on the frame.
Four. Call the external picture (loaded into the movie clip)
External pictures must be placed in the same directory as the Flash file being edited
1. Make two presses (one call, one purge) drag and drop into the scene
2. Make an empty movie clip, drag 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) {//mouse left button to execute the following code;
i++;
if (i>9) {//Because there are 9 pictures out there, when the variable is greater than 9, let the variable is 1, so that the load of the picture is continuous, that is, each point at a time, to change a picture, wait until the 9th picture, and then click the Twist, then loop to the first picture (J1.jpg to J9.jpg, Because there is no j0.jpg, if i=0, will be prompted not to find j0.jpg);
I=1;
}
Loadmovie (("J" +i) + ". Jgp", MYMC);//start loading pictures from j1.jpg to movie clip mymc;
mymc._x=110;//the properties of the picture to load the following settings
mymc._y=35;
mymc._xscale=130;
mymc._yscale=130;
}
Clear the As on the button:
On (release) {
Unloadmovie (MYMC);//Remove the picture that was loaded with Loadmovie to the movie clip;
}
Ctrl+enter test.
Of course as can be written on the frame.
Five. Call external sound file (load into scene)
External sound files must be in the same directory as the Flash file being edited
1. Make two presses (one call, one purge) drag and drop into the scene
2. Call the As on the twist:
On (release) {//mouse left button to execute the following code;
Mysound=new Sound ()//Create a new sound object mysound;
Mysound.loadsound ("Zaihuni.mp3", true);//load external *.mp3 sound file into Mysound object, and play as stream (when the argument is false, play after loading);
}
Clear the As on the button:
On (release) {
Mysound.stop ()////When the button is pressed, stop the sound playing
}
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.