在弹出的TitleWindow窗体中用dispatchEvent派发一个事件出来 为什么在Application中监听不到派发出来的事件???????????????代码如下:
自定义事件:
package event.BinddingEvent
{
import flash.events.Event;
public class OfferAPriceEvent extends Event
{
private var m_LowerCase:String="0.00";
private var m_UpperCase:String="0.00";
public function get LowerCase():String
{
return m_LowerCase;
}
public function get UpperCase():String
{
return m_UpperCase;
}
public function OfferAPriceEvent(_type:String, _LowerCase:String, _UpperCase:String, _bubbles:Boolean=false, _cancelable:Boolean=false)
{
super(_type, _bubbles, _cancelable);
m_LowerCase=_LowerCase;
m_UpperCase=_UpperCase;
}
}
}
TitleWindow窗体代码:
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" initialize="titlewindow1_initializeHandler(event)">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import control.Utility.Helper;
import event.BinddingEvent.OfferAPriceEvent;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
protected function button1_clickHandler(event:MouseEvent):void
{
//var winNotFirstOfferAPrice:demoTwo=new demoTwo();
//PopUpManager.addPopUp(winNotFirstOfferAPrice,Helper.GetParent(this),true);
//PopUpManager.centerPopUp(winNotFirstOfferAPrice);
dispatchEvent(new OfferAPriceEvent("OfferAPriceEvent","this.txtLowerCase.text","this.txtUpperCase.text",true));
}
protected function titlewindow1_initializeHandler(event:FlexEvent):void
{
//addEventListener("OfferAPriceEvent",OfferAPriceEventHadnler);
}
private function OfferAPriceEventHadnler(evt:OfferAPriceEvent):void
{
Alert.show(evt.LowerCase);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Button x="106" y="58" label="按钮" click="button1_clickHandler(event)"/>
</s:TitleWindow>
Application主程序代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Button x="169" y="136" label="竞价界面" id="btnWinBidding" click="btnWinBidding_clickHandler(event)"/>
<s:Button x="169" y="176" label="出价界面" click="button1_clickHandler(event)"/>
<fx:Script>
<![CDATA[
import event.BinddingEvent.OfferAPriceEvent;
import control.BiddingCtrl.ctrlWinBidding;
import control.BiddingCtrl.ctrlWinOfferAPrice;
import control.BiddingCtrl.demoAddLis;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.controls.Alert;
protected function btnWinBidding_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var winBidding:ctrlWinBidding=new ctrlWinBidding();
PopUpManager.addPopUp(winBidding,this,true);
PopUpManager.centerPopUp(winBidding);
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
//var winBidding:ctrlWinOfferAPrice=new ctrlWinOfferAPrice();
var winBidding:demoAddLis=new demoAddLis();
PopUpManager.addPopUp(winBidding,this,true);
PopUpManager.centerPopUp(winBidding);
}
protected function application1_initializeHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
this.addEventListener("OfferAPriceEvent",OfferAPriceEventHadnler);
}
private function OfferAPriceEventHadnler(evt:OfferAPriceEvent):void
{
Alert.show(evt.LowerCase);
}
]]>
</fx:Script>
</s:Application>
有谁知道 赶快出来顶
唉 分这么少啊 ...
原因:Application添加的监听是给谁添加的啊?你给this添加管毛的用啊?你的事件监听应该给ctrlWinBidding添加吧?
protected function btnWinBidding_clickHandler(event:MouseEvent):void{
// TODO Auto-generated method stub
var winBidding:ctrlWinBidding=new ctrlWinBidding();
winBidding.addEventListener("OfferAPriceEvent",OfferAPriceEventHadnler);//添加这句话
PopUpManager.addPopUp(winBidding,this,true);
PopUpManager.centerPopUp(winBidding);
}