Skills
Today we have seen many flash websites on the internet, most of the use of the flash site is to invoke other SWF files, so that our site's structure is clear and convenient for us to manage the site of Flash, and we are making it easier, because it is like when we develop software , the use of modular thinking! To facilitate our development, fragmented. Today we will give you a specific talk about this technique.
Demo animation effects:
Click here to download the packaging source file (total 5 files)
The basic idea of production:
Every SWF we make is a standalone animation, and each has its own stop frame, when the main movie loaded automatically loaded the first animation, the first animation began to load and set the middle of the pause frame, when we click on the other button and then load the other animation, and pause in the middle. In this system, two variables are mainly used: Midframe and _root.currmovie.
The Midframe is the first frame of each animation, which first indicates where the animation begins to pause in the middle frame. When the button is clicked first tells us is the current frame, but must move to call the midframe of the animation. Of course, the above demo is just a simple example, you can make in the actual production process more complex.
_root.currmovie refers to the current frame, which is created by _root, mainly by active painting.
Production steps:
1. Create four buttons, named Section1, Section2, Section3 and Section4 respectively. Of course, you can be named Main,about,work,conact in the actual production process.
2. Create a new movie clip, named container, this movie clip is empty! Then drag it onto the stage. We will invoke the other SWF file through this empty movie clip. This is a key place. Once created, put container in a layer, and then we create a new layer and drag the four buttons we just created onto the layer, as shown in the figure:
3. Below we select in the stage just dragged out of the film container, give it a name of an instance, so we can use the code to call Ah! As shown in figure:
4. Select the first button, then press F9 to open the action panel, start setting the button click Action, enter the following code:
On (release) {
if (_root.currmovie = = undefined) {
_root.currmovie = "Section1";
Container.loadmovie ("section1.swf");
else if (_root.currmovie!= "Section1") {
if (container._currentframe >= container.midframe) {
_root.currmovie = "Section1";
Container.play ();
}
}
}
Note: If your sub swf is main.swf, change to the following code:
On (release) {
if (_root.currmovie = = undefined) {
_root.currmovie = "main";
Container.loadmovie ("main.swf");
else if (_root.currmovie!= "main") {
if (container._currentframe >= container.midframe) {
_root.currmovie = "main";
Container.play ();
}
}
}
5. Add the corresponding action script to the other three buttons according to the above method.
Note: To produce the results shown, you must put the main file and others in the same directory!
6. If we want the active painting to display an animation first when it is loaded, you need to add a layer, and then add the following code to the first frame:
The common code is:
_root.currmovie = "Your_first_section_name";
Container.loadmovie (_root.currmovie+ ". swf");
Here we use the following statement:
_root.currmovie = "Section1";
Container.loadmovie (_root.currmovie+ ". swf");
7. The following is a brief introduction to the production method of the animation:
(1). Create a simple introduction of the animation, divided into two layers: one animation layer, the other is a code layer, do animation to take into account the middle frame, as shown:
(2). Select the middle frame of the animation and remember its frame number, and then enter the action at the Middle frame: stop (), as shown:
(3). Then go back to the first frame and set the action to:
midframe=78;
(4). Select the last frame to set the following action script:
_root.container.loadmovie (_root.currmovie+ ". SwF")
finally add point: because we are using Flash production site, so sometimes it is inevitable that the speed is slower, then we can make a loading effect! is to create loading for each animation, the method is very simple, just add 2 frames in front! At this time to pay attention to the Midframe has changed, pay attention to change it!
The script for the first frame is:
Midframe = [Yourupdatednumber];
bytes_loaded = Math.Round (this.getbytesloaded ());
Bytes_total = Math.Round (This.getbytestotal ());
Getpercent = Bytes_loaded/bytes_total;
This.loadbar._width = getpercent*100;
This.loadtext = Math.Round (getpercent*100) + "%";
if (bytes_loaded = = bytes_total) {
This.gotoandplay (3);
}
The script for the second frame is:
This. gotoAndPlay (1);
All right! This article has introduced to everybody, hoped that has the help to everybody!