Username:
Password:
Adobe Flash ActionScript 3.0 for Designers Tutorials

ActionScript Fundamentals pt. 1 / External AS Files

Subtitles of the Movie

Thus far we've been writing all of our scripts in the Script Pane of the Actions Window, however, more advanced coders also write their own classes or extend the functionality of existing ActionScript classes. In these cases the script is written not in the Flash Timeline or it's not written here in the Actions Window but in a separate text file. These external files are written with a .as extension to indicate that the text is actually ActionScript. This text file is then saved in the same directory as the Flash file. When creating your own classes like this you would use the Import Statement to build upon preexisting classes. There's the statement there. You can also keep script in an external .as file and then have Flash include it in the Timeline when you publish your SWF file. External ActionScript files are used to separate the code from the actual Flash interface. This is useful as it helps to unclutter the work area. It also allows you to work with multiple scripts at the same time or to have multiple coders working on the same script at the same time if needed. To get an external ActionScript file to work you need to link it to the Flash document. This only requires one simple line of code, as follows. Include and then in quotation marks the name of the ActionScript file. A couple of things to point out with this code here is that the value in between the quotation marks, there needs to be a String. It cannot be a variable. This line of code includes your external ActionScript file into your Flash document. ActionScript 2.0 used the pound sign in front of the include but that's no longer needed in ActionScript 3.0. Let's go ahead and practice working with this technique by including some external ActionScript in a new Flash file. Start by opening up the now function end file that we worked on earlier from the work files folder. Open that up and then choose Control, Test Movie. Let's go ahead and test the scripts and make sure that they're all working in this file before we copy them over to an external ActionScript file. We want to make sure that they're correct. Go ahead and click on all the buttons, make sure they're all working. Make sure there are no error messages. This looks good. Now let's open up the Actions Window and let's copy all of the text by highlighting all of it except for the stop action there at the top and then right-click in the Script Window and choose Copy from the contextual menu there. Now what we want to do is paste this script into a new ActionScript file, so choose from the Main Menu File, New. From the New Document dialog choose the ActionScript File option right here. Click OK. Notice that this gives us just a script window here. Right-click in that window and choose Paste from the contextual menu, that will paste all of that working script right here. Now we need to save this external ActionScript file in the same folder where we will save our new Flash file. Let's go ahead and choose File, Save As and let's call this basic nav script, underscore between the basic nav and script. Click Save. I'm going to go ahead and overwrite my practice file there. Now that we have a working script we now need to combine it with some working Flash so what we do now is open up the first nav file that we worked on, nav function start. This one has all of the buttons and all of the targets and labels but none of the ActionScripting. Let's go ahead and click on the Actions Window there, click on the first frame and then click on the Actions Window and let's go ahead and delete any scripting that we find there. I can go ahead and leave the stop actions in there. I'm going to basically include the script from our external file right here in the Timeline, so now I write my include statement: include and then in quotation marks the name of that ActionScript file and there it is right there: basic nav script - basic underscore nav underscore script. Don't forget the as extension and to close out the quotation marks and that's all there is to it. Let's go ahead and save this as a New filename so we don't overwrite our basic nav script. Let's call this external actionscript right there. Let's overwrite that other one. Control, Test our Movie and this should work identical to our first scripting project, the difference being that we're including all of the ActionScripts to make these buttons work from an external ActionScript file. That will conclude, then, this section of the tutorial Part 1 on ActionScript Fundamentals. You've learned all about objects, classes, properties, methods, and functions, as well as how to write and declare variables. You've learned about expressions and data types and been introduced to writing. syntax. You've also learned how to create external ActionScript files and then include them in your Flash Timeline when you publish your SWF files. Let's now move on to the next Section of this tutorial. and get on to our second project, Scripting an Animated Drop-down Menu.

Tutorial Information

Course: Adobe Flash ActionScript 3.0 for Designers
Author: James Gonzalez
SKU: 34060
ISBN: 1-935320-82-3
Release Date: 2009-11-09
Duration: 9.5 hrs / 101 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available