FLASH call external file details
Flash loads external files
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.
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.
Load External Images
If your animation contains many images. if they are all placed in a SWF file. it may be slow to open or download. this affects the viewing effect and speed, so you can use the method of loading external images, you just need to put the image in a directory on your Internet by name (the same directory as your SWF file), then this problem can be solved.
The first 10 shards you need to load LOADING. Starting from 11th bytes
Create a new layer named AS Layer
Add a key identifier to the 11th increment of the AS layer, open the action panel, and add the following
I = 0; // initialize the variable
LoadMovie ("p040.jpg", "pic"); // when the original SWF file is played
// Load it to the video clip PIC in Flash Player.
The preceding statement is used to load a file. we need it to load multiple. therefore, the IF statement is used. add a key token to the 60th statement on the as layer, open the action panel, and add the AS statement:
I ++; // variable I increments
If (I> = 21) {// when variable I increments to> = 21. here, 21 is because I have prepared 21 images to be loaded. if you load ten images. then you can change 21 to 10.
I = 0; // The variable is 0, that is, reload
}
LoadMovie ("p04" + I) + ". jpg "," pic "); // if not. then continue loading. here p04 + I is equal to p04i. that is to say, I is a few. here is p04 *. For example, if I is 12, p04 + I is equal to p0412.
GotoAndPlay (12); // jump to 12th bytes
So. when the image file name is given here. we need to follow this principle. the prepared image should be in the same directory as the SWF file called by your master, or you can use an absolute path when loading the image, it should be changed to "http://www.XXXXX.cn/p04" 'target = "_ blank"> http://www.XXXXX.cn/p04 "; + I + ". jpg"
The image size should be adjusted in advance. in the MC for loading the PIC you have prepared. its position is placed in the position where the XY coordinate is 0. The loaded graph is based on the upper left corner of the MC. That is to say, the upper left corner of the loaded graph is coincident with the upper left corner of the loaded MC.
--------------
LoadMovie ("image name", newname );
The preceding syntax is used as follows:
On (release ){
LoadMovie ("pic.jpg", "mc ");
Mc. _ x = 50;
Mc. _ y = 50
Mc. _ xscale = 40;
Mc. _ yscale = 40
}
--------------------------------------------------------------------------------
Three methods for loading external text files
Either way, the text file should be in the same directory as the main file, and the text file name here should be B .txt
* Method 1 txt =
1. Create a text box and give it a variable name txt;
2. The text format is dynamic;
3. Select multiple rows
4. Add the script language on the first frame. (By F9)
LoadVariablesNum ("B .txt", 0); // B .txt indicates the file name, and 0 indicates the root directory in the scenario.
Open the poems.txt file and enter: txt = In the notepad.
Note: convert text files before loading and save them as Unicode encoding formats.
* The second method is to input garbled AS on the master file frame.
Button to reference external text files:
Step 1: first frame at home:
System. useCodePage = true; // prevents garbled characters
Step 2: Write AS on the button:
On (release ){
_ Root. loadVariables ("B .txt"); // B .txt text name
}
** The third method uses the constructor to split the text into several strings for display and fundamentally prevent garbled characters.
That is to say, simply write something in the txt file. The Code is as follows:
Lala = new LoadVars (); // constructor; create a LoadVars object. Then you can use the LoadVars object method to send and load data.
Lala. onData = function (rw) {// triggered when lala is instantiated and displayed on the timeline
A_txt.text = replacePunc (rw );//
};
Function replacePunc (str) {// execute the command to split the text into multiple strings
Var tempArray = str. split ("\ r \ n"); // split the string into multiple substrings.
Var tempstr = new String ();
For (var I = 0; itempstr + = tempArray + newline;
}
Return tempstr;
}
System. useCodepage = true; // notify Flash Player to use the traditional code page to interpret external text
Lala. load ("B .txt ");
I think the third method is better.