Movie clips in Flash can be said to be the most use of a component, then for its as is also a lot.
Before I explain, I'd like to rewrite the rules for editing as as the last time the button was spoken, which is written on the film clip itself and on the timeline.
First, let's start with a simple little example. ( Click here to download the source file. )
Maybe you can make a motion animation of a small ball without as. But what if you were to use as as to move the ball? Let's see how to use as to achieve it.
In this example, you'll first learn how to write as as and write rules in the movie clip itself.
1, create a new film editing components, inside you just draw a circle. Then drag and drop the movie clip onto the stage (that is, create an instance of this movie clip).
2, now start writing script, select this MC, press F9 to open the action panel, according to the figure show select Onclipevent, then select Enterframe in the event shown, then write the script in the following:
This._x+=5
This script should be written after:
Onclipevent (enterframe) {//Enterframe means to constantly trigger this action with a movie frame
This._x + 5; This represents the movie clip itself. _x represents the x-axis coordinates of a movie clip.
}
Oh, press your CTRL + ENTER Test, a simple mobile animation is done.
From this example we can see that if you write as in the movie clip itself, then it has its own writing format. The correct writing format is:
Onclipevent (event) {
Scripts that need to be executed
}
This can be regarded as a formula, you remember it, it is written in the film clips. The "event" in parentheses is actually a trigger, and when the event occurs, execute the statement in curly braces behind the event. , what are the specific events that I have listed here.
-This action is started when the load movie clip is instantiated and appears in the timeline.
-Unload the action starts in the first frame after the movie clip is deleted from the timeline. Does not attach any action to the affected frame until the action associated with the Unload movie clip event is processed.
-Enterframe continues to trigger this action with the movie frame frequency.
-MouseMove initiates this action each time the mouse is moved. The _xmouse and _ymouse properties are used to determine the current mouse position.
-MouseDown starts this action when the left mouse button is pressed.
-MouseUp initiates this action when the left mouse button is released.
-KeyDown starts this action when a key is pressed. Use the Key.getcode method to get information about the recently pressed key.
-KeyUp initiates this action when a key is released. Use the Key.getcode method to get information about the recently pressed key.
-Data starts this action when it is received in a loadvariables or Loadmovie action. When specified with the Loadvariables action, the data event occurs only once, that is, when the last variable is loaded. When you specify with the Loadmovie action, the data event repeats itself when you get each part of the dataset.
After understanding the event, you can try to modify the script, if you want to click the mouse, the circle on the stage to move, how to do?
For an example of writing as in the film clip itself, let's take a look at how to write the as on the timeline.
First you get rid of the script just now. Then you need to start a name for this movie clip instance named MC
When you select the first frame of the timeline, open the Actions panel and enter the following script:
Mc.onenterframe = function () {
This._x + 5; You can also change the sentence to mc._x+=5 yourself to think about why.
};
Obviously, the following formula should be applied to the time axis:
Instance name. Event name =function () {
Script Program
It should be noted that this type of event name should not forget to add an on to the front, for example, if the event is enterframe, you should write Onenterframe
Here's a quick look at the properties of a movie clip. For example, a movie clip has its own x, y axis coordinates, and has its own transparency (_ALPHA), which is its property.
So how do you use these properties? You can use the "dot" syntax to set the properties.
Modify the script above.
Mc.onenterframe = function () {
Mc._x + 5;
Mc._alpha = random (100);
};
Here I added a this._alpha = random (100), which is to set the transparency of the movie clip, the use of the statement is _alpha. The following random () function is to randomly select a number within 100 as its transparency. As you can see from this sentence, the "point" syntax uses the method: instance name. Attribute (mc._alpha), you can even simply understand that "point" is "," then this._alpha this sentence you can understand: Film Clips MC Transparency
The above script mc._alpha = random (100) can also be changed to _root. Mc._alpha = random (100)
Then you can understand that the transparency of a movie clip on the stage is a random selection of 100 values.
About the as basic writing rules for movie clips here, in the future in the concrete examples will be more profound understanding.
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.