V2 Components

 <  Day Day Up  >  

V2 Components

All UI components that come with Flash MX 2004 have been rewritten in ActionScript 2.0. The components run faster and are lighter weight than the v1 components. The components use classes, the extends keyword, and the other techniques mentioned previously, including the getter and setter methods . For example, if you needed to populate a combo box with data, rather than using the setDataProvider method, you would use the dataProvider getter/setter method:

 cbTypes.dataProvider = types_array; 

V2 components are very different than v1 components, and the v2 components were built with OOP best practices in mind. V2 components will work only with Flash Player 7.

Note that Macromedia does not recommend combining v1 and v2 components in the same file. Of course, you can still target the Flash Player 6 using v1 components. V2 components inherit from specialized component classes (the UIcomponent and classUIobject classes), and they inherit from the MovieClip class. The new hierarchy of UIobject and UIcomponent classes makes building and customizing components a much easier process.

V2 components are located in FLA files external to the movie. However, v2 components can now be compiled into SWC files. This enables a faster compilation time and conceals component code. Any movie clip can be exported as a SWC file by right-clicking the symbol in the Library, and then making the appropriate selections. In addition, all the components that come with Flash MX 2004 use SWC files (although the FLAs are also included to enable developers to understand the component architecture).

N OTE

Component architecture is covered in detail in Chapter 9, "Building and Using UI Components."


V2 components use an event listener model syntax to handle events. For example, to set up an onChange handler on a combo box, which calls a function when the user makes a selection in the combo box, you would use the following code:

 var cbTypes:ComboBox; var eventObj = new Object(); eventObj.change = function(){              trace ("combo box selected"); } cbTypes.addEventListener("change", eventObj); 
 <  Day Day Up  >  


Object-Oriented Programming with ActionScript 2.0
Object-Oriented Programming with ActionScript 2.0
ISBN: 0735713804
EAN: 2147483647
Year: 2004
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net