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:
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();
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