Flex 2 Notes: World of Buttons
Some notes I took going through the manual…
Old Fashion Button
Q: When to use a button control?
A: When you need to elicit user gesture to fire an event.
Quick Code:
creationComplete="null">
width="150"
icon="@Embed(source='warning.gif')"
click="myTextArea.text = btn.label"
/>
height="20"
/>
Pop-up Button Control
Q: When to use a pop-up button control?
A: When you want the button to take on different modes but you don’t want to instantiate a button for each mode.
Quick Code:
creationComplete="null">
import mx.controls.*;
import mx.events.*;
private var myMenu:Menu;
// Initialize the Menu control, and specify it as the pop up object
// of the PopUpButton control.
private function initMenu():void
{
myMenu = new Menu();
myMenu.dataProvider = [{label: "Offence"}, {label: "Defence"},
{label: "Retreat"}];
myMenu.addEventListener("itemClick", changeHandler);
popUpBtn.popUp = myMenu;
}
// Define the event listener for the Menu control's change event.
private function changeHandler(event:MenuEvent):void
{
var label:String = event.label;
status.text="Set mode to " + label;
popUpBtn.label = label;
}
public function displayMode():void
{
if (popUpBtn.label != "Select Mode")
{
status.text = "Launching " + popUpBtn.label + "!";
}
}
]]>
width="135"
creationComplete="initMenu();"
click="displayMode();"
/>
Toggle Button Bar
Q: When to use a toggle button bar control?
A: When you want to have your user to be faced with multiple choices but only one can be selected. Think of it as one giant button with many options but only one handler called ‘itemClick’
Quick Code:
creationComplete="null">
import mx.events.ItemClickEvent;
private function clickHandler(e:ItemClickEvent):void
{
if (e.index == 2)
{
myTextArea.text = "You are a freggin genius!";
}
else
{
myTextArea.text = "You need to work on your math";
}
}
]]>
height="20"
text="What is 1 + 1?"
/>
itemClick="clickHandler(event);"
>





August 21st, 2006 at 8:25 pm
[...] [ Read more… ] [...]