Writing ActionScript with Dreamweaver


When creating large Flash movies, many programmers choose to keep their ActionScript in external text files — typically saved with the .as file extension. There are many benefits to this method:

  • You can start building libraries of code external to your .fla files, making it easier to reuse code in Flash movies that share common routines.

  • You don't have to work in the ActionScript window in Flash, which some coders find cramped and difficult to navigate, especially when writing large amounts of code.

  • You can take advantage of enhanced coding features in Dreamweaver 8, such as the flexible collapse and expand options and quick access to code snippets in the new Coding toolbar.

  • You can modularize your code files, allowing different developers to work on different parts of the same Flash movie simultaneously.

  • When code files are stored externally, you can use a version control system to track changes.

Since Dreamweaver MX, the Dreamweaver coding environment has supported external ActionScript files with full syntax coloring and code hinting features. This makes the process of creating code files much less error-prone than it was in early versions of Dreamweaver, where most methods of editing external ActionScript didn't offer any means of syntax checking.

Code hinting in Dreamweaver creates pop-up menus that automatically appear when you're typing the name of an object, as is true in the ActionScript panel in Flash. For example, if your object name ends in _mc, the code hint menu will show the methods and properties for a movieClip object. If your object name ends in xmlsocket, you see the methods and properties for an XMLSocket object.

Tip 

If you aren't using standard suffixes in your ActionScript and want to force code hints to appear, press Ctrl+spacebar.

To create an ActionScript .as file in Dreamweaver 8, follow these steps:

  1. In Dreamweaver, click More in the Create New column of the Start page (or if you are already in the authoring environment, choose File ð New from the application menu). Select ActionScript from the Basic page Category in the New Document dialog box and click the Create button.

  2. A new page opens in Code view with a comment at the start to indicate an ActionScript document file. You can begin writing ActionScript by typing directly in the code window.

  3. When you save the file, it is automatically given the .as extension; this is the format that will be recognized by Flash.

Some ActionScript is well-suited to being written in external files — long routines, groups of functions, and object definitions, for example.

New Feature 

The new Coding toolbar on the left side of the Code view window is a huge timesaver. The options to collapse or expand sections of code and to store and access custom code snippets are invaluable if you do any serious coding in Dreamweaver.

Cross-Reference 

To find documentation on these features, search Dreamweaver Help for "Snippets" or "Coding toolbar."

Though it may seem counterintuitive, it's practical to have more — rather than fewer — external files when writing code. A common method is to use a separate .as file for each object definition within your Flash project. In the Flash authoring environment, use the #include command in your Flash movie to load the code from an external file. External ActionScript is only included in the Flash movie when the .swf is published, so it will not be added to your .fla file. If you change any code in the external file, you'll need to publish the .swf again to include the changed ActionScript.

Cross-Reference 

For more information about using the #include directive to load external ActionScript from .as files into Flash movie files (.swf), refer to Chapter 35, "Building an Image Gallery Component."

Dreamweaver also has support for creating a wide range of other code format files, including ActionScript Communication files (.asc) and ActionScript Remote files (.asr). These are used with advanced ActionScripting features.

Cross-Reference 

For more details on ActionScript remoting and communications, refer to the Flash 8 ActionScript Bible (Wiley, 2006).




Macromedia Flash 8 Bible
Macromedia Flash8 Bible
ISBN: 0471746762
EAN: 2147483647
Year: 2006
Pages: 395

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net