as3中dispatchEvent参数传递(疑问)

A.swf中导出B.swf时

对B(A_Loader.contentLoaderInfo.content)做事件监听,用来捕捉B.swf中的root事件响应dispatchEvent(new Event("popup"));

这已经实现

A.swf

contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e):void{
e.target.content.addEventListener(
"subLoad",function(evt){blurBg(e,null);});
e.target.content.addEventListener(
"popup",function(evt){trace(evt.target);popupShow(evt.target)});
e.target.content.addEventListener(
"subClose",unBlurBg);
//e.target.content._newFont = tf;
})

B.swf

btn.addEventListener(MouseEvent.CLICK,function(e){root.dispatchEvent(new Event('popup'))});

这些已经实现,但现在再复杂一点:想B.swf抛出事件时,能传递一些参数给A.swf,查看dispatchEvent没有发现可实现的方式,

而Event对象可用的属性也不能成为参数的媒介(target属性只读,不能在构造时指定它吗)

总之。未解决

-------------------------------------------------------------------------------------

问题已解决:

由于as3 Event类无法传参,根据网上的提示。扩展一个Event类,增加自定义的属性,作为参数位

package com.wbClass
{
import flash.events.Event;

public class wbEvent extends Event
{
public static const POPUP_LOAD:String
= "popupLoad";

public
var argu:String;

public
function wbEvent(type:String, argu:String)
{
super(type);
this.argu = argu;
}

override public
function clone():Event{

return new wbEvent(type,argu);

}
}
}
在代码中使用
its[i].addEventListener(MouseEvent.CLICK,function(e){var ee= new wbEvent("popup","res/"+swfs[i]);return function(){root.dispatchEvent(ee)}}());

需要注意的是wbEvent中的super用法

由于Event的构造方法需要参数。子类wbEvent在继承它的时候,需要用super指定Event的构造参数

posted @ 2011-04-07 08:41  whe.gp  阅读(1704)  评论(0)    收藏  举报