Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Writing Scripts and Creating Applications in Flash MX 2004 and Flash 8

Writing Scripts and Creating Applications in Flash MX 2004 and Flash 8

The scripting improvements in Flash Basic 8 and Flash Professional 8 provide better performance, flexibility, and ease of use. The ActionScript editor (Actions panel and Script window) has several new features and changed user interface elements that improve how you write and edit ActionScript code in Flash.

You can now select Hidden Characters in the Actions panel and Script window to view or hide hidden characters when you’re writing script files in the Actions panel or Script window. This option shows spaces, tabs, and line breaks within your scripts (see Figure 14). If you accidentally add a hidden character that causes a compiler error (such as double-byte spaces), this feature can help you locate the problem.

 Hidden characters help you avoid errors that were invisible in Flash MX 2004.

Figure 14. Hidden characters help you avoid errors that were invisible in Flash MX 2004.

You can reload modified script files when working on an application. A warning message appears, prompting you to reload the modified script files associated with the application you’re working on. This feature is particularly beneficial to teams working on applications at the same time because it helps you avoid working with outdated scripts or overwriting newer versions of a script. If a script file was moved or deleted, a warning message appears and prompts you to save the files as necessary.

You can delete ASO files while you create, or when you test, your application. This helps you work with the latest version of your application’s class files because it removes cached files that are out of date. Select Control > Delete ASO Files or Control > Delete ASO Files and Test Movie.

The Script window feature (File > New > ActionScript File) is available in Flash Basic 8 and Flash Professional 8. You can now create ActionScript and JavaScript Flash files in both editions of Flash 8.

Changes to Debugging

There are a few changes to the debugging workflow in Flash 8. Debugging options are now available in the Script window, as well as the Actions panel for ActionScript files. You can now add breakpoints when you’re editing ActionScript (AS) files. The breakpoint information is stored in an XML document within the Configuration directory to keep track of breakpoints between your debugging sessions.

Note: For a list of specific classes, language elements, methods, and properties added to ActionScript 2.0 in Flash 8, see the next section. For example, new classes that enable you to interact between JavaScript code and a SWF file as well as upload files have been added to ActionScript 2.0. These classes are detailed next.

ActionScript in Flash MX 2004 and Flash 8

Macromedia Flash Basic 8 and Macromedia Flash Professional 8 provide several enhancements that make it easy for you to write robust scripts using the ActionScript language. The new features include new language elements, improved editing tools, changes to the security model, and other ActionScript-related improvements to the authoring tool. Flash Basic 8 and Flash Professional 8 introduce several new language elements for expressive features, such as filters and blending modes, and application development, such as JavaScript integration (ExternalInterface) and file input and output (FileReference and FileReferenceList).

New Capabilities in ActionScript

This section highlights some of the new capabilities that have been added to ActionScript 2.0 in Flash 8. In addition to the new classes and features mentioned in this section, there are numerous additional methods and properties you will want to play with. For more details on individual methods and properties, search the Flash Help panel (F1) for the particular topic.

A robust new capability of Flash Player is that you can load new kinds of image files at runtime, such as progressive JPEG images and non-animated GIF and PNG files. If you load an animated file, the first frame of that animation appears in the SWF file.

Bitmap caching lets you improve the performance of your applications at runtime by caching a bitmap representation of your vector button or movie clip instances at runtime. You can use ActionScript code to access this property or select the instance and then select an option in the Property inspector to cache the instance. Caching a movie clip as a bitmap prevents Flash Player from having to redraw the image continually, providing a significant improvement in playback performance.

Alpha channel masking is supported if both the mask and the maskee movie clips use bitmap caching. This support also lets you use a filter on the mask independently of the filter that is applied to the maskee itself.

Note: Mask layers do not support alpha channel masking. You must use ActionScript code to apply a mask and use runtime bitmap caching.

The 9-slice scaling feature enables you to scale movie clip instances without widening the strokes that outline the movie clip. You can use ActionScript code or the Flash user interface to access this feature in either Flash Basic 8 or Flash Professional 8.

Note: To use the 9-slice scaling feature with a symbol, select the symbol in the library and then select Properties from the options menu. Click the Advanced button (if applicable) and select Enable Guides for 9-Slice Scaling.

The 9-slice scaling feature is especially useful for creating components. To see this feature in use, open the FLA files for the FLVPlayback component and its skins, which use the 9-slice scaling feature. You can find numerous examples in this directory:

(Windows) Hard DiskProgram FilesMacromediaFlash 8<language>ConfigurationSkinFLA

(Mac OS X) HD/Applications/Macromedia Flash 8/Configuration/SkinFLA

The workflow for creating accessible applications is improved. Flash Player 8 no longer requires developers to add all objects to the tab index for content to be read correctly by a screen reader. For more information on tab index, see Button.tabIndex, MovieClip.tabIndex, or TextField.tabIndex in the ActionScript 2.0 Language Reference.

The ExternalInterface class (also called the External API) lets you easily communicate from ActionScript and the Flash Player container to an HTML page with JavaScript, or to a desktop application that embeds Flash Player. From ActionScript, you can call a JavaScript function on the HTML page. You can use any JavaScript function, not only the functions that you can use with the fscommand() function. You might have used fscommand() in Flash MX 2004. The External API offers the following improved functionality when compared with fscommand():

  • You can pass any number of arguments, with any names; you aren’t limited to passing a command and arguments
  • You can pass various data types (such as Boolean, Number, and String); you are no longer limited to String parameters
  • You can now receive the value of a call, which returns immediately to ActionScript (as the return value of the call you make)

The FileReference class is new in Flash 8. It lets you add the ability to upload and download files between a client and server from a SWF file. Your users are prompted to select a file to upload or a location for download in a dialog box (such as the Open dialog box in Windows).

New Classes, Methods, and Properties in Flash 8

The ActionScript language has grown and developed since its introduction several years ago. With each new release of Flash, additional keywords, objects, methods, and other language elements were added to ActionScript.

Table 2 lists classes and language elements new or changed in Flash 8 and supported in Flash Player 8. For more information on these classes and language elements, search the Flash Help panel (F1).

Table 2. New ActionScript 2.0 Classes

Class Package Description
BevelFilter flash.filters Adds bevel effects to objects
BitmapData flash.display Creates and manipulates arbitrarily sized transparent or opaque bitmap images
BitmapFilter flash.display Acts as a base class for filter effects
BlurFilter flash.filters Applies blurs to objects in Flash
ColorMatrixFilter flash.filters Applies transformations to ARGB colors and alpha values
ColorTransform flash.geom Adjusts color values in movie clips (Color class is deprecated in favor of this class)
ConvolutionFilter flash.filters Applies matrix convolution filter effects
DisplacementMapFilter flash.filters Uses pixel values from a BitmapData object to perform displacement on an object
DropShadowFilter flash.filters Adds drop shadows to objects
ExternalInterface flash.external Communicates by using ActionScript with the Flash Player container (the system holding the Flash application, such as a browser with JavaScript, or the desktop application)
FileReference Uploads and downloads files between the user’s computer and a server
FileReferenceList Selects one or more files to upload
GlowFilter flash.filters Adds glow effects to objects
GradientBevelFilter flash.filters Adds gradient bevels to objects
GradientGlowFilter flash.filters Adds gradient glow effects to objects
IME in the System class Manipulates the operating system’s input method editor (IME) within Flash Player
Locale mx.lang Controls how multilanguage text appears in a SWF file
Matrix flash.geom Represents a transformation matrix that determines how to map points from one coordinate space to another
Point flash.geom Represents a location in a two-dimensional coordinate system (x represents the horizontal axis and y represents the vertical axis)
Rectangle flash.geom Creates and modifies Rectangle objects
TextRenderer flash.text Provides functionality for anti-aliasing embedded fonts
Transform flash.geom Collects data about color transformations and coordinates manipulations that you apply to a MovieClip instance

Note: Official support is added for the AsBroadcaster class in Flash 8. This class was not officially supported in Flash MX 2004.