ActionScript: pushing a closure onto the event stack?

為{幸葍}努か 提交于 2019-12-11 15:56:17

问题


On occasion, I have wanted to push a closure onto ActionScript's event stack so that it will be executed after the current event handler. Right now I use setTimeout(closure, 0). Is there a more direct way of doing this?


回答1:


setTimeout(closure, 0) is creating a new event stack. I don't understand your objective if this solution isn't working for you. What is the goal you're trying to accomplish?

Flex has ENTER_FRAME events, Timer, callLater, setTimeout, setInterval, all which delay calls and create new execution stacks.

Are you trying to inject code into the current stack? If so, you might need to look at something like this: http://en.wikipedia.org/wiki/Active_object. The idea being that you push functions (closures) into an array, and the active object controller pulls the next one off the list when the previous one has run to completion. That's the simplest case. You can write a more complicated one that will have priority stacks like high, medium, low, with your own schedule management system. (e.g., low get promoted after waiting too long).

But hey! The devil is in the details. What's the goal?




回答2:


Take a look at capture and bubbling phases of the as3 events. I found this nice chapter that explains clearly the proccess: http://books.google.com/books?id=yFNZGjqJe9IC&lpg=PA250&ots=oPB9HXIby7&dq=flash%20event%20bubbling%20phase&pg=PA250#v=onepage&q=&f=false

And also check the EventDispatcher class documentation that explain the use of this different phases.



来源:https://stackoverflow.com/questions/1347789/actionscript-pushing-a-closure-onto-the-event-stack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!