home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeActionScript: The Definitive GuideSearch this book

Appendix C. Backward Compatibility

Flash allows you to publish .swf files in a format that is compatible with previous versions of the Player. By the time you read this, the majority of users will have at least version 5 of the Flash plug-in, but you may prefer to author for the Flash 4 plug-in instead. Even if you are authoring exclusively for Flash 5, this appendix will help you avoid using deprecated ActionScript and bring you up to speed on the preferred methods in Flash 5. For statistics on the distribution of various Flash Player versions, see:

http://www.macromedia.com/software/flash/survey/whitepaper

When authoring for Flash 4, use the deprecated techniques (i.e., those that are outdated, but supported for backward compatibility) listed in Table C-1. See also "Using Flash 5 to Create Flash 4 Content" under "Writing Scripts with ActionScript" in Macromedia's Flash ActionScript Reference Guide.

WARNING

To run scripts in the Flash 4 Player you must set the Version of your .swf file to Flash 4 under the Flash tab under File Publish Settings. All code is disabled if you attempt to run a Flash 5 or later .swf file in the Flash 4 Player.

Table C-1 summarizes key backward-compatibility issues and differences between Flash 4 ActionScript and Flash 5 ActionScript.

Table C-1. Backward-Compatibility Issues

Topic

Description

Creating variables

Flash 4's set function has been replaced by the var statement. To create dynamically named variables, use eval( ), or (more appropriately) use arrays to manage your data. See Chapter 11, "Arrays".

Variable and timeline references

The Flash 4-style slash-colon constructions (/square:area) have been superceded by dot notation (square.area). See Table 2-1.

String comparison operators

The Flash 4 string comparison operators -- eq, ne, ge, gt, le, lt -- have been superceded by the following operators in Flash 5: ==, !=, >=, >, <=, <. See Table 4-2.

String concatenation operator

When creating Flash 4 content in Flash 5 or later, use the add operator instead of Flash 4's & operator. When authoring for Flash 5, use the + operator for string concatenation. See Table 4-2.

String length

Flash 4's length( ) function (e.g., length(myString )) has been superceded by the length property (e.g., myString.length). See Table 4-2.

Substring extraction

Flash 4's substring( ) function (e.g., substring(myString, 1, 3)) has been superceded by the substring( ), substr( ), and slice( ) methods. Note that substring( ) differs in Flash 4 and Flash 5. See Table 4-2.

Character code point functions

Flash 4's chr( ) and mbchr( ) functions (used to create a character from a code point) have been superceded by String.fromCharCode( ). Flash 4's ord( ) and mbord( ) functions (used to determine the code point of a character) have been superceded by the String.charCodeAt( ) method. See Table 4-2.

Datatype conversion

When importing Flash 4 files, Flash 5 automatically inserts the Number( ) function around any numeric data that is used as an operand of the following potentially ambiguous operators: +, ==, !=, <>, <, >, >=, <=. See Table 3-5.

The ifFrameLoaded statement

Flash 3's ifFrameLoaded statement has been deprecated. Use the _totalframes and _framesloaded MovieClip properties to create preloading code.

Infinite loops

Flash 4 allowed a maximum of 200,000 loop iterations. Flash 5 allows 15 seconds for loops, after which it warns users that the movie has stopped responding. See Section 8.6.3, "Maximum Number of Iterations" in Chapter 8, "Loop Statements".

Subroutines versus functions

In Flash 4, a subroutine could be created by attaching a block of code to a frame with a label and executing it using the call( ) statement. Flash 5's functions replace Flash 4's subroutines.

Clip events

Flash 4 supported only button events (i.e., functions starting with on( ) ) as shown in Table 10-1. Clip events (i.e., onClipEvent( ) ) cannot be used in the Flash 4 Player.

Capturing keystrokes

In Flash 4, keyPress was the only means of capturing keystrokes. Flash 5's Key object, in combination with the movie clip events keyDown and keyUp, offers much greater control over keyboard interaction.

Tell Target deprecated

Flash 4's Tell Target (used to control remote movie clips) has been replaced by properties and methods accessed using dot notation and the with statement. See Chapter 13, "Movie Clips".

Get Property deprecated

Flash 4's Get Property command is no longer required for movie clip property access. Use the dot operator instead. See Chapter 13, "Movie Clips".

int deprecated

Flash 4's int( ) function (used to truncate floats to integers) has been superceded by Math.floor( ), Math.ceil( ), and Math.round( ).

Random number generation

Flash 4's random( ) function (used to generate a random number) has been superceded by Math.random( ).

toggleHighQuality deprecated

Flash 4's toggleHighQuality function (used to set the rendering quality of the player) has been superceded by the global _quality property.

_highquality deprecated

Flash 4's _highquality property has been superceded by the global _quality property.

Math object support in Flash 4

The functions and properties of the Math object (e.g., Math.cos( ), Math.PI ) are not natively supported by the Flash 4 Player. The values, however, are approximated when a movie is exported in Flash 4 format.

loadMovie versus loadMovieNum

Flash 3's loadMovie( ) onto a numbered level is superceded by Flash 5's loadMovieNum( ) (which accepts an integer level argument). Flash 4's loadMovie( ) into a target movie clip is still available as loadMovie( ) in Flash 5.

Printing

Flash 5 supports the native print( ) function, which was available in Flash 4 Build 20 and later as a modified Get URL Action only.

Objects and classes not supported

Flash 4 does not support any of Flash 5's built-in objects and classes.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.