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:

xmlns="*"
creationComplete="null">

label="Hello World!"
width="150"
icon="@Embed(source='warning.gif')"
click="myTextArea.text = btn.label"
/>

width="150"
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:

xmlns="*"
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 + "!";
}
}

]]>

label="Select Mode"
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:

xmlns="*"
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";
}
}
]]>

width="200"
height="20"
text="What is 1 + 1?"
/>

horizontalGap="5"
itemClick="clickHandler(event);"
>


1.3
3**9
2
All of the above



One Response to “Flex 2 Notes: World of Buttons”

  1. Flexed » knowledge.lapasa.net » Flex 2 Notes: World of Buttons Says:

    [...] [ Read more… ] [...]

Leave a Reply