请教关于动态文本一个小问题
1、想要让mc被点击的时候,动态文本显示计数,例如hist:1。点击第二个时,显示hist:2
2、当mc离开厂家后,同上,显示miss:1、2、3.。。。。
小弟挣扎了半天,都没让它成功显示,悲剧。求高手解答一下。
[解决办法]
参考:
小球MC类
- JScript code
package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.utils.Timer; public class fireBall extends Sprite { private var _speed:int;//上移速度 private var _timer:Timer;//开始移动时刻 private var _hitFun:Function;//单击执行的函数 private var _misFun:Function;//错过执行的函数 public function fireBall(hitFun:Function=null,misFun:Function=null) { this.addEventListener(Event.ADDED_TO_STAGE,initBall); _hitFun=hitFun; _misFun=misFun; } private function initBall(e:Event=null):void{ if(this.hasEventListener(Event.ADDED_TO_STAGE)){ this.removeEventListener(Event.ADDED_TO_STAGE,initBall); } //用随机颜色绘制一个小球,半径为10~20 this.graphics.clear(); this.graphics.lineStyle(1,0x666666); this.graphics.beginFill(Math.floor(Math.random()*0xFFFFFF),1); this.graphics.drawCircle(0,0,Math.round(Math.random()*10)+10); this.graphics.endFill(); //设置小球坐标 this.x=Math.round(Math.random()*(this.stage.stageWidth-this.width)+this.width/2); this.y=this.stage.stageHeight+this.width/2; //设置小球速度 _speed=Math.ceil(Math.random()*5); //设置小球开始运动时刻 _timer=new Timer(500+Math.ceil(5000*Math.random()),1); _timer.addEventListener(TimerEvent.TIMER_COMPLETE,startMoving); _timer.start(); } //开始移动小球 private function startMoving(e:TimerEvent=null):void{ this.buttonMode=true; _timer.removeEventListener(TimerEvent.TIMER_COMPLETE,startMoving); this.addEventListener(Event.ENTER_FRAME,moveUp); this.addEventListener(MouseEvent.CLICK,hitMe); } //小球向上移动 private function moveUp(e:Event=null):void{ this.y-=_speed; //如果超出屏幕 if(this.y<0-this.height/2){ this.removeEventListener(Event.ENTER_FRAME,moveUp); if(this.hasEventListener(MouseEvent.CLICK)){ this.removeEventListener(MouseEvent.CLICK,hitMe); } //如果有错过函数,则执行之 if(_misFun!=null){ _misFun(); } initBall();//重新初始化小球 } } //点击小球事件 private function hitMe(e:MouseEvent=null):void{ this.removeEventListener(MouseEvent.CLICK,hitMe);//一个小球只能点击一次 this.removeEventListener(Event.ENTER_FRAME,moveUp); //如果有单击事件,则执行之 if(_hitFun!=null){ _hitFun(); } initBall();//重新初始化小球 } } }