Game Development Reference
In-Depth Information
Creating the CustomEventHeartsNeeded.as class
This class will be very similar to the custom Event classes we created in Chapter 2. This one will
be part of the Drive She Said package rather than the framework package.
Here is the file name and location for the Flash IDE:
/source/projects/driveshesaid/flashIDE/com/efg/games/driveshesaid/CustomEventHeartsNee
ded.as
Here is the file name and location for the Flex SDK (using Flash Develop):
/source/projects/driveshesaid/flexSDK/src/com/efg/games/driveshesaid/CustomEventHearts
Neeeded.as
This class is a very simple subclass of the Event class. Here is the full source:
package com.efg.games.driveshesaid
{
import flash.events.Event;
/**
* ...
* @author Jeff Fulton
*/
public class CustomEventHeartsNeeded extends Event{
public static const HEARTS_NEEDED:String = "hearts needed";
public var heartsNeeded:String;
public function CustomEventHeartsNeeded(type:String,heartsNeeded:String,
bubbles:Boolean=false,cancelable:Boolean=false) {
super(type, bubbles,cancelable);
this.heartsNeeded = heartsNeeded;
}
public override function clone():Event {
return new CustomEventHeartsNeeded(type,heartsNeeded, bubbles,cancelable)
}
}
}
When an instance of this class is created, the heartsNeeded value is passed in and the listening
function will be able to retrieve it. You'll see this in action when we get to the newLevel function in
the DriveSheSaid class.
Creating the Library.as class
The Library.as class is only necessary for those using the Flex framework. It is not used for
Flash IDE projects. The changes to the library have to do with adding the sounds as static
const assets rather than having them inside an exported SWF from the IDE. By doing this, we
free the game from needing the IDE at all. The one drawback to using assets embedded at run-
time is the inability of the Flex framework to import .wav files. By using .mp3 files, we mitigate this
Search WWH ::




Custom Search