Components in Flash MX 2004 have been
improved and made easier to use than their
Flash MX counterparts. If you're used to
Flash MX components, and learning MX04,
I'd suggest starting with Phil
Kerman's article on MX vs MX04 components.
It provides a good overview of the differences
between the two, and talks about how to
do what you used to do with Flash MX (v1)
components with the new v2 components.
To take an introductory look at the new
components, I've converted my FUI
components example page to provide
exactly the same functionality with v2
components (in Flash MX 2004) that was
previously done with v1 (in Flash MX).
The movie was compiled as a Flash MX 2004
movie, so you'll need the Flash
7 player to view it.
The changes one has to make to code v2
components are not big or drastic ones.
They involve
Using the addEventListener method
for the component, instead of the previous
component-specific methods like setClickHandler
and setChangeHandler, to trigger calls
to the callback handler function (or
method) when a component event happens,
Setting properties of the component
directly, instead of via getter and
setter functions, and
Using the .target property of the
object reference passed to a handler
(callback) function to access the component
that triggered it.
Another change I made to the movie was
to use ActionScript 2.0-style coding, in
which all variables are strongly typed
(even values returned by a function). This
allows us to breathe a big sigh of relief
and go back to Hungarian notation for variable
names, instead of using the previously
recommended variable extensions (_txt,
_lv, etc), and still get code hinting!
For more info about AS 2.0 coding conventions,
see Joey Lott's AS 2.0 primer for AS 1.0
coders.
As an example of the change, instead of
this Flash MX code (in
frame 1 of the main movie) to cause user
combobox selections to change the color
of a movieclip object:
we now use this code with the v2 combobox
(in Flash MX 2004) to
produce the same effect:
function
changeColor(obj):Void {
cSquiggle.setRGB(obj.target.selectedItem.data);
}
var
cSquiggle:Color = new Color(mcSquiggle);
var
aColors:Array = [
{label:'gray',
data:0x666666},
{label:'red',
data:0xff0000},
{label:'green',
data:0x00ff00},
{label:'blue',
data:0x0000ff}];
cbColor.dataProvider
= aColors;
cbColor.selectedIndex
= 0;
cbColor.addEventListener("change",
changeColor);
Similar changes were made to the code for
each of the other components in the example.
Component settings were manually set (in
the Properties window parameters tab) as
described in the original FUI components
article. Download the fla and look in the
code layer for the corresponding component
in the file to see those changes. One surprising
thing to note is that the fla for this
sample went from 426k in the Flash MX version
to 1.1M in the MX04 version! (even after
a Save and compact) The corresponding swf
also, rather disappointingly, more than
doubled, from 28k to 65k. This is the size
of each of five swf's made from the individual
components in the movie:
Wildform
provides a 100% satisfaction guarantee on all our Flash software.
If you are not completely satisfied with our Flash multimedia software
for any reason you may request a refund within 15 days
of purchase.