About ActionScript components
123
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
mx.controls.TextArea
component. This component adds
an event listener for the
keyDown
event to the TextArea control. The
KeyDown
event deletes all
the text in the control when a user presses the 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
package
statement. For
more information on using the
package
statement, and specifying the directory location of
your components, see
Chapter 3, “Using ActionScript to Create Components,” on page 25
.
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>
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...