Actionscript 委托函数麻烦... (myFunction).toString() 打印 function Function() {}

发布于 2024-09-29 19:20:03 字数 1342 浏览 4 评论 0原文

我有一个 ViewToActionMap 对象的向量,它具有以下构造函数:(

public function ViewToActionMap(_forModule:eModule, 
                                _forAction:eViewAction,
                                _toFunction:Function,
                                _withArgs:Array=null):void{         
            forModule   = _forModule;
            forAction   = _forAction;
            toFunction  = _toFunction;
            withArgs    = _withArgs;
        }

eModule / eViewAction / withArgs are与我的帖子无关)

所以我的向量看起来像这样(为了简洁起见,我只包含了它的第一个对象..):

const actionMappings:Vector.<ViewToActionMap> = new <ViewToActionMap>
               [new ViewToActionMap(eModule.WELCOME,    
                eViewAction.GP_CONTINUE_BUTTON,     
                startGame,  //<--- the source of my troubles!
                null)
               ]

其中 startGame 是一个简单的函数:

function startGame():void{  }

/////// //////// 所以这就是问题 ///////////////

如果我循环遍历 actionMappings[0] 的属性,这里是输出:

gpContinueButton
welcome
function Function() {}    //<---------- why isn't this working?
null

为什么 .toFunction 一个空函数,而不是对 startGame() 的引用???

谢谢!

I've got a Vector of ViewToActionMap objects, which have following constructor:

public function ViewToActionMap(_forModule:eModule, 
                                _forAction:eViewAction,
                                _toFunction:Function,
                                _withArgs:Array=null):void{         
            forModule   = _forModule;
            forAction   = _forAction;
            toFunction  = _toFunction;
            withArgs    = _withArgs;
        }

(eModule / eViewAction / withArgs aren't relevant to my post)

So my vector looks like this (for brevity, i've only included its first object..):

const actionMappings:Vector.<ViewToActionMap> = new <ViewToActionMap>
               [new ViewToActionMap(eModule.WELCOME,    
                eViewAction.GP_CONTINUE_BUTTON,     
                startGame,  //<--- the source of my troubles!
                null)
               ]

Where startGame is a simple function:

function startGame():void{  }

/////////////// so here's the problem //////////////

if I loop through the properties of actionMappings[0], here is the output:

gpContinueButton
welcome
function Function() {}    //<---------- why isn't this working?
null

Why is the value of .toFunction an empty function, instead of a reference to startGame()????

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惟欲睡 2024-10-06 19:20:03

解决了:

似乎跟踪 ".toFunction" 的值只会产生这样的结果: function Function() {}

一旦我修复了一个不相关的错误,我就能够调用startGame() 成功。

Solved it:

it seems that tracing the value of ".toFunction" simply yields this: function Function() {}

Once i fixed an unrelated bug, I was able to call startGame() successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文