PackageTop Level
Classpublic class OptionPanel

The class represents the small panel that shows up when the user clicks on the arrow button. There can be any number of buttons on it, and it is possible to add or remove buttons from it. Do not create an instance of this class - instead use the global optionPanel object.

See also

Global.optionPanel


Public Methods
 MethodDefined by
  
addButton(button:OptionButton):void
Adds the given button to the panel.
OptionPanel
  
buttonCount():Number
Returns the number of buttons on the option panel.
OptionPanel
  
close():void
Closes the option panel.
OptionPanel
  
getButtonAt(index:Number):void
Gets the button at the specified index.
OptionPanel
  
isOpen():Boolean
Returns true if the panel is open.
OptionPanel
  
open():void
Opens the option panel.
OptionPanel
  
Removes the specified button.
OptionPanel
Method detail
addButton()method
public function addButton(button:OptionButton):void

Adds the given button to the panel.

Parameters
button:OptionButton — The button to add to the panel.

Example
The following code creates a new button and add it to the panel.
  
 -- Create the button  
 button = OptionButton:new()  
 button:setName("my button")  
  
 -- Register an event listener  
 button:addEventListener("click", "button_click")  
  
 -- Add it to the option panel  
 optionPanel:addButton(button)  
  
 function button_click(event)  
     dialogs:showMessage("'"..event.sender:getName().."' has been clicked!")  
 end  
 

buttonCount()method 
public function buttonCount():Number

Returns the number of buttons on the option panel.

Returns
Number — Number of buttons.

Example
This script loops through all the option buttons and returns the one with the given name.
  
 function getButtonByName(buttonName)  
     buttonCount = optionPanel:buttonCount()  
  
     for i = 0, (buttonCount - 1) do  
         button = optionPanel:getButtonAt(i)  
         if buttonName == button:getName()  
             return button  
         end  
     end  
 end  
  
 helpButton = getButtonByName("Help")  
 

close()method 
public function close():void

Closes the option panel.

getButtonAt()method 
public function getButtonAt(index:Number):void

Gets the button at the specified index.

Parameters
index:Number — Button index.

See also

isOpen()method 
public function isOpen():Boolean

Returns true if the panel is open.

Returns
Booleantrue if the panel is open.

Example
This code toggles the option panel on and off:
  
 function toggleOptionPanel()  
     if optionPanel:isOpen() then  
         optionPanel:close()  
     else  
         optionPanel:open()  
     end  
 end  
  
 toggleOptionPanel()  
 

open()method 
public function open():void

Opens the option panel.

removeButton()method 
public function removeButton(button:OptionButton):void

Removes the specified button.

Parameters
button:OptionButton — The button to remove from the panel.

Example
This script removes the last button from the panel.
  
 lastButton = optionPanel:getButtonAt(optionPanel:buttonCount() - 1)  
 optionPanel:removeButton(lastButton)