AS3 - gotoAndStop with immediate action

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

I'm moving from AS2 to AS3 and probably as many ppl before found this incompatibility:

I used quite often code like:

gotoAndStop(5); trace(box); //where box is a movie on 5th frame 

What is the easiest way how to do it in AS3.

回答1:

There is an easy way to solve this, but it is undocumented:

addFrameScript(1, update); gotoAndStop(2);  function update() {     trace(box); // outputs [object MovieClip] } 

Please note that the first argument for addFrameScript is the frame number but it's 0-based, i.e. 0 is frame 1, 1 is frame 2, etc... The second argument is the function you would like to call.



回答2:

no easy way to do that.

what you need to do is

  • setup a listener for when the frame renders

  • tell it to go to the said frame(5)

  • force the rendering to happen ASAP stage.invalidate

.

One of the top reasons to stay with as2. Not saying as2 is better, just better at a few things and this is one of them. My opinion on this is that as3 wasn't really meant to handle timelines very well.

with as2 you do

gotoAndStop(5); trace(box); 

With as3 you need to wait for the timeline to render.

stage.addEventListener(Event.RENDER, onRenderStage); protected function onRenderStage(ev:Event):void {     trace(this['box']); } gotoAndStop(5); stage.invalidate(); 

I used to have different assets in different frames of one MovieMlip in my as2 days, but to do that in AS3 is too complicated to enjoy any of the benefits. So while this will work, I'd recommend looking into a different solution altogether. Or stick to as2.



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