Macromedia flex 2 Manual

Page of 254
172
Creating Advanced Visual Components in ActionScript
Best practices when designing a 
component
Use the following practices when you design a component:
Keep the file size as small as possible.
Make your component as reusable as possible by generalizing functionality.
Use the Border class rather than graphical elements to draw borders around objects.
Use tag-based skinning.
Assume an initial state. Because style properties are on the object, you can set initial 
settings for styles and properties so your initialization code does not have to set them 
when the object is constructed, unless the user overrides the default state. 
Example: Creating a composite 
component
Composite components are components that contain multiple components. They might be 
graphical assets or a combination of graphical assets and component classes. For example, you 
can create a component that includes a button and a text field, or a component that includes 
a button, a text field, and a validator.
 
When you create composite components, you should instantiate the controls inside the 
component’s class file. Assuming that some of these controls have graphical assets, you must 
plan the layout of the controls that you are including, and set properties such as default values 
in your class file. You must also ensure that you import all the necessary classes that the 
composite component uses.
Because the class extends one of the base classes, such as 
UIComponent
, and not a controls 
class like 
Button
, you must instantiate each of the controls as children of the custom 
component and arrange them on the screen.
Properties of the individual controls are not accessible from the MXML author’s environment 
unless you design your class to allow this. For example, if you create a component that extends 
the UIComponent class and uses a Button and a 
TextArea
 component, you cannot set the 
Button control’s label text in the MXML tag because you do not directly extend the Button 
class.