I tried implementing CPMStar Ads in my game , but the official CPMStar readme is only for flash CS. I searched around for hours yet I can’t find a solution.
This is my code for now:
`package { import flash.display.Sprite; import net.flashpunk.Engine; import net.flashpunk.FP; import net.flashpunk.graphics.Image; import net.flashpunk.World; import flash.display.MovieClip; import flash.display.DisplayObject;
public class Main extends Engine {
public static var mainMenuWorld:MainMenuWorld;
private var ad:AdLoader;
public function Main() {
super(400, 600);
mainMenuWorld = new MainMenuWorld();
}
override public function init():void {
var adBox: MovieClip = new MovieClip();
var CPMStarContentSpotID:String = "xxxxxxxxxxxxxxx"; //spot id
var ad: DisplayObject = new AdLoader(CPMStarContentSpotID);
adBox.addChild(ad);
FP.world = mainMenuWorld;
}
}
}`
And the AdLoader:
`package { import flash.display.; import flash.events.; import flash.net.; import flash.system.;
public class AdLoader extends flash.display.Sprite {
private var cpmstarLoader:Loader;
private var contentspotid:String;
public function AdLoader(contentspotid:String) {
this.contentspotid = contentspotid;
addEventListener((Event.ADDED_TO_STAGE), addedHandler);
}
private function addedHandler(event:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, addedHandler);
Security.allowDomain("server.cpmstar.com");
var cpmstarViewSWFUrl:String = "http://server.cpmstar.com/adviewas3.swf";
var container:DisplayObjectContainer = parent;
cpmstarLoader = new Loader();
cpmstarLoader.contentLoaderInfo.addEventListener(Event.INIT, dispatchHandler);
cpmstarLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, dispatchHandler);
cpmstarLoader.load(new URLRequest(cpmstarViewSWFUrl + "?contentspotid="+contentspotid));
addChild(cpmstarLoader);
}
private function dispatchHandler(event:Event):void {
dispatchEvent(event);
}
}
} `