Macromedia flex 2 Manuale

Pagina di 254
92
Creating Advanced MXML Components
With loosely coupled components, you typically define properties of the component to pass 
information to it. These properties, defined by using variables or setter and getter methods, 
specify the data type of the parameter value. For more information about defining component 
properties, see 
The best practice for defining components that return information back to the main 
application is to design the component to dispatch an event that contains the return data. In 
that way, the main application can define an event listener to handle the event and take the 
appropriate action. For more information on dispatching events, see 
.
Adding custom properties and methods 
to a component
MXML components provide you with a simple way to create ActionScript classes. When 
defining classes, you use class properties to store information and class methods to define class 
functionality. When creating MXML components, you can also add properties and methods 
to the components. 
One of the reasons that you add properties and methods to your components is to make them 
configurable. By allowing the user to pass information to the components, you can create a 
reusable component that you can use in multiple locations throughout your application, or in 
multiple applications. 
This section describes how to define properties of MXML components in MXML tags or as 
ActionScript variables, and how to define new methods of an MXML component by using 
ActionScript functions. 
Defining properties and methods in MXML 
components
You can define methods for your MXML components in ActionScript, and properties in 
ActionScript or MXML. The Flex compiler converts the MXML component into an 
ActionScript class, so there is no performance difference between defining a property in 
MXML and defining it in ActionScript.