Game Development Reference
In-Depth Information
class (you may have added these lines previously when you added the STATE_SYSTEM_PRELOAD for
the Flash IDE):
public static const STATE_SYSTEM_MOCHI_AD:int = 10;
public static const STATE_SYSTEM_MOCHI_HIGHSCORES:int = 12;
We also need to add some new variables to GameFrameWork.as to support the Mochi services.
mochiGameID is the Mochi supplied ID that Mochi uses to reference this game. mochiBoardId is the
Mochi supplied ID used to reference the leader board for this game. lastScore is a variable we
will create that will hold the last score a player received for a game. We will use this variable to
send to the score to the Mochi leader board.
//*** added chapter 12 for Mochi Ads and Highscores
public var mochiGameId:String;
public var mochiBoardId:String;
public var lastScore:Number;
Changing switchSystemState
The changes to the GameFrameWork.as switchSystemState function are similar to the ones we
presented earlier in the Flash IDE preloader section.
You will need to make sure that the following two additional states are added to the
switchSystemState function:
case FrameWorkStates.STATE_SYSTEM_MOCHI_AD:
systemFunction = systemMochiAd;
break;
case FrameWorkStates.STATE_SYSTEM_MOCHI_HIGHSCORES:
systemFunction = systemMochiHighscores;
break;
Making Mochi ad-specific changes
The systemMochiAd function must be added to GameFrameWork.as . It calls the Mochi class and
requests an ad to be displayed dynamically. We pass in the resolution (example: res:600x400 )
and a function ( mochiAdComplete ) to be called if the ad completes or is skipped, or if an error
occurs. More options for the ads are described in the latest Mochi documentation, and new
features are also being added all the time. This is a basic implementation of the Mochi ad
functionality:
public function systemMochiAd():void {
//format resolotion as string example: 600x400
var resolution:String = stage.width + "x" + stage.height;
MochiAd.showPreGameAd({clip:this, id:mochiGameId, res:resolution,
ad_finished:mochiAdComplete, ad_failed:mochiAdComplete,
ad_skipped:mochiAdComplete});
switchSystemState(FrameWorkStates.STATE_SYSTEM_WAIT_FOR_CLOSE);
nextSystemState = FrameWorkStates.STATE_SYSTEM_TITLE;
}
//*** new Function for Mochi ads chapter 12
public function mochiAdComplete():void {
Search WWH ::




Custom Search