flash游戏吧 关注:9,647贴子:43,037
  • 3回复贴,共1
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextField;
public class egg extends MovieClip{
public function egg(){
this.addEventListener(MouseEvent.MOUSE_OVER,overEgg);//移入
this.addEventListener(MouseEvent.MOUSE_OUT,outEgg);//移出
this.addEventListener(MouseEvent.MOUSE_DOWN,downEgg);
}
public function overEgg(e:MouseEvent):void{
this.gotoAndPlay(2);
}
public function outEgg(e:MouseEvent):void{
this.gotoAndStop(1);
}
public function downEgg(e:MouseEvent):void{
this.removeEventListener(MouseEvent.MOUSE_OVER,overEgg);//移出侦听
this.removeEventListener(MouseEvent.MOUSE_OUT,outEgg);//移出侦听
this.removeEventListener(MouseEvent.MOUSE_DOWN,downEgg);//移出侦听
if(Math.random()>0.9)
this.t.text="中奖了!";
else
this.t.text="谢谢合作";
this.gotoAndPlay("crack");
}
}
}
要求:对砸金蛋游戏进行修改,改成游戏有且仅有一个金蛋显示中奖信息。


1楼2013-11-19 19:22回复
    1.给蛋加一个删除所有鼠标事件的方法,在有一个蛋咋中奖了之后将调用剩余未砸的蛋删除事件方法。
    2.给蛋增加一个变量表示能否中奖,初始化时从所有蛋中随机取出一个设置成有奖,剩余全部设置成没奖。


    IP属地:河南2楼2013-11-23 01:20
    收起回复