AS学习的小练习

简介:

 最近折腾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,0,squareSize,squareSize); 
  16.         return square; 
  17.     } 

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

 
  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. function timeComplete(event:TimerEvent):void
  8.     trace("计时停止"); 
  9. //注册事件侦听器 
  10. function reLis():void
  11.     mTimer.addEventListener(TimerEvent.TIMER,tickHandler); 
  12.     mTimer.addEventListener(TimerEvent.TIMER_COMPLETE,timeComplete); 
  13.     //启动定时器 
  14.     mTimer.start(); 
  15. reLis(); 
  16. //注销事件侦听器 
  17. //mTimer.removeEventListener(TimerEvent.TIMER,tickHandler); 

 本文转自shyy8712872 51CTO博客,原文链接:http://blog.51cto.com/shuyangyang/900878,如需转载请自行联系原作者


目录
打赏
0
0
0
0
69
分享
相关文章
k8s学习
【10月更文挑战第1天】
169 4
ans介绍学习
【9月更文挑战第5天】
236 13
学习的一些知识
这段内容主要是关于个人承诺将把自己学到的知识分享到阿里云平台,以提供更多的学习经验和资源给其他用户。通过这种分享和交流的方式,希望能够帮助到更多在阿里云平台上学习的人们,一起共同进步和成长。
|
9月前
学习使用按位取反~
【6月更文挑战第23天】学习使用按位取反~。
58 7
js知识学习总结
js知识学习总结
42 1
鱼书学习小结(一)
1 安装环境 python -V #查看版本 pip -V #查看版本 pip list #查看列表 makedir fisher #新建项目目录 pip install pipenv #进入项...
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等