首页 新闻 赞助 找找看

Flex事件派发问题

0
悬赏园豆:5 [待解决问题]

在弹出的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>


有谁知道 赶快出来顶

问题补充: 高手赶快帮忙呀
chwj2dyn的主页 chwj2dyn | 初学一级 | 园豆:195
提问于:2011-05-09 17:36
< >
分享
所有回答(1)
0

唉  分这么少啊 ...

原因: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);
}
英雄小强 | 园豆:292 (菜鸟二级) | 2012-03-05 17:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册