Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 137

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

Advertisement

Defining a method override
You can override a method of a base class in your ActionScript component. To override the
method, you add a method with the same signature to your class, and prefix it with the
keyword. The following example overrides the
override
an Alert box when a new item is added to it:
package myComponents
{
import mx.controls.Alert;
import mx.containers.HBox;
import flash.display.DisplayObject;
public class HBoxWithAlert extends HBox
{
// Define the constructor.
public function HBoxWithAlert()
{
super();
}
// Define the override.
override public function addChild(child:DisplayObject):DisplayObject {
// Call super.addChild().
super.addChild(child);
// Open the Alert box.
Alert.show("Item added successfully");
return child;
}
}
}
Notice that the method implementation calls the
causes Flex to invoke the superclass's
super.addChild()
operation. Your new functionality to open the Alert box occurs after the
method.
You might have to use
code, or not at all. The location is determined by your requirements. To add functionality to
the method, you call
call
at all.
super()
to call the base class method before your code, after your
super()
before your code. To replace the base class method, you do not
super()
HBox.addChild()
super.addChild()
addChild()
Adding properties and methods to a component
method to open
method. The call to
method to perform the
super.addChild()
137

Advertisement

Table of Contents
loading

Table of Contents