- 事件抛出
protected function FileList_changeHandler(event:ListEvent):void
{
// 当用户点击列表中的数据项后,抛出加载影像的请求
var evt:LoadImageEvent=new LoadImageEvent(LoadImageEvent.EVENT_LOADIMAGE); evt.URL=URLList.getItemAt(event.rowIndex).toString();
this.dispatchEvent(evt);
}
2.事件定义
package com.gw.events
{
import flash.events.Event;
/*该事件用于向后台请求图像列表*/
public class WeatherEvent extends Event
{
public static const EVENT_IRFILELIST:String = "event_IRfilelist";//红外影像请求事件
public static const EVENT_3DFILELIST:String = "event_3Dfilelist";//3D影像请求事件
public static const EVENT_SARFILELIST:String = "event_SARfilelist";//SAR影像请求事件
public static const EVENT_WEATHERFILELIST:String = "event_Weatherfilelist";//天气影像请求事件
public static const EVENT_JAPANFILELIST:String = "event_Japanfilelist";//日本预报图影像请求事件
public static const EVENT_EUROPEFILELIST:String = "event_Europefilelist";//欧洲预报图影像请求事件
public static const EVENT_MM5FILELIST:String = "event_MM5filelist";//MM5影像请求事件
public static const EVENT_GETCURRENTPAGE:String = "event_getcurrentpage";
public var startDate:String;
public var endDate:String;
public var fileType:String;
public function WeatherEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=true)
{
//TODO: implement function
super(type, bubbles, cancelable);
}
}
}
*bubbles一定要为TRUE 否则事件不冒泡。
3.控件自定义事件
<mx:Metadata>
[Event(name="event_getcurrentpage", type="com.gw.events.WeatherEvent")]
[Event(name="event_loadimage", type="com.gw.events.LoadImageEvent")]
</mx:Metadata>
4.控件事件绑定
pictureShower=new TitleWindow;
pictureShower.addEventListener(CloseEvent.CLOSE,PictureShowerCloseWindow);
5.Mate事件地图机制
<services:ROService id="services" />
<EventHandlers type="{WeatherEvent.EVENT_IRFILELIST}" start="trace('EVENT_IRFILELIST started!')" end="trace('EVENT_IRFILELIST ended!')" debug="true">
<RemoteObjectInvoker instance="{services.weatherService}" method="getIRcloudbyDate" arguments="{[event.startDate,event.endDate]}">
<resultHandlers>
<MethodInvoker generator="{SelectImagePanelControl}" method="ProsingIR" arguments="{resultObject}" />
</resultHandlers>
</RemoteObjectInvoker>
</EventHandlers>
6.Mate注入机制
在事件地图中:
<Injectors target="{SelectImagePanel}" debug="true">
<PropertyInjector targetKey="fileList" source="{SelectImagePanelControl}" sourceKey="fileList" />
<PropertyInjector targetKey="URLList" source="{SelectImagePanelControl}" sourceKey="URLList" />
</Injectors>
将SelectImagePanelControl的fileList注入到SelectImagePanel的fileList。
在SelectImagePanel定义要绑定。
[Bindable]
public var fileList:ArrayCollection;
[Bindable]
public var URLList:ArrayCollection;
7.错误处理
事件地图中:
<EventHandlers type="{UnhandledFaultEvent.FAULT}">
<MethodInvoker generator="{GenericFaultHandler}" method="displayMessage" arguments="{event.fault}" />
</EventHandlers>