openfl截止6.1.0的MovieClip存在一个bug,如果采用addFrameScript添加跳转函数可能不会生效,例如:
// mc has 10 frames
// go to frame 5 in last frame
mc.addFrameScript(mc.totalFrames - 1, function(e:Event):Void
{
mc.gotoAndPlay(5);
});
// trace current frame
mc.addEventLitener(Event.ENTER_FRAME, function(e:Event):Void
{
trace(mc.currentFrame);
});
// expected output:
// 1,2,3,4,5,6,7,8,9, 5,6,7,8,9, 5,6,7,8,9...
// actually output ( goto not work ):
// 1,2,3,4,5,6,7,8,9, BUG-> 10,1,2,3...
经过研究源码,我进行了以下修改:
// MovieClip.hx
private function __evaluateFrameScripts (advanceToFrame:Int):Bool
{
for (frame in __currentFrame...advanceToFrame + 1)
{
if (frame == __lastFrameScriptEval) continue;
__lastFrameScriptEval = frame;
__currentFrame = frame;
if (__frameScripts.exists (frame))
{
var script = __frameScripts.get (frame);
script ();
// when frame changed return false
if (__currentFrame != frame)
{
return false;
}
}
if (!__playing)
{
break;
}
}
return true;
}
public override function __enterFrame (deltaTime:Int):Void
{
if (__symbol != null && __playing)
{
var nextFrame = __getNextFrame (deltaTime);
if (__lastFrameScriptEval == nextFrame)
{
return;
}
if (__frameScripts != null)
{
if (nextFrame < __currentFrame)
{
// when frame changed return
if (!__evaluateFrameScripts (__totalFrames))
{
return;
}
__currentFrame = 1;
}
// when frame changed return
if (!__evaluateFrameScripts (nextFrame))
{
return;
}
}
else
{
__currentFrame = nextFrame;
}
}
....
}
经过修改,表现正常了,我希望作者能修复这个bug,修复之前,遇到这个问题的朋友可以这么临时修改下~
ps:我还是更喜欢自己的母语 ~