MovieClip帧动作bug反馈及修复

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:我还是更喜欢自己的母语 :grin: ~

1 Like

Thanks for the feedback! We’ll take a look :slight_smile:

Do you understand @singmajesty? Why does he/she not write in English?
Or are you using Google Translator?

The comments in the source code do a good job of explaining the problem.

1 Like

Google Translate is not perfect, but here’s the result

Openfl has a bug in the 6.01 MovieClip, and if you add a jump function with addFrameScript, it may not take effect, for example

// 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...

After research source, I made the following changes:

// 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;
		}
	}
	....
}

After the modification, the performance of normal, I hope the author can fix the bug, before repair, the problem encountered friends can be so temporary modified under ~
Ps: I still prefer my native language :grin: ~

1 Like

Great news :grinning:

We just added inline translation support to the community forums!

Once you’re logged in, there is a “world icon” that appears at the foot of posts. You should be able to click it to translate the text from the original to your user locale.

You can customize your locale by using http://community.openfl.org/u/<your user name>/preferences/interface

2 Likes

Translation works great!

Oh Yes, where ist translatable posts :confused:

If You write “Hello Sir @singmajesty

I read with correct language German:
“Guten Tag, @singmajesty

Ps where is website of your community?
I want try community. I found earth icon.

The “OpenFL community forums” are this site, here, http://community.openfl.org

The earth or world icon should allow you to translate posts from their original language (which here was Chinese, but is often English) to your language, based upon the language you set when you signed up for the forums. You can go to “Profile > Preferences > Interface” to set a different language if you prefer

:smile::+1: Thank you ~

老乡啊。openFl 还是挺有搞头的。方便交个朋友吗?加我微信: 135#3768#7305 (把#号去掉)

技术无国界~ :grin:
我微信很少上,加Q吧,私信你了~

Thanks again for your help, sorry about the delay to test this, it’s now committed in dev versions :slight_smile:

Feel free to make a pull request next time you have an improvement :slight_smile:

Great job ! :+1:
My pleasure~