• flex(入门)之timer的使用,键盘,鼠标的监听


    package
    {
    	import flash.display.Shape;
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.events.KeyboardEvent;
    	import flash.events.MouseEvent;
    	import flash.events.TimerEvent;
    	import flash.utils.Timer;
    	
    	import mx.controls.Label;
    	//窗体大小,绘制帧率
    	[SWF(width="400", height="300", frameRate="60")]
    	public class MyDemo extends Sprite
    	{
    		private var circle:Shape;
    		private var label:Label;
    		private var timer:Timer;
    		public function MyDemo()
    		{
    			label = new Label();
    			label.x = 30;
    			label.y = 30;
    			addChild(label);
    			circle = new Shape();
    			circle.x = 50;
    			circle.y = 100;
    			addChild(circle);
    			circle.graphics.beginFill(0xee2f2f);
    			circle.graphics.drawCircle(circle.x,circle.y,40);
    			circle.addEventListener(Event.ENTER_FRAME,changePos);//每帧调用changePos函数
    			stage.addEventListener(MouseEvent.CLICK,onClick); //舞台上添加鼠标点击监听事件
    			stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);//舞台添加键盘监听
    			timer = new Timer(1000,5); //设置延迟时间是1秒,循环执行5次timerExcute()
    			timer.addEventListener(TimerEvent.TIMER,timerExcute);
    			timer.addEventListener(TimerEvent.TIMER_COMPLETE,timerComplete);//执行完成后调用timerComplete
    			timer.start();//启动timer
    		}
    		
    		public function changePos(event:Event):void
    		{
    			if(circle.y >= 300)
    			{
    				circle.y = 1;
    			}else if(0<circle.y && circle.y < 300)
    			{	
    				circle.y+=5;
    			}
    		}
    		
    		//在点击的地方产生绿色方形
    		public function onClick(event:MouseEvent):void
    		{
    			var rect:Shape = new Shape();
    			addChild(rect);
    			rect.graphics.beginFill(0x11ff00);
    			rect.graphics.drawRect(event.stageX,event.stageY,20,20);
    		}
    		
    		
    		public function keyDown(event:KeyboardEvent):void
    		{
    			var count:int = 0
    			if(event.keyCode == 13) //监听Enter键
    			{	
    				var rect:Shape = new Shape();
    				addChild(rect);
    				rect.graphics.beginFill(0x00f1f0);
    				rect.graphics.drawRect(Math.random()*400,Math.random()*300,10,10);
    			}
    		}
    		
    		public function timerExcute(event:TimerEvent)
    		{
    			var rect:Shape = new Shape();
    			addChild(rect);
    			rect.graphics.beginFill(0x0f11f0);
    			rect.graphics.drawRect(Math.random()*400,Math.random()*300,10,10);
    		}
    		
    		public function timerComplete(event:TimerEvent)
    		{
    			var rect:Shape = new Shape();
    			addChild(rect);
    			rect.graphics.beginFill(0x000000);
    			rect.graphics.drawRect(Math.random()*400,Math.random()*300,30,60);
    		}
    	}
    }

    桌面程序Air效果图:


  • 相关阅读:
    深入浅出Win32多线程程序设计(一)
    dm642的优化
    SpringBoot2
    HZERO微服务平台09: jhipster接入hzero
    如何以纯文本方式简单快速记录java代码的调用过程
    HZERO微服务平台07: 代码分析之登录日志、验证码登录、jwt token等
    HZERO微服务平台02: 认证鉴权体系介绍
    HZERO微服务平台06: 代码分析之token生成、校验、获取信息、传递
    HZERO微服务平台10: 代码分析之admin服务刷新路由、权限、swagger的过程 .md
    HZERO微服务平台11: 代码分析之数据权限、sql拦截 .md
  • 原文地址:https://www.cnblogs.com/vokie/p/3602065.html
Copyright © 2020-2023  润新知