Graphics Reference
In-Depth Information
The last thing that happens here is another call to the
drawItem
Background
method, which you
ll remember clears the graphics and
redraws with the desired color and alpha values.
'
private function alterState(e:MouseEvent):void {
_menuItem = Sprite(e.target);
_menuItemLabel =
TextField(_menuItem.getChildByName(
"
itemText
"
));
switch(e.type) {
case MouseEvent.MOUSE_UP:
case MouseEvent.MOUSE_OVER:
_stateBackgoundColor = overBackground;
_stateBackgroundAlpha = backgroundOverAlpha;
_stateTextFormat = labelFormatOver;
break;
case MouseEvent.MOUSE_DOWN:
_stateBackgoundColor = downBackground;
_stateBackgroundAlpha = backgroundDownAlpha;
_stateTextFormat = labelFormatDown;
break;
case MouseEvent.MOUSE_OUT:
_stateBackgoundColor = upBackground;
_stateBackgroundAlpha = backgroundUpAlpha;
_stateTextFormat = labelFormatUp;
break;
}
_menuItemLabel.setTextFormat(_stateTextFormat);
drawItemBackground(_menuItem, _stateBackgoundColor,
_stateBackgroundAlpha, _menuItem.width, _menuItem.height);
}
Sample Use of SimpleMenu
The following code is the full code from the Document class
named SimpleMenuSample in the com.flashadbook.base package.
The first thing this class does is to declare a
_simpleMenu
variable
and a
_menuArr
variable. Once inside the class constructor, we
'
ll
create the new SimpleMenu using the
_menuArr
.We
ll set the pad-
ding between menu items to 10 and tell it to have a vertical layout.
The next thing we take care of is assigning actions to each menu
item using the
assignAction
method of SimpleMenu. After that,
we
'
'
ll call
setPosition
with an
x
value of 100 and a
y
valueof0,and
then we
ll add the SimpleMenu to the stage. Once again, nothing
much to it.
'
package com.flashadbook.base {
import com.flashadbook.display.SimpleMenu;
import flash.display.Sprite;
import flash.events.MouseEvent;