织梦学习网,专业提供DEDECMS模板,DEDECMS教程,网页特效素材等建站资源!
当前位置:ca88老虎机 > 网页设计 > Flash教程 >

flash as3实现打字小游戏代码

整理编辑:织梦学习网 更新时间:2017-05-09 阅读:

ca88老虎机 www.casmzx.com    游戏效果

flash as3实现打字小游戏代码

  新建Fla,在第一帧F9添加代码即可。

 代码如下  

var arr:Array = new Array();
var time:uint=0;
var angle:Number=0;
var zfun;
[SWF(width=800, height=465,backgroundColor=0xffffff, frameRate=24)]
this.addEventListener(Event.ENTER_FRAME,function(event){
 time++;
 angle+=0.1;
      if(time>=13){
           var tf:TextField = addChild(new TextField()) as TextField;
     zfun = function(){time = 0,tf.htmlText ='<font size="'+String(Math.round(Math.random()*35)+15)+'" color="#'+String(Math.random()*16777215)+'">'+ String.fromCharCode(int(Math.random()*26+65).toString())+'</font>',tf.x = Math.random()*-760+780,tf.y = -10,tf.name = (Math.random()*-10+5).toString(),arr.unshift(tf)}.apply();   
      }
      for(var i:Number = arr.length-1;i>=0;i--){
     zfun =function(){arr[i].y+=3,arr[i].x+= Math.sin(angle)*int(arr[i].name)}.apply();
           if(arr[i].y>=stage.stageHeight){
                        zfun =function(){removeChild(arr[i]),arr.splice(i,1)}.apply();
      break;
           }
      }
});
stage.addEventListener(KeyboardEvent.KEY_DOWN,function(event){ 
    for(var i:Number = arr.length-1;i>=0;i--){
            if(arr[i].text==String.fromCharCode(event.keyCode)){
                         zfun =function(){removeChild(arr[i]),arr.splice(i,1)}.apply();
       break;
            }
        }
});

转载请注明出处:http://www.casmzx.com/wysj/flash/3213.html

关键词: flash
ca88老虎机