128
Creating Simple Visual Components in ActionScript
}
break;
// Was Ctrl-M pressed?
case 77 :
if (currentFontSize > minFontSize) {
currentFontSize = currentFontSize - 1;
setStyle('fontSize', currentFontSize);
}
break;
default :
break;
}
}
}
}
}
Notice that the call to the
getStyle()
method is in the event listener for the
creationComplete
event. You must wait until component creation is complete before calling
getStyle()
to ensure that Flex has set all inherited styles. However, you can call
setStyle()
in the component constructor to set styles.
This example uses variables to define public properties to control the maximum font size,
maxFontSize
, and minimum font size,
minFontSize
, of the control. Users can set these
properties in MXML, as the following example shows:
<?xml version="1.0"?>
<!-- as/MainTextAreaFontControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<MyComp:TextAreaFontControl id="myTAFS"
minFontSize="8"
maxFontSize="50"/>
<mx:Button
label="Get Font Size"
click="myTA.text=String(myTAFS.getStyle('fontSize'));"/>
<mx:TextArea id="myTA"/>
</mx:Application>
Defining public properties by using getter and setter methods
There are no restrictions on using public variables to define public properties, However,
Adobe recommends that you use getter and setter methods so that you can control user
interaction with your component, as described in
“Defining properties as getters and setters”
on page 30
.
Содержание 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...