Flash MX offers widespread performance increases, greater control of movie elements from ActionScript, and a step-through debugger.Objects and Events
Any developer who made the transition from Flash 4 to 5 knows what a major evolution ActionScript underwent in the product's last version, evolving from a simple toolkit built for artists to a relatively robust medium for a wide variety of development. With Flash MX, ActionScript is a step closer to ECMA-262 (ECMAScript) compliance, including Unicode support, a new switch statement, strict equality (===) and inequality (!==) operators, andbest of alltrue object classes and event handlers.Using ActionScript's new object syntax, developers can create custom classes rather than having to rely on loopholes in ActionScript syntax. Previously, authors could only simulate class abstraction by loading custom object constructors from external .as files or instanced MovieClips. Now, developers can register classes globally and instantiate them anywhere. ActionScript provides object prototyping through a standard object.prototype syntax. You can inherit from and override methods in existing classes, and the new form of the keyword super lets you invoke superclass methods or constructors.
Because objects can be either pure code or a combination of code and media elements in the context of a MovieClip, Flash MX offers a unique way to associate either a MovieClip symbol or a standard object class with an ActionScript class. The Object.registerClass() method that provides this service takes two arguments: the linkage identifier for a MovieClip or the name of the ActionScript class, and the class constructor. On the downside, registering MovieClips can be a bit confusing, but here's the process: To register a clip in the Library panel, choose linkage for the chosen symbol, check the Export for ActionScript option, and provide a linkage name. All new instances of registered MovieClips automatically register to the specified class. (See Listing 1 and Sample 1. You need the Flash 6 player to view the samples. You can download the beta player here.ActionScript provides flexible event handlers that respond to object events, such as mouse clicks and key presses. Instead of awkwardly attaching individual actions to objects themselves via instance ActionScripts (e.g. onclick), Flash MX exposes event handlers for prototype objects, such as MovieClip and XML. ActionScript can define or override handlers for these events.
Among the ECMA compliance features still missing from ActionScript are try, catch, throw, error trapping, runtime-compiled eval statements, and strict XML validation using DTDs. These limitations will be less critical with the forthcoming MX application integration because rigorous application engineering can be handled seamlessly on the server. In the meantime, ActionScript classes make it possible to overload problematic object functions or event handlers for greater control. For example, the XML object's onData event handler fires before the existing onLoad handler, letting you override the internal XML parser.Components
Flash MX extends Flash 5 SmartClips into new objects called Components. SmartClips offered a way to consolidate complex functionality into common library elements, such as scrollbars and charts. While the raw power of Flash Components lies in the terrain of the developer, designers will also reap many of their time-saving benefits. MX provides a set of basic UI components for forms, including checkbox, combo box, push button, etc. One of the most useful UI components is the Scroll Pane, which automates a process almost every Flash author has had to create manually at one time or another.The Component Parameters panel is another important improvement over SmartClips that greatly simplifies work for designers and developers alike. Unlike SmartClips, Flash MX components are more like traditional software components. You set properties at either design-time or run-time to manipulate a component. For example, an address form component might expose a Region parameter. Changing the parameter from US to UK could change both the visual form elements themselves, and underlying validation or other behaviors. Component parameters give designers a neat and direct interface to the component (see Figure 5).
Knowing that most applications use form elements in one way or another, Flash MX also lets designers change UI Component skins relatively easily. For global changes in a movie, find the Component Skins folder in the movie's Library and edit the chosen elements. Developers should note that new ActionScript interfaces make it possible to register component skins at runtime.The real power of Components is that you can create your own, place them in a code library, and then share them at both design- and run-time. Unfortunately, Macromedia doesn't provide any good tutorials or examples, so learning the process the first time can be mind-bending. A component is similar to a linked object, but with additional definitions for design-time control and panel docking.
To create a component, define and link a MovieClip symbol and include any additional graphical materials. In an action, wrap a class definition in an #initclip .. #endinitclip directive (this ensures that the class initializes only once). Then define the MovieClip as a component in the Library. To define parameters for the component, simply add them in the Component definition dialog in the Library. The property editor allows you to define a parameter name and a bound variable; take care not to confuse the two. The parameter name is what will appear in the Properties panel; the variable is the object variable name that will be set if the parameter is defined. For example, a parameter called value might be bound to a class variable called initValue. When you create a class instance with the parameter defined, the code this.initValue will return the parameter value. See Listing 2 and Sample 2 for a simple example of a custom component.Connecting with Flash
Flash MX offers a number of major improvements in data connectivity. The most noticeable is a twenty-fold performance boost for the on-board XML parser. Even simple XML parsing was slow in Flash 5, but data snaps into place in the Flash 6 player. Best of all, authors who have already published XML-connected movies in version 5 will benefit from the performance increase when loading those movies in the new player.Flash MX also offers two new client-side connectivity features, Local Connection and Bookmarks. Local Connection lets separate Flash movies on the same machine to send messages, data, or execute scripts between one another. One use of this feature is to converse between Flash movies on the same HTML page, for example a navigation movie and a contextual help movie. The navigation movie could update the contextual help movie when users switch between sections. The conversing movies don't even have to be in the same window.
Dynamic ContentOne major change for the MX product line is the retirement of Generator, Macromedia's server software for dynamically rendering images and other content into Flash movies. Those capabilities will appear in the the MX server releases soon. In the meantime, XML and socket communication for real-time dynamic data and text carries over from Flash 5, and Flash MX adds the ability to dynamically include both image (JPEG) and sound (MP3) content in movies at runtime. Dynamic resources are remarkably easy to use: just use the loadMovie() and loadSound() methods, respectively. Many developers got around Flash 5's inability to load images dynamically by manually creating .swf wrappers for JPEGs or MP3s. Now you can achieve the same result with the same loadMovie() syntax, and a lot less work (See Listing 3 and Sample 3). This feature is especially useful for streaming music (the second parameter of Sound.loadSound() specifies whether the sound streams or not). Previously, sounds had to be attached from the Symbol library or dragged directly into the timeline.
This technically minor addition alone will greatly evolve the Flash platform, even before the full MX product line's release. In an HTML web page, you take for granted the ability to use the HTTP protocol to load disparate elements into a coherent whole, but Flash has lacked this basic hypertext feature until now (See Figure 6).Other Features
Anyone who has built an entire website in one large Flash movie knows that you lose the ability to navigate through pages or sections with the browser history, an easy feat on HTML websites. But now, Flash MX authors can add Named Anchors to any frame on the timeline, or set the IDE to automatically create a named anchor at the beginning of every scene. Users can then navigate through Flash movies using their browser's Back and Forward buttons. Sample 4 gives a visual example of how named anchors work.Flash MX offers an ActionScript API so you can draw vector graphics directly to the stage using new MovieClip object methods. Developers can programmatically render vector shapes through line, curve, fill, and gradient methods. Authors can exploit these features for real-time data visualizations, like charts and graphs. Additional features in this and future versions include tweened masking, external media device support, improved PocketPC support, an event-savvy object-based interface to loadVariables(), and listeners that let you fired multiple responses to single events (such as a mouse click).