设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源分享平台

Function.apply在super上的bug解决方案A

来源:136z.Com 作者:佚名 时间:2005-07-19 00:16:53

Function.apply在继承的类上使用会出现问题,参见:http://www.flash8.net/bbs/dispbbs.asp?BoardID=38&ID=238991

这是Flash 6中就出现的,为了保持最大兼容性,Flash7也继承了这个bug。= =。。

mx.utils.Delegate很有用的1个dd,也使用了apply来实现的,由于很多时候只是想delegate1个类的方法,所以就改用方法名来做delegate,而不是函数的引用。改写后的delegate不在使用apply调用函数,可以避免这个bug。

新写的delegate的调用接口:

__xpLib__.createMethodDelegate(obj:Object,method:String):Function其中obj是对象应用,method是这个对象上的1个方法的名字。

和mx.utils.Delegate 1样,它返回1个代理函数,调用这个函数就可以自动将它的this指针指向obj参数的对象上。

例子:

varq=__xpLib__.createMethodDelegate(_root,"tt");
functiontt(a,b){
trace(a+""+b);
}
q(12,14);
//output:
1214

因为要实现不定个参数的调用,所以这个东西都用pcode写的,用flasm编译,没有as的源代码可以看- -..使用的时候需要直接在Flash里添加这段代码:

#initclip
__bytecode__("88140002005F676C6F62616C005F5F78704C69625F5F0096020008001C96020008014E9D0200FA0096020008001C96020008019B050000000000004F9609000070726F746F0008001C96020008014E960B000070726F746F74797065004E3C96020008001C96020008014E961600006372656174654D6574686F6444656C6567617465009B10000002006F626A006D6574686F64008A008E08000000000B26005700960A000401006C656E677468004E8701000A4C129D02001000514C96020004014D4E4D4C9D0200F0FF17960200040A960A0004010063616C6C6565004E4C96080000746172676574004E4D9606000066756E63004E523E4C4C960D000074617267657400006F626A001C4F960E000066756E6300006D6574686F64001C4F3E4F00");
#endinitclip
pcode的代码:
#initclip
if(!_global.__xpLib__)
{
_global.__xpLib__=function()
{
};
varproto=_global.__xpLib__.prototype;
_global.__xpLib__.createMethodDelegate=function(obj,method)
{
"function2()(r:1=’arguments’)";
"pushr:arguments,’length’";
"getMember";
"setRegisterr:10";

"dup";
"not";
"branchIfTrueout";

"loop:";
"decrement";
"dup";
"pushr:arguments";
"swap";
"getMember";

"swap";

"dup";
"branchIfTrueloop";
"out:";
"pop";

"pushr:10";

"pushr:arguments,’callee’";
"getMember";
"dup";

"push’target’";
"getMember";

"swap";

"push’func’";
"getMember";

"callMethod";

"return";
"end";

"dup"
"dup"

"push’target’,obj"
"getVariable"
"setMember"

"push’func’,method"
"getVariable"
"setMember"


"return"
};
}
#endinitclip

Tags:

  • 好的评价 如果您觉得好,就请您
      0%(0)
  • 差的评价 如果您觉得差,就请您
      0%(0)
  • 相关文章
    广告赞助

    文章随便看看 设计素材 建站学院 网页模板 视频教程

    网友评论

    共有 0 位网友发表了评论,得分 0 分,平均 0 分    查看完整评论

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 1分

    内 容:

             通知管理员 验证码: