3.3 Include .as file

In this exercise, we will approach one more method to separate the action script side from the Flash authoring environment: the “include” instruction. To illustrate it, we will again use our “Hello world!” example.

1. As we saw in the previous exercise, separating the code from the Flash authoring tool has numerous advantages, such as the possibility of using other coding platforms (such as Flash Builder), specialized and optimized for coding; clarity of code; team work; and sharing the same code across projects. The “include” instruction provides another path for this separation. The difference relatively to the document class is that the code will be embedded in the main timeline, therefore there will be no need for a new class definition. Several “includes” can be used, and the code will be interpreted by order of appearance of the respective “include”.

2. Let’s create a new Flash file, and type the following line of code in the Actions window:

include "actions.as"

Save the Flash file.

3. Now, let’s create a new ActionScript file. Let’s type this “Hello World!” code there:

var myTextField:TextField = new TextField();
stage.addChild(myTextField);
myTextField.text="Hello world!";

Save the file as “actions.as” in the same directory as the Flash file.

4. That’s it! Quite simple. The result should look familiar by now – another hello to the world.

Download files: ex17-include_as_file.zip

Advertisements

About Nuno Correia

audiovisuals+interaction
This entry was posted in 3. Project Management and tagged . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s