Flash AS3.0 rookie Learn to fly the location of the tutorial code

Source: Internet
Author: User

Earlier versions of ActionScript code could be written in places such as frames, buttons, movie clips, as files, and the location of Flash AS3.0 code was changed significantly, only in frames and as files.

Although Flash AS3.0 support to write code in the timeline, in practice, if you put a lot of code in the timeline, it will cause code difficult to manage. Or, it's more appropriate to organize a lot of code with classes, because the class code is placed in the as file.

In addition to putting the code on the timeline, you can also place the code in an external file, such as a TXT file in the server, and then load the external data into the FLA file.

External File Code

In the past are in the timeline to write code, the program is generally only multilayer one frame of the characteristics of which the topmost layer to place code. In this mode, if the program is larger, need hundreds of lines of code to achieve, or even more, the code is all placed in the same place, light is very inconvenient to view, you need to open the Flash software, and then find the frame and action panel, the last page to view the code.

In fact, for a more code program, the code can be divided into several large functional modules, each module code in an as file, so whether it is to view or other management is more convenient.

In addition to using the Flash IDE, Notepad can be used to write code, so faster, after writing code to change the extension as can achieve the same effect, if not very familiar with programming, or use the flash from the editor to write as well, you can use code hints.

Here is an example of how to write code in the as file, and how to import code from the as file into the timeline.

Example: (Separation of code from ART)

1, open flash, choose New command, select ActionScript file in the New Document dialog box, click OK button, create a new as file, save named "Shift.as".

2, enter the code in the as file, and the code is written the same way on the timeline:

This.addeventlistener (event.enter_frame, onenterframe)

var shift:number = 0
var startx = $
var starty =
var r = m

Graphics.linestyle (0)
Graphics . MoveTo (StartX + R, starty)

function Onenterframe (evt:event) {
Graphics.lineto (startx + R * Math.Cos (SHIFT) Starty + R * Math.sin (SHIFT)
Ball.x = startx + R * Math.Cos (SHIFT)
Ball.y = starty + R * Math.sin (SHIFT)
Shif T + +

}

3, create a new Flash file, save the name "Sample", save it in the same directory as "Shift.as", the same file,

4, press Ctrl+f8 to make a movie clip symbol, select the Ellipse tool, No strokes, fill color red, draw a small ball.

5, return to Scenario 1, drag a small ball from the library onto the stage, and in the property panel instance name, enter Ball.

6, click the first frame of layer 1, open the Actions panel, enter code:

include "shift.as"

Hint: The import command is include in AS3.0, and the previous version of AS3.0 is #include.

7, press Ctrl+enter to test the movie. The

Imports code from the as file with the include command, if the as textIf the item is not in the same directory as the FLA file, you should bring the directory name. For example,

If the as file is in a directory at the top level of the FLA file, the "../" Reference to the previous directory, the code should be: include. /shift.as, if the

as file is in the child level directory of the FLA file such as test, the code should be: include "test/shift.as".










Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.