package event
{
import flash.events.Event;
public class CustomEvent extends Event
{
public var evObject:Object;
public function CustomEvent(obj:Object, type:String)
{
super(type);
evObject = obj;
}
override public function clone():Event
{
return new CustomEvent(evObject, type);
}
}
}
这个就是一个自定义控件,它和传统的区别在于可以自己传送一个参数过去,比如两个界面的参数传递。
比如这样的一个例子,当datagrid的某条记录双击之后,传递selectedItem:object到另外的一个界面中去
1、usersummary.mxml ------(子控件)
<mx:DataGrid allowMultipleSelection="true"
doubleClickEnabled="true"
doubleClick="transfer(event)"
dataProvider="{arr}"
id="myDg"
change="dataEvent()>
public function transfer(evt:MouseEvent):void
{
var cusEvent:CustomEvent=new CustomEvent(myDg.selectedItem, "itemUserDataChange");
dispatchEvent(cusEvent);
}
3、主程序Application
userCanvas.usersummary.addEventListener("itemUserDataChange", transferHandleChange);
事件冒泡后,接收事件执行方法:
private function transferHandleChange(e : CustomEvent):void{
userCanvas.usersView_edit.UserSelectedData = e.evObject; //
userCanvas.usersView_edit.edit_bt.enabled=true;
}