如何更改/确定 Flex 中函数执行的优先级?
所以基本上我有一个已调度事件的组件:
<components:MyComp id="Id" myDispatchedEvent(event)/>
在脚本标记中我有该函数:
private function myDispatchedEvent(event:Event):void
{
//Here I have my static function with title and handler function showConfirmation
Calculate.showConfirmation("String Title", function(event:Close):void
{
if(bla bla bla)
//lots of code etc. ...
});
//myDispatchEvent function continues here..
}
所以问题出在我的静态函数的 showConfirmation 处理程序上,如果我进行调试,它只会跳过该函数并继续执行 myDispatchedEvent。为什么 showConfirmation 函数中的匿名函数不执行?
谢谢
So basically I have a component with my event dispatched:
<components:MyComp id="Id" myDispatchedEvent(event)/>
In script tags I have that function:
private function myDispatchedEvent(event:Event):void
{
//Here I have my static function with title and handler function showConfirmation
Calculate.showConfirmation("String Title", function(event:Close):void
{
if(bla bla bla)
//lots of code etc. ...
});
//myDispatchEvent function continues here..
}
So problem is with my static function's showConfirmation handler, if I go through debug, it just skips that function and continues doing myDispatchedEvent. Why doesn't anonymous function inside showConfirmation function execute?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
函数在调用时执行。就你而言,你只需声明它。在
Calculate.showConfirmation
内的某处调用此函数,它将被执行。像下面这样:
Functions are executing upon call. In your case you have just declaration of it. Call this function somewhere inside
Calculate.showConfirmation
and it will be executed.Something like the following:
首先我要说的是,你想做的事情很奇怪。我会尝试编写不同的解决方案,但这取决于您想要做什么。如果您告诉我们更多相关信息,我们可以找到更好的方法来实现您的目标。顺便说一句,你可以这样做:
类似于康斯坦丁已经告诉过你的事情。如果您不执行作为静态函数内的参数传递给静态函数的函数,则该函数将不会被执行。
Let me say first that what you're trying to do is quite strange. I'd try to code a different solution, but this depends on what you're trying to do. It you tell us a more about it we could find a better way to reach your goal. BTW, you can do something like this:
Something similar what Constantiner has already told you. If you don't execute the function that you're passing to your static function as a parameter inside this static function, it won't be executed.