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的构造参数

转载于:https://www.cnblogs.com/whegroup/archive/2011/04/07/2007418.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值