Graphics Reference
In-Depth Information
beneath that index to get the reference we need. Finally, we
ll run a
quick switch statement to check the _layout of the SimpleMenu.
Depending on that value, we know to place the current menu item
either beneath the lastItem (VERTICAL) or beside it (HORIZONTAL) .If
some other value was passed in when the SimpleMenu was instan-
tiated, now is the time to let the developer know he or she has
made a mistake and inform him or her of the acceptable values.
That gets taken care of in the default case of the switch statement.
'
private function
placeItem(itemToPlace:Sprite,index:int):void {
if(index == 0) return;
var lastItem:Sprite = Sprite(getChildAt(index - 1));
switch(_layout){
case HORIZONTAL:
itemToPlace.x = lastItem.x + lastItem.width +
_spacing;
break;
case VERTICAL:
itemToPlace.y = lastItem.y + lastItem.height +
_spacing;
break;
default:
trace( ' Please use a String value of
" horizontal " or " vertical " for the SimpleMenu layout
param. ' );
break;
}
}
s only one method left
to cover in the SimpleMenu class and that is the alterState
method. If you recall, the addItemListeners method added
MouseEvent listeners to change the states of the menu items. The
alterState method handles the changing of the background color,
the background alpha, and the formatting of the label as a menu
item is interacted with. Again, this is a very simple method because
it is just checking the type of MouseEvent that occurred and setting
the values accordingly. One thing to note in the switch statement is
that there is nothing for the MouseEvent.MOUSE_UP case (not even a
break ). You
Other than the getter and setters, there
'
'
ll also notice that the MouseEvent.MOUSE_OVER case is
directly after it. By leaving that first case blank, the outcome is the
same for both the upstate and the overstate. The thinking behind
that is that when you put the item in a downstate and then bring it
back to the upstate, your mouse is still over the item. In that case,
the upstate should be the same as the overstate. Once the mouse
triggers the MouseEvent.MOUSE_OUT event, then I set all the styling
back to the real upstate styling that was originally intended.
Search WWH ::




Custom Search