刮刮乐demo:flash+php
发布时间:2020-12-15 17:46:24 所属栏目:百科 来源:网络整理
导读:php ?php/** *接收来自flash的参数 *username:用户名 *goodId:商品ID *amount:购买数量(箱) **/$username = $_POST['username'];$goodId = $_POST['goodId'];$amount = $_POST['amount'];//刮奖次数$views = 3;//刮奖显示文字$prize = '恭喜您,刮中1箱
php <?php /** *接收来自flash的参数 *username:用户名 *goodId:商品ID *amount:购买数量(箱) **/ $username = $_POST['username']; $goodId = $_POST['goodId']; $amount = $_POST['amount']; //刮奖次数 $views = 3; //刮奖显示文字 $prize = '恭喜您,刮中1箱五粮液精品酒'; //测试逻辑 if($username == 'pangzimin'){ $views = 8; $prize = '恭喜您,刮中500000000万'; } //向flash返回数据 $data = $prize.'&'.$views; echo ($data); ?> html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN"> <head> <title>scratchCard</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css" media="screen"> html,body { height:100%; background-color: #ffffff;} body { margin:0; padding:0; overflow:hidden; } #flashContent { width:448px; height:297px; visibility:hidden;} </style> </head> <script type="text/javascript"> window.onload = function (){ document.getElementById('text').value = ''; } function thisMovie() { if (navigator.appName.indexOf ("Microsoft") !=-1) { return window["scratchCard"]; }else { return document["scratchCard"]; } } /** *向flash发送刮奖请求 *goodId:商品ID *amount:购买个数 **/ function sendDataToFlash(goodId,amount,username){ document.getElementById('flashContent').style.visibility = 'visible'; thisMovie().sendDataToFlash(goodId,username); } /** *检测刮出数量达到一定值自动触发函数 *value:刮奖显示文字 *checkV:检测刮出数量 **/ function sendToJs(value,checkV) { document.getElementById('text').value = value; } /** *隐藏flash函数 **/ function closeFlash(){ document.getElementById('flashContent').style.visibility = 'hidden'; } /** *立即兑换执行函数(立即兑换按钮) *value:刮奖显示文字 *checkV:检测刮出数量 **/ function scratch(value,checkV) { if(checkV == 0){ alert('你倒是刮呀'); } else if(checkV >= 6){ alert(value); }else{ alert('再多刮几下又不会怀孕:' + checkV); } } </script> <body> <div style="margin:20px auto; width:448px; height:297px;"> <div> <input id="but1" onclick="sendDataToFlash(3803,1,'pangzimin1');" name="" type="button" value="买1箱" /> <input id="but2" onclick="sendDataToFlash(3803,3,'pangzimin1')" name="" type="button" value="买3箱" /> <input id="but3" onclick="sendDataToFlash(3803,5,'pangzimin1')" name="" type="button" value="买5箱" /> <input id="but4" onclick="sendDataToFlash(3803,10,'pangzimin1')" name="" type="button" value="买10箱" /> </div> <div style=" width:448px; margin:10px; font-size:12px;"> 兑奖结果:<input id="text" style="background:#fff; color:#cc0000; width:300px; border:none;" type="text" disabled="disabled" value="" readonly="readonly" /> </div> <div id="flashContent"> <object id="scratchCard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0" width="448" height="297" id="ok" align="middle" name="ok"> <param name="allowScriptAccess" value="always" /> <param name="allowFullScreen" value = "true" /> <!-- flash的地址 --> <param name="movie" value="scratchCard.swf" /> <param name="quality" value="high" /> <param name="allowScriptAccess" value="sameDomain" /> <!-- 设置背景色 --> <param name="bgcolor" value="#ffffff" /> <!-- 传参数的地方 --> <param name="FlashVars" value="detect=6" /> <!-- src:flash的地址; bgcolor:背景色;width:宽度; height:高度--> <embed src="scratchCard.swf" allowScriptAccess="sameDomain" allowFullScreen="true" name="scratchCard" FlashVars="detect=6" quality="high" bgcolor="#ffffff" width="448" height="297" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> </div> </div> </body> </html> as3 package { /** * ... * @author .....pangzimin * @contact.....QQ:26983075 */ import flash.display.Sprite; import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.net.URLRequest; import flash.net.URLRequestMethod; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLVariables; import flash.net.URLRequestHeader; import flash.utils.ByteArray; import flash.external.ExternalInterface; import flash.display.BitmapData; import com.greensock.*; import com.greensock.easing.*; import flash.text.TextFormat; public class ScratchCard extends MovieClip { private var ScratchRequest:URLRequest = new URLRequest("http://172.16.102.18/flash/getScratch.php"); private var award:Array = new Array(); //输出文字 private var count:String = ""; //刮奖次数 private var views:Number = 0; private var txt:TextField=new TextField(); private var txt2:TextField=new TextField(); //private var bg:Sprite = createball(100,100,100); private var bg:Sprite = new Sprite(); private var bgborder:Sprite = new Sprite(); private var btn:MyBtn = new MyBtn(); private var btn2:MyBtn2 = new MyBtn2(); private var canvas:BitmapData; private var area:Number;//总面积 private var colors:Array; private var color:uint;//过滤的颜色 private var mc:Sprite=new Sprite(); var i:int = 0; var j:int = 0; private var urlLoader:URLLoader; private var phpUrl:URLRequest; private var detect:int = 0; private var username:String = ''; private var printout = ''; private var txtform:TextFormat; private var qqKF:QQKF = new QQKF(); private var closeBtn:CloseBtn = new CloseBtn(); private var goodId:int = 0; private var amount:int = 0; private var noScratchTips:NoScratchTips = new NoScratchTips(); public function ScratchCard() { ExternalInterface.addCallback ("sendDataToFlash",jscallas3); // constructor code addChild(qqKF); addChild(closeBtn); qqKF.x = 365; qqKF.y = 241; closeBtn.x = 427; closeBtn.y = 44; closeBtn.addEventListener(MouseEvent.CLICK,closeBtnClickHandler); //trace('来自HTML:'+stage.loaderInfo.parameters.detect); detect = stage.loaderInfo.parameters.detect; //username = stage.loaderInfo.parameters.username; txt.width = 240; txtform = new TextFormat(); txtform.align="center"; txtform.font = "微软雅黑"; txtform.size = 16; txt.textColor=0x525252; txt.defaultTextFormat=txtform; txt.defaultTextFormat = txtform; txt.selectable=false; //bg.graphics.lineStyle(2,0xff3300); bg.graphics.beginFill(0xffdb00); bg.graphics.drawRoundRect(0,240,33,0); bg.graphics.endFill(); //mc.width = 200; //mc.height = 80; //bgborder.graphics.lineStyle(2,0xff3300); bgborder.graphics.beginFill(0x333333); bgborder.graphics.drawRoundRect(0,0); bgborder.graphics.endFill(); InitConstructor(); } public function reSetbg():void{ //bgborder.graphics.lineStyle(2,0); bgborder.graphics.endFill(); /*try{ mc.removeChildren(0,mc.numChildren - 1); }catch(ex:Error){}*/ if(mc.numChildren != 0){ mc.removeChildren(0,mc.numChildren - 1); } j = 0; trace(mc.numChildren); } private function closeBtnClickHandler(e:MouseEvent):void{ ExternalInterface.call("closeFlash"); } private function getPHPData():void{ var urlLoader:URLLoader=new URLLoader(); var variables:URLVariables = new URLVariables(); variables.username = username; variables.goodId = goodId; variables.amount = amount; ScratchRequest.data = variables; ScratchRequest.method = URLRequestMethod.POST; urlLoader.addEventListener(Event.COMPLETE,completeHandler); urlLoader.load(ScratchRequest); } public function jscallas3(goodId:int,amount:int,username:String):void{ this.goodId = goodId; this.amount = amount; this.username = username; reSetbg(); getPHPData(); //txt2.htmlText = "<font size='16' color='#000000'>商品ID:"+goodId+" 数量:"+amount+"</font>"; } function callJs():void { //bgborder.removeEventListener(MouseEvent.MOUSE_MOVE,MouseMoveHandler); //stage.removeEventListener(MouseEvent.MOUSE_DOWN,Start); //stage.removeEventListener(MouseEvent.MOUSE_UP,Remove); //stage.removeEventListener(Event.ENTER_FRAME,mouse); ExternalInterface.call("sendToJs",count,j); } function completeHandler(evt:Event) { //trace(evt.target.data); award = evt.target.data.split('&'); //txt2.htmlText = "<font size='16' color='#000000'><b>您还能刮奖 " + award[1] + " 次</b> 用户名:"+ username +"</font>"; txt2.htmlText = "<b><font size='15' color='#0066ff'>您还能刮奖 " + award[1] + " 次 用户名:"+ username +"</font>"+"<font size='15' color='#0066ff'>商品ID:"+goodId+" 数量:"+amount+"箱</font></b>"; //几率 count = award[0]; views = (Number)(award[1]); if (count=="") { count = "谢谢参与"; } trace("formPHP:" + award + "; 奖品:" + count); //txt.htmlText = "<font size='20' color='#525252'><b>" + count + "</b></font>"; txt.text = count; if(views == 0){ stage.removeEventListener(MouseEvent.MOUSE_DOWN,Start); stage.removeEventListener(MouseEvent.MOUSE_UP,Remove); stage.removeEventListener(Event.ENTER_FRAME,mouse); bgborder.addEventListener(MouseEvent.CLICK,mcClickHandler); addChild(noScratchTips); noScratchTips.x = 237; noScratchTips.y = 78; noScratchTips.alpha = 0; noScratchTips.scaleX = 0.8; noScratchTips.scaleY = 0.8; TweenLite.to(noScratchTips,.35,{scaleX:1,scaleY:1,alpha:1,ease:Back.eaSEOut}); //stage.addEventListener(MouseEvent.MOUSE_DOWN,Start); //stage.addEventListener(MouseEvent.MOUSE_UP,Remove); //stage.addEventListener(Event.ENTER_FRAME,mouse); }else{ noScratchTips.alpha = 0; stage.addEventListener(MouseEvent.MOUSE_DOWN,Start); stage.addEventListener(MouseEvent.MOUSE_UP,Remove); stage.addEventListener(Event.ENTER_FRAME,mouse); bgborder.removeEventListener(MouseEvent.CLICK,mcClickHandler); } } private function mcClickHandler(e:MouseEvent):void{ noScratchTips.alpha = 0; noScratchTips.scaleX = 0.8; noScratchTips.scaleY = 0.8; TweenLite.to(noScratchTips,ease:Back.eaSEOut}); } private function InitConstructor() { stage.frameRate = 120; txt.text = count; //txt2.text = "调试"; txt2.width = 448; txt2.height = 30; addChild(txt2); txt.selectable = false; bg.addChild(txt); txt.x = 0; txt.y = 5; //btn.addEventListener(MouseEvent.MOUSE_OVER,btnMouSEOVER); //btn.addEventListener(MouseEvent.MOUSE_OUT,btnMouSEOUT); btn.addEventListener(MouseEvent.CLICK,btnMouseClick); btn2.addEventListener(MouseEvent.CLICK,btn2MouseClick); bgborder.addEventListener(MouseEvent.MOUSE_OVER,bgborderMouSEOVER); bgborder.addEventListener(MouseEvent.MOUSE_OUT,bgborderMouSEOUT); addChild(bgborder); addChild(bg); addChild(btn); addChild(btn2); btn.x = 152; btn.y = 186; btn2.x = 253; btn2.y = 186; bg.x = 166; bg.y = 123; bgborder.x = 166; bgborder.y = 123; addChild(mc); bg.mask = mc; //stage.addEventListener(MouseEvent.MOUSE_DOWN,Start); //stage.addEventListener(MouseEvent.MOUSE_UP,Remove); //stage.addEventListener(Event.ENTER_FRAME,mouse); } private function btn2MouseClick(e:MouseEvent):void{ getPHPData(); reSetbg(); } private function MouseMoveHandler(e:MouseEvent):void { //canvas = new BitmapData(200,80); //canvas.draw(bg); color = canvas.getPixel(stage.mouseX,stage.mouseY); //6291456 13369344 8716288 2031616 4128768 11272192 if (color != 0 && color != 5395026 && color != 14663951 && color != 10193966 && color != 7695936 && color != 12428830 && color != 11272192) { var mcs:Sprite = createball(0,10); mc.addChild(mcs); i++; mcs.x = mouseX; mcs.y = mouseY; canvas = new BitmapData(550,400); canvas.draw(stage); //trace("渲染数量" + i + " 检测刮出数量:" + j + " X:" + (stage.mouseX) + " Y:" + (stage.mouseY) + " 色素:" + canvas.getPixel(stage.mouseX,stage.mouseY)); } else { canvas = new BitmapData(550,400); canvas.draw(stage); } trace("当前色素:"+canvas.getPixel(stage.mouseX,stage.mouseY)); if (canvas.getPixel(stage.mouseX,stage.mouseY) == 5395026 || canvas.getPixel(stage.mouseX,stage.mouseY) == 14663951 || canvas.getPixel(stage.mouseX,stage.mouseY) == 10193966 || canvas.getPixel(stage.mouseX,stage.mouseY) == 7695936 || canvas.getPixel(stage.mouseX,stage.mouseY) == 12428830 || canvas.getPixel(stage.mouseX,stage.mouseY) == 11272192) { j++; trace('检测刮出:' + j); } printout = "渲染数量" + i + " 检测刮出数量:" + j + " X:" + (stage.mouseX) + " Y:" + (stage.mouseY) + " 色素:" + canvas.getPixel(stage.mouseX,stage.mouseY); txt2.htmlText = "<font size='16' color='#000000'><b>" + printout + "</b></font>"; //trace((stage.mouseX - 20) + " "+ (stage.mouseY - 20) + ":" + canvas.getPixel(stage.mouseX - 20,stage.mouseY - 20)); if (j >= detect) { callJs(); } } private function bgborderMouSEOVER(e:MouseEvent):void { buttonMode = true; } private function bgborderMouSEOUT(e:MouseEvent):void { buttonMode = false; } private function btnMouSEOVER(e:MouseEvent):void { buttonMode = true; //TweenLite.to(btn,.25,{x:58,y:170,scaleX:1.1,scaleY:1.1,alpha:.6}); } private function btnMouSEOUT(e:MouseEvent):void { buttonMode = false; //TweenLite.to(btn,{x:60,scaleX:1,alpha:1}); } private function btnMouseClick(e:MouseEvent):void { ExternalInterface.call("scratch",j); } private function chekScratch():void { //var myBitmapData:BitmapData = new BitmapData(200,80,true,0); //myBitmapData.draw(mc); //var rgb=myBitmapData.getPixel(0,0); i++; //trace(i); } private function createball(x:Number,y:Number,s:Number):Sprite { var ball:Sprite=new Sprite(); ball.graphics.beginFill(0x333333); ball.graphics.drawCircle(x,y,s); chekScratch(); return ball; } function Remove(evt:MouseEvent):void { //stage.removeEventListener(Event.ENTER_FRAME,mouse); bgborder.removeEventListener(MouseEvent.MOUSE_MOVE,MouseMoveHandler); } function Start(evt:MouseEvent):void { //stage.addEventListener(Event.ENTER_FRAME,mouse); bgborder.addEventListener(MouseEvent.MOUSE_MOVE,MouseMoveHandler); } function mouse(evt:Event):void { /*var mcs:Sprite = createball(0,10); mc.addChild(mcs); mcs.x = mouseX; mcs.y = mouseY;*/ canvas = new BitmapData(550,400); canvas.draw(stage); //trace((stage.mouseX) + " "+ (stage.mouseY) + ":" + canvas.getPixel(stage.mouseX,stage.mouseY)); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |