Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 127

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

Advertisement

Defining public properties as variables
In the following example, you use the Control+I key combination to extend the
control to let the user increase the font size by one point, or use the Control+M key
combination to decrease the font size by one point:
package myComponents
{
// as/myComponents/TextAreaFontControl.as
import mx.controls.TextArea;
import flash.events.KeyboardEvent;
import flash.events.Event;
public class TextAreaFontControl extends TextArea
{
// Constructor
public function TextAreaFontControl() {
super();
// Add event listeners.
addEventListener("keyDown", myKeyDown);
addEventListener("creationComplete", myCreationComplete);
}
// Define private var for current font size.
private var currentFontSize:Number;
// Define a public property for the minimum font size.
public var minFontSize:Number = 5;
// Define a public property for the maximum font size.
public var maxFontSize:Number = 15;
// Initialization event handler for getting default font size.
private function myCreationComplete(eventObj:Event):void {
// Get current font size
currentFontSize = getStyle('fontSize');
}
// keyDown event handler.
private function myKeyDown(eventObj:KeyboardEvent):void {
// Was Ctrl key pressed?
if (eventObj.ctrlKey)
{
switch (eventObj.keyCode) {
// Was Ctrl-I pressed?
case 73 :
if (currentFontSize < maxFontSize) {
currentFontSize = currentFontSize + 1;
setStyle('fontSize', currentFontSize);
Adding properties and methods to a component
TextArea
127

Advertisement

Table of Contents
loading

Table of Contents