Step by step by step ActionScript 2.0 (2)

xiaoxiao2021-03-06  41

Tutorial http://jinjunshi.blogchina.com

What is ActionScript? [Learning Objectives]: Know ActionScript, know the composition of ActionScript. Through the last class, we know that the AS is a collection of instructions, complete the control of the film, let me see what AS is like, knowing it, we can draw a scoop compared with the scoop, then further comparison Halfese painting, finally we threw the same painter as the gourd, hey, we will do it.

Now give you a question: Do a "analog painting sinus curve" animation. You will think that I use the mask to do, it is possible, if you draw a curve that is really y = sin (α), it is really difficult: (Simple with AS. Below we start: 1 New Flash document, the property is set to : Size 500x400, background color is white. 2 Open the action panel, copy the following code to the first.

// Set the initial value;

VAR x = 10;

// Create an empty movie clip MCS;

_Root.createemptyMovieClip ("MCS", 1);

/ / Let MCS move to (100,200) position;

_Root.mcs.moveto (100, 200);

// Set the thickness, color and transparency of the line;

_Root.mcs.LineStyle (2, 0x000000, 100);

// This function is to draw graphics;

_root.mcs.onterframe = function () {

// Picture;

THIS.LINETO (X 100, - (100 * math.sin (0.02 * x) -200);

IF (x <500) {

X = 5;

}

}

3 Then Ctrl Enter test, see the sinusoidal curve that is slowly drawn! We did not manually command to do any actors, the director of this animation, but the scene behind the scenes is you :) You released the instruction, Flash executes your director intention. Now let's take a closer look, understand the composition of the AS program, we see more English words, don't be strange, if this software is you developed, you will use the Chinese characters, who let We use the forefront of the foreigner, of course, Flash understands the fores (joke). We can get 2 conclusions: First, as the code from top to the next row, we can understand: Initialization - Create an actor - let the actor stand well - ready pen - Painted lines in the actor The painting, this process is like the recipe of us, so we use the AS to do animation, you must first make such a plan, the official call is "algorithm". We don't go to the things. Second, there are various forms of "elements" in each line with its own name and rules. For example, the keyword, grammar format, etc. understand these basic knowledge is to learn the most basic steps in Flash. 1 Note ActionScript Note Only for developers to do some notes and is not a formal part of the program. Flash is uncomfortable, just give yourself, know this or this sentence is what to do. Single row of annotations with //, such as the use of "// Picture" above; multi-line comments with / * start, * / end. 2 Scripturescript Each full statement is ended in a semicolon ";", executes a specific operation, such as the above code _root.mcs.moveto (100, 200); is the actor station to let the name MCS to point ( 100, 200). 3 Keyword Keyword is "personal property" of ActionScript, when programming, in variables, functions such as user-defined element name, "avoiding" when naming. For example, root is a keyword, then we can't give an actor to name the root, otherwise the program will be dizzy by you, don't know what you want to do. 4 variables you can understand "container", we must declare one, such as the above x, we declare VAR X = 10; and put a number 10 in it. 5 Operator operators are well understood, the meaning is basically the same as our primary school, which is the differential differences, including =, <,>, , -, *, and so on. 6 points (.) This dot (".") Function is too powerful, don't look at it, it is very frequent, we can understand this (.): ×× "in this" ××. Its role is usually two. First, used to position, such as _root.mcs is an actor MCS at the root movie level. Second, use to access the properties of the object, call the object method, and the like. 7 This concept is more abstract, just like a "black box", in detail in the future, such as our Math is a class. 8 Function You can understand a piece of code that completes a specific task, you can call directly, such as the SIN function above, you can define it yourself, the above picture is your own definition.

转载请注明原文地址:https://www.9cbs.com/read-73099.html

New Post(0)