Complete implementation tutorial of as script loadMovie

Source: Internet
Author: User

With loadMovie, You can dynamically load external files to reduce the volume of the primary file, facilitate online download, and modify and replace various subfiles. If you have not performed a FLASH webpage, you can check the basic composition of the FLASH webpage, as shown in Figure 2-2-1.

You only need to upload the main and sub-files in the figure to your own space using ftp tools, so that you can easily download only the main files. If you need to browse the sub-files, you can download them separately, you can think about it. If your entire FLASH page has a uniform FLASH page with several MB or even more than 10 MB, who would like to watch your webpage? Unless you are yourself.

Therefore, it is very important to use loadMovie. Now let's start with the basics and analyze the specific problems involved in using loadMovie. There are two basic methods to use loadMovie: (1) load an external swf file to a layer. (2) load the external swf file into a video clip on the timeline. The use of these two methods is more intuitive with graphs. See Figure 2-2-2

The second method can be written as follows: _root.mc.loadmovie(+a1.swf "); If a1 is suffixed with jpg, it is loaded with an external image. Loading images is the same as loading swf files. It is still relatively empty here. Let's take a look at it as an example.

1. Create a new folder and take any name, for example, mywangye.

2. Create a Flash file and release it into a swf file named a1. Save it in the mywangye directory. This a1 is the sub-file to be loaded.

3. Next we will make the main file. Because we are the simplest, We will write loadmovie(+a1.swf "in the first commit of this main file. 1) save the file in the mywangye directory and name it index.

Iv. Test results. For the source files, see the 01 folder in the package after this article.

Then, use the 2nd syntaxes shown in the preceding figure to continue. Note that the second method requires a mc on the stage and an Instance name, or an empty MC. What conclusions can we draw from the above small experiment? If you just come to the conclusion that an external file can be loaded, it would be too superficial. We can think of the coordinates of the added external files, the length and width, the loading latency caused by the large size of the external files, and how to access the loaded swf; don't load, uninstall ..... If we do not study these issues, we will encounter a lot of trouble when actually doing Web pages.

From the simplest loading above, we can draw the following conclusion: (1) if loaded to the layer, the registration point is the upper left corner of the stage by default; if it is loaded into mc, the default registration point is the registration point of MC. If the registration point of MC is the upper left corner, the loaded SWF file is aligned with the upper left corner of MC. If the registration point of MC is the center, then, the loaded SWF is aligned with the center of MC in the upper left corner. (2) The loaded MC retains the original length-width ratio.

Question 1: How do I control the coordinates and length/width ratio of the loaded SWF file?

To control the length and width of a loaded SWF file, use onEnterFrame. For example:

On (press ){
LoadMovie ("a2.swf", "_ root. mymc ");
OnEnterFrame = function (){
_ Root. mymc. _ x = 0;
_ Root. mymc. _ y = 0;
_ Root. mymc. _ width = 330;
_ Root. mymc. _ height = 240;
};
}

Why is onEnterFrame used? Because the loading process is a little delayed, if there is no onEnterFrame statement, the statement will not be read once. However, after reading this statement, it has not been loaded yet, therefore, the coordinate size setting is invalid. Similarly, if it is loaded to a layer, the same is true.

On (press ){
LoadMovie ("a1.swf", 1 );
OnEnterFrame = function (){
_ Level1. _ x = 17;
_ Level1. _ y = 30;
_ Level1. _ width = 330;
_ Level1. _ height = 240;
};
}

Note the two methods. The first one is to load external a2 to mymc. After adding it, a2 will automatically replace mymc, we directly set the properties of mymc to set the properties of the loaded swf. In the second method, _ level is a reference to a movie loaded to the timeline. loading to Layer 2 is _ level2, and loading to Layer 2 is _ level3.

Question 2: How can I click the button to load an external SWF file and display the download progress of the file?

There are two ways to achieve this effect. One is to write the loaded londing into the main file, and the other is to write the loaded sub-SWF file with its own londing. Here, we will explain it separately.

1. Write londing in the master file

The external sub-swf file name is a1. The main file has a dynamic text box named loadText and a button named bbt. Now we write loadMovie and londing on the notebook.

_ Root. bbt. onPress = function (){
_ Root. createEmptyMovieClip ("mc", 10 );
Mc. loadMovie ("a1.swf ");
Mc. _ visible = false;
_ Root. bbt. onEnterFrame = function (){
Var l = mc. getBytesLoaded ();
Var t = mc. getBytesTotal ();
Var getPercent = l/t;
LoadText = Math. round (getPercent * 100) + "% ";
If (l> 0 & l> = t ){
Mc. _ visible = true;
Delete this. onEnterFrame;
}
Mc. _ x = 10;
Mc. _ y = 10;
Mc. _ width = 440;
Mc. _ height = 320;
};
};

Second, the sub-file has its own londing.

This statement is the same as the londing mentioned earlier. But pay attention to the path problem, for example:

First Region

Loaded = getBytesLoaded ();
Total = getBytesTotal ();
Lts = Math. round (loaded/total) * 100 );
Wenben = lts + "% ";

Second Region

If (lts = 100 ){
GotoAndStop (3 );
} Else {
GotoAndPlay (1 );
}

Compared with the previous londing, do you see the difference? After _ root is removed, the external SWF file is equivalent to a MC in the main file. _ root is the _ root object pointing to the main file. Of course, an error is displayed.

Question 3: I want to draw a screen on the stage and click a button to load an external swf for playback. What should I do?

Let's create an album together. When the main file is loaded, click the button to load an external swf file with londing displayed. First, make the following preparations: (1) prepare several images. Now we have seven and six sub-files, one for the master file. (2) The size of the main file stage is set to 770*420 to meet the needs of the webpage. Set the stage size of the sub-file to 512*384, so that you do not need to control the size after loading. (In fact, we should do this to save some trouble.

1. Create a subfile. Each image is used to display images. The first and second rows write londing, and the third rows ~~ Twenty brightness changes according to your hobbies to generate a dynamic state, and write stop () in the last segment (). The londing of the first and second shards is as follows:

First Region

Loaded = getBytesLoaded ();
Total = getBytesTotal ();
Lts = Math. round (loaded/total) * 100 );
Wenben = "downloading data" + lts + "% ";

Second Region

If (lts = 100 ){
GotoAndPlay (3 );
} Else {
GotoAndPlay (1 );
}

In this way, six processed products are named b1 ..... All b6 files are published as swf files. Save it in a folder.

Ii. Create the main file

The first notebook is used to write londing. The first notebook puts some things like the screen, and buttons. In order to increase the effect, a music is placed on the timeline.

Londing of the first shard // I will not repeat it because I have already said more.

Stop ();
I = 0 ;,
OnEnterFrame = function (){
// Use continuously triggered events
Loaded = _ root. getBytesLoaded ();
Total = _ root. getBytesTotal ();
Var aa = Math. round (loaded/total) * 100 );
_ Root. dongtai. wenbens = aa + "% ";
_ Root. dongtai. _ x = 188 + aa * 3;
_ Root. bb. _ width = aa * 3;
If (aa >=100 ){
// Jump out when the conditions are detected. Otherwise, continue the loop.
_ Root. gotoAndStop (2 );
Delete this. onEnterFrame;
// Delete is used to destroy the onEnterFrame event after the download is completed to save resource consumption.
}
};

2nd.

On (press ){
_ Root. I ++;
If (I = 7 ){
I = 6;
}
LoadMovie ("B" + I + ". swf", "_ root. mc ");
_ Root. tishi = "" + I + "Images ";
}

If you are a little lazy, we will not go into details about its meaning. We can also use a long statement to achieve the same effect. This method is a concentrated method for.

For details, see the original file.

Question 4: I want to load multiple external files one by one. When the first file is loaded and played, 2nd files are loaded immediately. After the second file is played, 3rd files are loaded immediately ,......, Until the end. What should I do?

First of all, we should first ask the person who asked the question. What is the significance of this? In this case, it is better to implement one SWF, because each time an external SWF is called, it takes some time to wait for download. Of course, if you want to create a series, after playing one, you can still use the londing screen of the next set of londing to display "loading the next set, please wait.

The method is very simple: according to the original file in question 3, modify it a little, remove a button, use a button to load the first one, and then put the last one to call the function in the main file.

Button:

On (press ){
LoadMovie ("b1.swf", "_ root. mc ");
}

Functions defined in the main file

Function go2 (){
LoadMovie ("b2.swf", "_ root. mc ");
}
Function go3 (){
LoadMovie ("b3.swf", "_ root. mc ");
}
Function go4 (){
LoadMovie ("b4.swf", "_ root. mc ");
}
Function go5 (){
LoadMovie ("b5.swf", "_ root. mc ");
}
Function go6 (){
LoadMovie ("b6.swf", "_ root. mc ");
}

The last vertex _ root. go2 () of the First b1 SWF, And the last vertex _ root. go3 () of the second external SWF ()...........

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.