最近折腾AS3.0的学习,做了一个小练习,收藏下,哈哈。
下面附一个鼠标点击FLASH,舞台变换各种颜色的代码:
- import flash.events.MouseEvent;
- import fl.motion.MotionEvent;
- import flash.display.Shape;
- //为舞台stage注册鼠标点击事件
- stage.addEventListener(MouseEvent.MOUSE_DOWN,changeColor);
- function changeColor(e:MouseEvent):void{
- //每次点击时重新生成一个正方形
- var newShape:Shape=createSquare();
- addChild(newShape);
- function createSquare():Shape{
- var squareSize:Number=200;
- var square:Shape=new Shape();
- square.graphics.beginFill(Math.random()*0XFFFFF);
- square.graphics.drawRect(0,0,squareSize,squareSize);
- return square;
- }
- }
定时器(每秒种打印出当前显示是第几秒,停止也会打印):
- import flash.utils.Timer;
- import flash.events.TimerEvent;
- //创建事件侦听器
- var mTimer:Timer=new Timer(1000,10);
- function tickHandler(event:TimerEvent):void{
- trace("现在是第"+event.target.currentCount+"秒");
- }
- function timeComplete(event:TimerEvent):void{
- trace("计时停止");
- }
- //注册事件侦听器
- function reLis():void{
- mTimer.addEventListener(TimerEvent.TIMER,tickHandler);
- mTimer.addEventListener(TimerEvent.TIMER_COMPLETE,timeComplete);
- //启动定时器
- mTimer.start();
- }
- reLis();
- //注销事件侦听器
- //mTimer.removeEventListener(TimerEvent.TIMER,tickHandler);
本文转自shyy8712872 51CTO博客,原文链接:http://blog.51cto.com/shuyangyang/900878,如需转载请自行联系原作者