Problem
The use of Loadmovie can dynamically load external files, thereby reducing the volume of the main file, is conducive to downloading online, as well as the changes to the various files, replacement. If you have not done a flash page, you can see the basic composition of the Flash page, see figure 2-2-1
You just need to upload the main files and files in the diagram to your own space, such as FTP tools, you can easily realize only download the main file, if you need to browse the sub files can be downloaded separately, you can think, if your entire Flash page without primary and secondary, all unified a flash, made a few m or even more than 10 m, Then who would like to wait to see your Web page? Unless you yourself.
So it's important to use Loadmovie. Now let's start with the basics and then analyze the specific issues involved in using Loadmovie. There are two basic ways to use Loadmovie: (i) load an external SWF file onto a layer. (ii) Load the external SWF file into a movie clip in the timeline. The use of these two methods is more intuitive with graph representation. See Figure 2-2-2
The second method can be written like this: _root.mc.loadmovie ("a1.swf"), and if the suffix of A1 is named JPG, then the external picture is loaded. Loading a picture is the same as loading a SWF file, so don't dwell on it. Speaking of this is still relatively empty, do an example to see.
One, create a new folder, arbitrarily take a name such as: Mywangye
Second, make a flash into a SWF file and take the name of A1, saved in the Mywangye directory, this A1 is we want to load the child files.
Third, then the master file, because we are doing the simplest, so do not draw, in the first frame of the main file, write Loadmovie ("a1.swf", 1) also save this file in the Mywangye directory, take a name named index
Iv. test results, source files See the 01 folders in the package after this article
Then use the 2nd syntax in the diagram above to continue to do one, note that the second method needs to put an MC on the stage and take an instance name, or create an empty MC. After doing the little experiment above, what can we conclude? If you just get a conclusion that you can load an external file, it's too superficial. We can think of: the coordinate problem of the external file that is joined in; long-width problem; The problem of loading delay caused by the large external file; How to access the problem of the loaded SWF; do not load, uninstall the problem ... if we do not study these problems, we will encounter a lot of trouble when we do the Web page.
By the simplest loading of the above we can get this conclusion: (1) If the load into the layer, the default registration point is the upper left corner of the stage, if the load into the MC, then the default registration point is the registration point of the MC. If the registration point of the MC is the upper left corner, then the loaded SWF file is aligned with the upper left corner of the MC, if the registration point of the MC is the center, then the loaded SWF will align the upper left corner with the center of the MC. (2) The loaded MC retains its original height-to-width ratio.
Question one: How do you control the coordinates and height-to-width proportions of the loaded SWF file?
Control which SWF file is loaded to control its long width to use onenterframe, such as:
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 use Onenterframe? Because the loaded in the process, a bit of a delay, if there is no onenterframe statement, then the statement read one time does not read, but after reading this time, has not been loaded in, so will cause the coordinate size set invalid. Similarly, if loaded onto a layer, so is the case.
On (Press) {
Loadmovie ("a1.swf", 1);
Onenterframe = function () {
_level1._x = 17;
_level1._y = 30;
_level1._width = 330;
_level1._height = 240;
};
}
Note that these two methods, the first one, the external A2 loaded into the MYMC, added in, A2 automatically replaced the MYMC, we set the properties of the MYMC directly set the properties of the SWF loaded in. The second method, _level, is a reference to a movie loaded into the timeline, which is _level2 to the 2nd layer, and _LEVEL3 to the 3rd layer.
Question two: How to implement the Click button to load an external SWF file, and to display the download progress of loading?
There are two ways to achieve this effect, one: Load londing written in the main file, the second, the loaded sub-SWF file has its own londing. Now give a separate description.
One: Write londing in the main file
The external child SWF file name is A1, the main file has a dynamic text box named LoadText, a button named BBT, now write Loadmovie and londing on the hardwood.
_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 child file has its own londing
This writing is the same as the previous londing, just pay attention to a problem is to note the path of the problem, such as:
First
loaded = getbytesloaded ();
Total = Getbytestotal ();
LTS = Math.Round ((loaded/total) *100);
Wenben = lts+ "%";
Second Zhen
if (lts = = 100) {
gotoAndStop (3);
} else {
gotoAndPlay (1);
}
Compared to the previous londing, see the difference? Just get rid of the _root. Because it is loaded, the external SWF file is equivalent to an MC in the main file has _root is to point to the main file _root, of course, will show errors.
Question three: I want to draw a screen on the stage, and then click on a button to load an external SWF to play how to do?
So let's make an album together. When the primary file is loaded, the click button loads an external SWF file, and there is a londing display. First of all, we do the following preparations: (1) Prepare a few pictures, now we prepare 7, 6 sub Files a one, the main file with a sheet. (2) The main file stage size to fit the needs of the Web page, set to 770*420. The child file stage size is set to 512*384 so that you do not need to load the control size, more convenient (in fact, we should do this, save some trouble.)
First, the production of sub-files. Each is used to display pictures, the first and second Zhen write londing, the third zhen ~ ~ 20 Zhen According to their hobbies do point brightness changes to produce dynamic, the last one to write the Stop (). The first and second londing are as follows
First
loaded = getbytesloaded ();
Total = Getbytestotal ();
LTS = Math.Round ((loaded/total) *100);
Wenben = "+lts+" in "Data download";
Second Zhen
if (lts = = 100) {
gotoAndPlay (3);
} else {
gotoAndPlay (1);
}
This is the same as the production of 6, respectively named B1.....b6 are published as SWF files. Saved in a folder.
Second, the production of the main document
The first is used to write londing, 2nd to put some things like the screen, and buttons, in order to increase the effect, put a music on the timeline.
The londing//of the first one has been said much before, and will not repeat it.
Stop ();
i = 0; ,
Onenterframe = function () {
Using events that are constantly triggered
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) {
If the condition is detected, jump out or continue looping
_root.gotoandstop (2);
Delete This.onenterframe;
The purpose of using delete is to save resource consumption by destroying the Onenterframe event after the download is complete.
}
};
The As on the button on the 2nd
On (Press) {
_root.i++;
if (i = = 7) {
i = 6;
}
Loadmovie ("B" +i+ ". SwF", "_ROOT.MC");
_root.tishi = "The first" +i+ "Zhang Picture";
}
Steal a little lazy, not detailed to repeat its meaning, we can also use a very long statement to achieve the same effect, this writing is a concentration of as.
Please refer to the original document for details.
Question four: I would like to load more than one external file, when the first load playback finished, immediately load the 2nd, after the second playback finished, immediately load the 3rd, ... until the end. What to do?
First of all, let's ask the person who asked the question, what is the point of doing so? Rather than doing it all in one SWF, because each time an external SWF is invoked, it takes a certain amount of time to wait for the download. Of course, if you want to make a series, after playing one, use londing the next episode of the londing screen display "is loading a second, please wait" then it is OK.
The method is very simple: according to the original file of question three, slightly modified, remove a button, with a button load the first, and then the first last chapter of the call in the main file function.
Button:
On (Press) {
Loadmovie ("b1.swf", "_ROOT.MC");
}
Functions defined by the primary 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 first B1 SWF's last _root. Go2 (), the last one of the second external SwF _root.go3 () ...
Refer to the original program