由于在一个弹出窗派发事件时主页面上接收不到这个事件,因为弹出窗不是直接以组件形式引用在主页面上的,而是new出来后用popUpManager弹出的,So?
new一个弹出窗时,把当前页面也传给弹出窗,window.pageWindow=this; 如下:其中FlowChartWindow中包含FlowChart组件:
<s:BorderContainer height="100%" width="35%" backgroundColor="#E6E6E6" cornerRadius="7">
<s:layout>
<s:VerticalLayout verticalAlign="bottom" paddingBottom="10" horizontalAlign="center"/>
</s:layout>
<flowChart:FlowChart width="100%" height="90%" task="{this._task}" pageWindow="{this}"/>
<s:Button id="up" label="点击放大" click="getBigFlowChar(event)"/>
<fx:Script>
<![CDATA[
import mx.events.CloseEvent;
import com.sthr.pdm.AutoTaskMgr.view.component.flowChart.FlowChartWindow;
public function getBigFlowChar(event:MouseEvent):void
{
var window:FlowChartWindow=new FlowChartWindow;
window.task=this._task;
window.pageWindow=this;
window.addEventListener(CloseEvent.CLOSE,function close(event:CloseEvent):void
{
PopUpManager.removePopUp(window);
});
PopUpManager.addPopUp(window,this,true);
PopUpManager.centerPopUp(window);
}
]]>
</fx:Script>
</s:BorderContainer>
在FlowChartWindow中又将它从上文获取到的pageWindow传给FlowChart组件的属性pageView:
<s:VGroup width="100%" height="100%">
<s:HGroup width="100%" horizontalAlign="right">
<s:Image width="50" height="50" source="@Embed(source='/assets/close.png')" buttonMode="true" click="image1_clickHandler(event)"/>
</s:HGroup>
<flowChart:FlowChart width="100%" height="80%" task="{task}" type="small" pageWindow="{this._pageWindow}"/>
</s:VGroup>
然后在FlowChart中直接用pageWindow去派发事件:pageWindow.dispatchEvent(evt);
var evt:ProcessTaskEvt = new ProcessTaskEvt(ProcessTaskEvt.DoTask,false);
evt.taskObj=newTask;
evt.pageView=event.data.stepUser.pageView;
evt.isEditor=event.isEditor;
pageWindow.dispatchEvent(evt);