Tutorials | Getting Started Tutorials
As Foundation
Flash animation Flash enthusiasts know that to do a flash animation, as is essential, even if just a few simple code can play the role of the entire flash finishing. Here I simply introduce the basic common sense of as.
First we need to know where the as is to be written and when as will be triggered.
1, Frame:
As on the key frame, when the pointer on the timeline goes to the keyframe, the as on which the frame is written is triggered. A common example is a stop () and so on in the frame at the end of the movie. The action method is to click the Keyframe, and then open the as panel.
2, Button:
Unlike the as above the frame, the as on the button has a trigger condition. To write as on a button, the action is to click the Target button, and then open the as panel. For example, you can make it more clear.
Suppose there is an animation that you want to stop at the end of the play, then all you have to do is write as in the last frame of the animation.
stop();
Suppose you have a button that stops playing after you press the button, and the steps are as follows.
Make a button, put it in the main scene, click the button, and then open the as panel. Now if you're writing on the button,
Stop ();
Then, the output will be prompted with an error. That's the right thing to write.
on(release){
stop();
}
This is more than the animation of the frame: on (release) {}, the entire code translates as follows:
当(松开){
停止
}
The red code represents one of the trigger event events for the mouse, which is used for release releases and buttons for common events:
Release released
Releaseoutside out of the button.
Press down
Rollover mouse into the sensor area of the button
RollOut the sensor area where the mouse leaves the button
Now it's clear: the As that is written on the button must be in this format:
On (event) {Code to execute}
3, MC (movie clips)
If you read the above, the same as and written on the MC are the same as the one on the button. The way to do this is to click the MC and then open the as panel. See an example
onClipEvent(load){
stop();
}
Similarly, the MC needs an event to trigger the execution of AS. The code for translation is
当剪辑(载入){
停止
}
The red Code also represents an event. The events of MC have the following:
Load load, execute when MC appears. This means that the code in the Load event executes only once, unless the MC is uninstalled.
Unload Uninstall, when the MC uninstall the execution.
Enterframe every frame that exists. Code is executed once in each frame where the MC exists. If your scene has 100 frames, there is a MC from 41 frames to appear to 100 frames to disappear, then the code above the MC executes 60 times.
MouseDown press the mouse, it is counted anywhere in the scene. And the button is not the same place.
MouseMove move the mouse, just move the mouse to execute the code
MouseUp Release Mouse
Again, you have to be clear: the code written on the MC must always be in this format:
Onclipevent (event) {code}
See here, if you understand the writing in the Frame, button, MC Code on what is different, the task is completed.
As Grammar Chapter
After reading my first tutorial--based on the basics--now do you have a certain idea of the existence of as? If not, then go and review it.
Aborigines series as Getting Started tutorial--Basic articles
The next thing I want to talk about is the syntax of AS.
The first thing to make people understand is that the case of as grammar is sensitive.
such as: gotoAndPlay () correct gotoandplay () error.
The spelling of the keyword must be consistent with the grammar, and it is easy to do so, because in the Flash's as panel, the keyword will have a different color display.
Many flash birds may want to start complaining, can't remember? I have a way here, is back. Do not shed the grievances of tears, we are all so come through. Use two more times and you'll remember.
Here, we want to start with a good habit of programming, such as after each statement with a semicolon, if possible, to add comments to complex statements. Example of an annotation:
This is a comment, but only one line
* This is also a note, can write a lot of lines * *
Next, introduce several types of syntax.
1. Several common methods of controlling the scene, such as:
play(); //让时间轴的指针播放
stop(); //停止时间轴的指针在程序触发时候的那个帧
gotoAndPlay(); //让指针跳转到某个帧,然后继续播放
gotoAndStop(); //让指针跳转到某个帧,停止在那个帧
nextFrame(); //往下走一帧
prevFrame(); //往前走一帧
The above are all methods.
Method? Solution: For example, we call eating food a way to solve the problem of starvation. We call Stop () a method to solve the problem that the time axis pointer stops. We call the above several things called methods, to solve the problem of the motion of the time axis pointer.
2, control the syntax of the property. There are many, I list a few
_x
_y
_alpha
_width
_name
..... And so on properties
The above are all attributes.
Property? The solution: to make an analogy. We call your height the attribute, which is used to identify your height. We call your weight the attribute, to identify your quality. We call the _x attribute, which identifies the x-axis coordinates of the target. We call the _alpha attribute, which is used to identify the transparency of the target .... I'm so wordy, alas.
3, control The syntax of the statement process, such as
if (条件){
//条件满足执行这里的代码
}else{
//条件不满足执行这里的代码
}
for(i=0;i <N;I++){ P <>
//执行这里的代码N次
}
while(条件){
//当条件满足时一直执行这里的代码
}
Wait a minute. These are the basic grammar and the basis of AS.
4, other methods and their own definition of the method.
Here I can not put all the grammar listed to introduce, because it is too much, specific reference to the flash with the Help manual. We can only be familiar with the application in the future. Here, you have a basic concept. At the back I would add a note to every sentence.
In retrospect, this is a minor thing to remember:
the case of the as grammar is sensitive.
The concept of the method.
The concept of a property.
Although as is not really object-oriented programming, it also has an object concept. This concept runs through the entire as, so the understanding of the object is more important than the grammar or other understanding. Let's start now:
First, let's take a look at the path, which is divided into two types: an absolute path and a relative path. A friend who has done HTML should know the concept. But here I would like to explain in detail, I think the path of understanding to go deep, I am a beginner of the time is to knock on the path.
Before you talk about the path, it is necessary to talk about it first. Grammar: For example, here is a book on a table in a room that says:
Room, table, book
If you want to be more detailed on the page above the words, it is obvious
Room, table, book, page, Word
You see? I don't know how to say that. The syntax is how the object is represented, and the point is preceded by the parent behind it. If the room is the parent of the table, the child of the table is the book. Still don't get it? That's it, you put. In the "Inside" is OK, so that is:
(inside) a table (inside) a book (inside) a page (inside)
It's much easier, isn't it?
Now I began to say the path, which was also to be mingled with the description of the object, to see:
Start with the example. Create a new Flash file and build a MOVIECLIP,MC named "MC", put it in the home scene, then create a button, put it in the "MC", and drag one out of the library to the home scene, naming the two element instances (Instance name, Note that the instance name is not the name of the MC): MC->MYMC button->mybtn
Now we assume that the main scene is the house, the MC is the table, the button is a book, then how to express the House, table, book? As follows:
_root House
_ROOT.MYMC House. Table
_ROOT.MYMC.MYBTN House, table, book
Here the _root is a flash keyword that represents the Timeline (timeline) of the main scene.
It's easy to understand. The House, the table, the book are the "objects" we want to understand.
When you find this object, you can manipulate the object to apply a method to the object. For example, I now have to clean the house, cleaning is the method, but the object is the house, the expression is this:
House. Cleaning ()
If you can't properly express the object of the house, your cleaning will not be implemented properly.
* Description: Why do you want to add () it behind the sweep? Because cleaning is the method not the object, in order to let Flash know this is a method, we must add (), otherwise it will think that the house has "clean" this thing.
Now, we can easily operate on everything in the room, such as:
House. Cleaning ();
House, wooden table, finishing ();
House, Glass table, broken ();
House, desk, book, Look ();
Wait, I believe you have no problem with translating them into the as code:) For example, to stop playing the main scene, which is
_root.stop ();
To the MC to stop playing, is
_root.mymc.stop ();
Now talk about relative paths. or the example above. If I gave you an order: fix the red chair in the house. So how do you express it? It is:
House. Red Chair. Repair ();
No matter where the person who gave you the order told you, you would know which chair to repair. But if he says so: Fix the chair you're sitting on. The red ones? Or the blue one? It depends on which chair you are sitting on. So the relative expression is.
I sit in the chair. Repair ();
Why don't you write this here:
The house. I sit in the chair. Repair ();
This is wrong, because I sit in a chair is not fixed, I might move a chair outside the house to sit, then this expression is wrong, because the chair is not in the house.
In exchange for the Flash instance description. Now I want to let the MYMC in the main scene not play at the beginning, but stop first. So what can you do?
I guess the idea is to put it in the frame of the MC at the home scene:
_root.mymc.stop ();
That's the right one. But once MYMC's name changes, you have to change the sentence.
There is no way regardless of the "MC" instance name, regardless of how to change, will be our same sentence as found? Of course, if your as must "sit on this MC".
Into the MC of the editing state, in the MC Timeline the first frame written.
This.stop ();
This is also the keyword for flash, this is the Timeline of the AS.
Now no matter where you put the MC, the name is what, I do not care, anyway, will certainly stop. Why, because as is "sitting on the MC".
This.stop ();
If you write in here.
That's a mistake. Why? Think about it carefully.
This is one of the key words for the relative path. You have to understand it carefully.
Another key word is _parent. If you understand this, then _parent is not difficult to understand. Example:
or which Assumption House (_root), table (Mc_zhuozi), book (Mc_shu) Their relationship is (in parentheses for the MC instance name)
The House, the table, the book
_root.mc_zhuozi.mc_shu
In the timeline of Mc_zhuozi, write:
_parent. cleaning ();
It means cleaning the room.
In the timeline of Mc_shu, write:
_parent. cleaning ();
It means cleaning the table.
_parent is also the parent level. The _parent of the table is the timeline of the house, the _parent of the book is the timeline of the table. The _parent of the object behind the point is the object in front of the point.
This is the right time to review:
Point Grammar learns to express objects.
Learn to express objects with absolute and relative paths.