Académique Documents
Professionnel Documents
Culture Documents
Data Grid
if (myDataGrid.selectedIndex != -1)
{
var myData:Object = myDataGrid.selectedItem;
}
-1 means not found. This IF statement helps to evaluate whether a user has selected a row in a
DataGrid or List control
Bindable variable
- able to keep track of the value of the variables as the program runs, eliminates the need of
creating eventListener
- the convention is as follow:
<mx:Script>
<![CDATA[
[Bindable]
private var myVar:String
]]>
</mx:Script>
<mx:Binding source=”myInput.text” destination=”myVar”/>
<mx:TextInput id=”myInput”/>
<mx:Label text=”{myVar}”/>
Static properties
A static property is a value that’s the same for all instances of the component; it also can be referred
to by other parts of the application without having to instantiate the component at all. You make a
property static by adding the static keyword after the access modifier:
public static var myStaticVar:String;
Using constants
A constant is a property whose value is set at the time of declaration and never changes
private const ALLPRODUCTS:String=”All Products”;
by convention, it is recommended to be uppercased.
Handling event
- to know it’s target properties
private function clickHandler(event:Event):void
{
myLabel.text=”You clicked the button labeled “ +
event.target.label;
}
Extended MouseEvent
- altKey:Boolean: Set to true if the Alt key is held down when the event is dispatched;
otherwise false.
- ctrlKey:Boolean: Set to true if the Ctrl key is held down when the event is dispatched;
otherwise false.
- shiftKey:Boolean: Set to true if the Shift key is held down when the event is dispatched;
otherwise false.
- commandKey:Boolean: Set to true if the command key on the Mac is held down when the
event is dispatched; otherwise false. Always set to false on Windows.
- localX:int: The number of pixels from the left border where the user clicked an object
dispatching the event.
- localY:int: The number of pixels from the top border where the user clicked an object
dispatching the event.
- stageX:int: The number of pixels from the left border where the user clicked the stage (Flash
Player region).
- stageY:int: The number of pixels from the top border where the user clicked the stage (Flash
Player region).
- buttonDown:Boolean: Set to true if the primary mouse button is pressed when the event is
dispatched; otherwise false.
Eg: myLabel.text=”The “ + event.type + “ event was dispatched by “ + event.target.id;
altLabel.text=”Alt key pressed: “ + event.altKey;
ctrlLabel.text=”Ctrl key pressed: “ + event.ctrlKey;
shiftLabel.text=”Shift key pressed: “ + event.shiftKey;
Buttons
Toggle
<mx:Button id="toggleButton" label="Toggle Button" toggle="true"/>
Add icon to button
[Bindable]
[Embed(source=”graphics/deleteIcon.png”)]
public var myDeleteIcon:Class;
<mx:Button id=”deleteButton” label=”Delete” icon=”{myDeleteIcon}” labelPlacement=”right”/>
labelPlacement can be right, left, top, bottom
Check Box
private function checkSelected():void{
if (myCheckBox.selected){
Alert.show("You selected the CheckBox");
}
else{
Alert.show("You didn’t select the CheckBox");
}
}
Radio Button
private function activateFunction():void{
Alert.show(“You have selected ” + buttonGroup.selectedValue.toString());
}
<mx:RadioButtonGroup id=”buttonGroup” change=”activateFunction()”/>
<mx:RadioButton value=”Small” label=”Small” groupName=”buttonGroup” selected=”true”/>
set one of them to true as default value
<mx:RadioButton value=”Medium” label=”Medium” groupName=”buttonGroup”/>
<mx:RadioButton value=”Large” label=”Large” groupName=”buttonGroup”/>
Panel
<mx:Panel id="myPanel" x="285" y="37" width="250" height="200" layout="absolute" title="Panel"
status="status" roundedBottomCorners="true" borderAlpha="1.0" alpha="1.0" cornerRadius=”15”>
adding control bar to panel, including buttons and spacer
<mx:ControlBar>
<mx:Button label="Button"/>
<mx:Spacer width=”100%”/>
<mx:Button label="Button"/>
</mx:ControlBar>
add an icon
[Embed(source=”assets/questionicon.png”)]
private var questionIcon:Class;
Alert.show(“An Alert dialog box with custom icon”, “Alert Event Handler”, 0, null, null,
questionIcon);
Effects in Flex
(or)
var myFade:Fade = new Fade();
myFade.target = myImage;
myFade.alphaFrom = 0; // from invisible
myFade.alphaTo = 1; // to visible
myFade.play();