Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 123

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

Advertisement

Example: Creating a simple component
When you define a simple component, you do not create a component yourself, but you
modify the behavior of an existing component. In this section, you create a customized
TextArea control by extending the
an event listener for the
the text in the control when a user presses the Control+Z key combination:
package myComponents
{
// as/myComponents/DeleteTextArea.as
import mx.controls.TextArea;
import flash.events.KeyboardEvent;
public class DeleteTextArea extends TextArea {
// Constructor
public function DeleteTextArea() {
// Call super().
super();
// Add event listener for keyDown event.
addEventListener("keyDown", myKeyDown);
}
// Define private keyDown event handler.
private function myKeyDown(eventObj:KeyboardEvent):void {
// Check to see if Ctrl-Z pressed. Keycode for Z is 90.
if (eventObj.ctrlKey && eventObj.keyCode == 90)
text = "";
}
}
}
The filename for this component is DeleteTextArea.as, and its location is in the
myComponents subdirectory of the application, as specified by the
more information on using the
your components, see
You can now use your new TextArea control in an application, as the following example
shows:
<?xml version="1.0"?>
<!-- as/MainDeleteTextArea.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:DeleteTextArea/>
</mx:Application>
mx.controls.TextArea
event to the TextArea control. The
keyDown
statement, and specifying the directory location of
package
Chapter 3, "Using ActionScript to Create Components," on page
component. This component adds
event deletes all
KeyDown
statement. For
package
About ActionScript components
25.
123

Advertisement

Table of Contents
loading

Table of Contents