flex中的addEventListener方法
flex控件对象、RemoteObject等都有一个共同的方法addEventListener。
addEventListener方法如下:
public function addEventListener(type:String, listener:Function,
useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
{
eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
@param type:String 触发事件的类型,flex预定义的事件类型和处理方式。
@param listener:Function 事件触发时的回调函数。
@param useCapture:Boolean 事件处理的顺序
@param priority:int 事件优先权,我的理解是如果添加了多个listener则按照priority的顺序执行:(没多大用
@param useWeakReference:Boolean 是否设为弱引用
重点讲进后面三个参数。
useCapture 参数只有用实例才能表达清楚。
useCapture例:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” applicationComplete=”init()”>
<mx:HBox id=”hbox” >
<mx:Button id=”button” label=”click”/>
</mx:HBox>
<mx:Script>
import mx.controls.*;
public function init():void
{
// 注意:这里的useCapture:Boolean值应加到一个包含内部元素的控件上,这样才能让flex运行时识别事件顺序的范围!!!
// 由于 flex的Alert控件是重叠方式显示,所以最外一层才是最后弹出的一层
hbox.addEventListener(MouseEvent.CLICK,hboxClick,true);
button.addEventListener(MouseEvent.CLICK,buttonClick);
}
public function hboxClick(e:MouseEvent):void
{
Alert.show(”外HBox事件。”);
}
public function buttonClick(e:MouseEvent):void
{
Alert.show(”内Button事件。”);
}
</mx:Script>
</mx:Application>
原文地址:http://blog.sina.com.cn/s/blog_5c4558600100d39q.html
相关文档:
为了在应用程序中使用数据,Adobe Flex 包括了与HTTP servers,web services 或remoteobject services
(Java objects)进行交互的组件,这些组件被称之为远程过程调用(RPC)服务组件。
与 Adobe ColdFusion,PHP 或类似的服务器技术不同,Flex 应用程序并不直接连接数据
库。举 ......
<mx:HSlider id="priceSlider" creationComplete="{HsilderChangeThumb(event)}"/>
<mx:Script>
<![CDATA[
private function HsilderChangeThumb(e:Event):void
{
var slider:HSlider = e.target as HSlider;
&nbs ......
Top 10 things new Flex developers should know
By Michael Portuesi | Published: November 27, 2009
While helping a coworker get started with Flash and Flex development, I thought it would be a good time to cover the list of things that I have found pretty essential to know about Flex development, co ......
//获得屏幕的分辨率
var x:Number=Capabilities.screenResolutionX;
var y:Number=Capabilities.screenResolutionY;
Alert.show("x="+x+"y="+y);
第二种方法
Alert.show(stage.fullScreenWidth+"=="+stage.fullScreenHeight);
//获得stage(工作区)的宽、高
Alert.show(stage.stageWidth+"=="+stage.stageHei ......
合是ActionScript 中功能强大的基于索引的数组组件,添加了如对内容进行排序等功能,
操作数组的读取位置,创建经过排序的数组视图。集合也能通知其任意事件监听器监听其数
据是否改变,以及任何数据项被添加到源数组时可执行自定义逻辑。当数据改变时可通知其
监听器,这是集合的新功能,叫数据绑定,还有就是允许DataG ......