Game Development Reference
In-Depth Information
private function addedToStage(e:Event):void {
playButton.addEventListener(MouseEvent.CLICK,
playButtonClick, false, 0, true);
rulesButton.addEventListener(MouseEvent.CLICK,
rulesButtonClick, false, 0, true);
}
private function playButtonClick(e:MouseEvent):void {
dispatchEvent(new Event(PLAY_GAME));
}
private function rulesButtonClick(e:MouseEvent):void {
dispatchEvent(new Event(SHOW_RULES));
}
}
As you can see, the logic behind this screen is very simple.
When either of the two buttons on the Title screen are clicked,
events are dispatched with names corresponding to the listeners
we saw in the MixUp class. Adding buttons to this screen is as sim-
pleasaddingaconstantfortheeventitgeneratesavariablefor
the DisplayObject and a listener for button click.
The RulesPanel Class
From the Title screen, the player can choose to view the rules panel.
In the MixUp class, we saw how this panel is instantiated and added
to the Stage. Now, we
'
ll look at the internal logic behind it.
public class RulesPanel extends Sprite {
public var closeButton:SimpleButton;
public function RulesPanel() {
addEventListener(Event.ADDED_TO_STAGE, addedToStage,
false, 0, true);
}
private function addedToStage(e:Event):void {
TweenLite.from(this, .4, { y :
height } );
closeButton.addEventListener(MouseEvent.CLICK,
closeButtonClick, false, 0, true);
}
private function closeButtonClick(e:MouseEvent):void {
closeButton.removeEventListener(MouseEvent.
CLICK, closeButtonClick);
Search Nedrilad ::




Custom Search