<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initapp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.Event;
import mx.graphics.codec.PNGEncoder;
import flash.events.TimerEvent;
import flash.utils.Timer;
private var adurl:String;
private var gameurl:String;
private var iscutpic:Boolean=false;
//加载广告
private function initapp():void{
adurl=mx.core.Application.application.parameters.adurl;
gameurl=mx.core.Application.application.parameters.gameurl;
iscutpic=mx.core.Application.application.parameters.iscutpic;
flashplay.source=adurl;
flashplay.addEventListener(Event.COMPLETE,adre);
flashplay.addEventListener(IOErrorEvent.IO_ERROR,loadGame);
}
//加载广告成功事件,3秒后加载游戏
private function adre(rs:Event):void{
var playtime:Timer=new Timer(3000,1);
playtime.addEventListener(TimerEvent.TIMER_COMPLETE,loadGame);
playtime.start();
}
//加载游戏
public function loadGame(loadrs:Event):void{
flashplay.source=gameurl;
//Alert.show(gameurl);
flashplay.addEventListener(Event.COMPLETE,flashrs);
flashplay.addEventListener(IOErrorEvent.IO_ERROR,flashfa);
}
//加载FLASH游戏成功事件,加载成功后开始截图
private function flashrs(rs:Event):void{
if(iscutpic){
cutpic();
}
}
//加载FLASH游戏失败事件
private function flashfa(fa:Event):void{
Alert.show("游戏加载失败");
}
//截图
private function cutpic():void{
var bmpData:BitmapData = new BitmapData(flashplay.width,flashplay.height);
bmpData.draw(flashplay);
var pngEnconder:PNGEncoder = new PNGEncoder();
var pngBytes:ByteArray = pngEnconder.encode(bmpData);
var request:URLRequest = new URLRequest(" http://127.0.0.1/flex/flashplayer/bin-debug/cutpic.php");
request.method = URLRequestMethod.POST;
request.contentType = "application/octet-stream";
request.data = pngBytes;
navigateToURL(request,"_blank");
}
]]>
</mx:Script>
<mx:SWFLoader verticalCenter="0" horizontalCenter="0" id="flashplay" width="100%" height="100%">
</mx:SWFLoader>
</mx:Application>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initapp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.events.Event;
import mx.graphics.codec.PNGEncoder;
import flash.events.TimerEvent;
import flash.utils.Timer;
private var adurl:String;
private var gameurl:String;
private var iscutpic:Boolean=false;
//加载广告
private function initapp():void{
adurl=mx.core.Application.application.parameters.adurl;
gameurl=mx.core.Application.application.parameters.gameurl;
iscutpic=mx.core.Application.application.parameters.iscutpic;
flashplay.source=adurl;
flashplay.addEventListener(Event.COMPLETE,adre);
flashplay.addEventListener(IOErrorEvent.IO_ERROR,loadGame);
}
//加载广告成功事件,3秒后加载游戏
private function adre(rs:Event):void{
var playtime:Timer=new Timer(3000,1);
playtime.addEventListener(TimerEvent.TIMER_COMPLETE,loadGame);
playtime.start();
}
//加载游戏
public function loadGame(loadrs:Event):void{
flashplay.source=gameurl;
//Alert.show(gameurl);
flashplay.addEventListener(Event.COMPLETE,flashrs);
flashplay.addEventListener(IOErrorEvent.IO_ERROR,flashfa);
}
//加载FLASH游戏成功事件,加载成功后开始截图
private function flashrs(rs:Event):void{
if(iscutpic){
cutpic();
}
}
//加载FLASH游戏失败事件
private function flashfa(fa:Event):void{
Alert.show("游戏加载失败");
}
//截图
private function cutpic():void{
var bmpData:BitmapData = new BitmapData(flashplay.width,flashplay.height);
bmpData.draw(flashplay);
var pngEnconder:PNGEncoder = new PNGEncoder();
var pngBytes:ByteArray = pngEnconder.encode(bmpData);
var request:URLRequest = new URLRequest(" http://127.0.0.1/flex/flashplayer/bin-debug/cutpic.php");
request.method = URLRequestMethod.POST;
request.contentType = "application/octet-stream";
request.data = pngBytes;
navigateToURL(request,"_blank");
}
]]>
</mx:Script>
<mx:SWFLoader verticalCenter="0" horizontalCenter="0" id="flashplay" width="100%" height="100%">
</mx:SWFLoader>
</mx:Application>