Graphics Reference
In-Depth Information
private var _labelFormatOver:TextFormat = new
TextFormat();
private var _labelFormatDown:TextFormat = new
TextFormat();
//
———
color, alpha and format used for different
states of the menu items
private var _stateBackgoundColor:uint =
upBackground;
private var _stateBackgroundAlpha:Number =
backgroundUpAlpha;
private var _stateTextFormat:TextFormat =
labelFormatUp;
public function SimpleMenu(menuArray:Array,
spacing:Number = 0, layout:String =
"
horizontal
"
){
_layout = layout;
_spacing = spacing;
setDefaultFormats();
menuArray.forEach(createMenuItem);
}
public function assignAction(itemIndex:int,
action:Function):void {
_menuItem = Sprite(getChildByName(
"
menuItem
"
+
itemIndex));
_menuItem.addEventListener(MouseEvent.CLICK,
action, false, 0, true);
}
public function
setPosition(xPosition:Number,yPosition:Number):void{
x = xPosition;
y = yPosition;
}
// START PRIVATE FUNCTIONS
private function setDefaultFormats():void {
labelFormatUp.color = 0xFFFFFF;
labelFormatUp.underline = false;
labelFormatOver.color = 0xCCCCCC;
labelFormatOver.underline = true;
labelFormatDown.color = 0x000000;
labelFormatDown.underline = true;
}
private function createMenuItem(itemLabel:String,
index:int, array:Array):void {
_menuItem = new Sprite();
_menuItem.name =
"
menuItem
"
+ index;