Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 17

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

The following example shows two components based on the Flex
defined in ActionScript and the other in MXML:
MyASButton.as
package
{
public class MyASButton extends Button
{
// Override inherited methods
// and properties.
// Define new methods
// and properties.
// Define custom logic
// in ActionScript.
}
}
Both implementations create a component as a subclass of the Button class and, therefore,
inherit all of the public and protected properties, methods, and other elements of the Button
class. Within each implementation, you can override inherited items, define new items, and
add your custom logic.
You cannot override an inherited property defined by a variable, but you can override a
property defined by setter and getter methods. You can reset the value of an inherited
property defined by a variable. You typically reset it in the constructor of the subclass for
an ActionScript component, or in an event handler for an MXML component because
MXML components cannot define a constructor.
However, when you use MXML, the Flex compiler performs most of the overhead required to
create a subclass of a component for you. This makes it much easier to create components in
MXML than in ActionScript.
Deciding to create components in MXML or ActionScript
One of the first decisions that you must make when creating custom components is deciding
whether to write them in MXML or in ActionScript. Ultimately, it is the requirements of your
application that determine how you develop your custom component.
Button.as
MyMXMLButton.mxml
<mx:Button>
<mx:Script>
// Override inherited methods
// and properties.
// Define new methods
// and properties.
// Define custom logic
// in ActionScript.
</mx:Script>
<!-- Add MXML code. -->
</mx:Button>
Button
component, one
About creating components
17

Advertisement

Table of Contents
loading

Table of Contents