Newsletter: Learn More ||| Multimedia Presentation Software |||
Flash MX 2004 Pro Components
Contents Download the FLA for this tutorial here.
Introduction
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.
Changes to v2 Components
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.
Using ActionScript 2.0-style coding
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:

function changeColor(comp) {
  squiggle_color.setRGB(comp.getSelectedItem().data);
}  
var squiggle_color = new Color(squiggle_mc);
colors_arr = [
  {label:'gray', data:0x666666},
  {label:'red', data:0xff0000},
  {label:'green', data:0x00ff00},
  {label:'blue', data:0x0000ff}};
color_cb.setDataProvider(colors_arr};
color_cb.setSelectedIndex(0);
color_cb.setChangeHandler('changeColor');

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:

push button 27k
textarea   40k
combobox   56k
listbox   48k
radio buttons   30k
This tutorial was written by Helen Triolo.
 
©2007 Wildform, Inc | Policies | Contact Us | Newsletter Options
 
©2010 Wildform, Inc | Policies | Contact Us | Newsletter Options
 
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.