Game Development Reference
In-Depth Information
public function onMouseDownListener(e:MouseEvent):void {
dispatchEvent(new CustomEventClickBlock(CustomEventClickBlock.EVENT_CLICK_BLOCK,
this));
}
The makeBlockClicked function sets a GlowFilter around the block. This function is called from
Game when that class is trying to determine which Blocks to light up when the player clicks a
Block.
public function makeBlockClicked():void {
this.filters=[new GlowFilter(0xFFFFFF,70,4,4,3,3,false,false)]
}
}
}
Creating the CustomEventClickBlock class
To go along with the Block class, we need to create a new custom Event that will be dispatched
when the player clicks a Block . The custom event will be similar to the custom events we created
and put into the game framework in Chapter 2. However, we are going to put this event into the
colordrop package instead of the game framework. Why? Well, it is specific enough to the
ColorDrop game that it can live within the colordrop package.
This Event will include one property: a reference to the Block object that generated it. We will
store this reference in the block property. We also need to create an identifier that will be used by
the Block and ColorDrop classes to refer to this Event . This identifier will have the value of
eventClickBlock and will be stored in a static const named EVENT_CLICK_BLOCK .
package com.efg.games.colordrop
{
import flash.events.*;
public class CustomEventClickBlock extends Event
{
public var block:Block;
public static const EVENT_CLICK_BLOCK:String = "eventClickBlock";
public function CustomEventClickBlock(type:String, block:Block,
bubbles:Boolean=false,cancelable:Boolean=false)
{
super(type, bubbles,cancelable);
this.block = block;
}
public override function clone():Event {
return new CustomEventClickBlock(type, block, bubbles,cancelable)
}
public override function toString():String {
return formatToString(type, "type", "bubbles", "cancelable", "eventPhase");
}
}
}
Search WWH ::




Custom Search