flex event捕获的两种方法

<?xml version="1.0" encoding="utf-8"?>

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 

					   xmlns:s="library://ns.adobe.com/flex/spark" 

					   xmlns:mx="library://ns.adobe.com/flex/mx"

					   creationComplete="initAppHandler()">

	<fx:Script>

		<![CDATA[

			import flash.utils.getTimer;

			

			import mx.events.FlexEvent;



			private var itemArray:Array = new Array;

			private var num:Number = 20;

			protected function initAppHandler():void

			{

				for(var i:int=0;i<num;i++){

					var item:Item = new Item();

					itemArray.push(item);

					addElement(itemArray[i]);

					itemArray[i].txt.text = i;

					itemArray[i].x = i*120;

					//trace(itemArray[i]);

				}

				addEventListener(MouseEvent.CLICK,onClick);

				addEventListener(MouseEvent.MIDDLE_CLICK,onMidClick);

			}

			

			protected function onClick(event:MouseEvent):void{

				//trace(event.target +"\t");

				//trace(event.currentTarget);

				var t:uint = getTimer();

				

				var temp:String = String(event.target);

				var aa:Array = (temp.split(".B"));

				if(aa.length > 1){

					var bb:Array = aa[1].split(".");

					var obj:Object = event.target;

					for(var i:int=0; i<bb.length;i++){ obj = obj.parent; }

					//trace(obj);					

				}

				trace("aa:");

				trace(getTimer()-t);

			}	

			

			protected function onMidClick(event:MouseEvent):void{

				var t:uint = getTimer();

				

				var temp:String = String(event.target);

				var aa:Array = (temp.split(".B"));

				for(var i:int=0; i<num; i++){

					if(itemArray[i] == aa[0]) { 

					//trace(itemArray[i]);

					}

				} 

				trace("bb:");

				trace(getTimer()-t);

			}

		]]>

	</fx:Script>

</s:WindowedApplication>

 


 第一个全部在0毫秒,第二个偶尔为1毫秒。

你可能感兴趣的:(event)