加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AS学习的小练习

发布时间:2020-12-15 18:42:42 所属栏目:百科 来源:网络整理
导读:?最近折腾AS3.0的学习,做了一个小练习,收藏下,哈哈。 下面附一个鼠标点击FLASH,舞台变换各种颜色的代码:? import?flash.events.MouseEvent;? import?fl.motion.MotionEvent;? import?flash.display.Shape;? ? //为舞台stage注册鼠标点击事件? stage.add

?最近折腾AS3.0的学习,做了一个小练习,收藏下,哈哈。

下面附一个鼠标点击FLASH,舞台变换各种颜色的代码:?

 
 
  1. import?flash.events.MouseEvent;?
  2. import?fl.motion.MotionEvent;?
  3. import?flash.display.Shape;?
  4. ?
  5. //为舞台stage注册鼠标点击事件?
  6. stage.addEventListener(MouseEvent.MOUSE_DOWN,changeColor);?
  7. function?changeColor(e:MouseEvent):void{?
  8. ????//每次点击时重新生成一个正方形?
  9. ????var?newShape:Shape=createSquare();?
  10. ????addChild(newShape);?
  11. ????function?createSquare():Shape{?
  12. ????????var?squareSize:Number=200;?
  13. ????????var?square:Shape=new?Shape();?
  14. ????????square.graphics.beginFill(Math.random()*0XFFFFF);?
  15. ????????square.graphics.drawRect(0,squareSize,squareSize);?
  16. ????????return?square;?
  17. ????}?
  18. }?

?定时器(每秒种打印出当前显示是第几秒,停止也会打印):

 
 
  1. import?flash.utils.Timer;?
  2. import?flash.events.TimerEvent;?
  3. //创建事件侦听器?
  4. var?mTimer:Timer=new?Timer(1000,10);?
  5. function?tickHandler(event:TimerEvent):void{?
  6. ????trace("现在是第"+event.target.currentCount+"秒");?
  7. }?
  8. function?timeComplete(event:TimerEvent):void{?
  9. ????trace("计时停止");?
  10. }?
  11. //注册事件侦听器?
  12. function?reLis():void{?
  13. ????mTimer.addEventListener(TimerEvent.TIMER,tickHandler);?
  14. ????mTimer.addEventListener(TimerEvent.TIMER_COMPLETE,timeComplete);?
  15. ????//启动定时器?
  16. ????mTimer.start();?
  17. }?
  18. reLis();?
  19. //注销事件侦听器?
  20. //mTimer.removeEventListener(TimerEvent.TIMER,tickHandler);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读