Custom MovieClip

It looks like you’re running into unrelated compile errors, if you build for HTML5 and WebGL, that one build will run in many browsers. The Type not found : hscript.Interp suggests, perhaps you tried to include the hscript library, and did not intend to, or are missing a haxelib reference?

I am unfamiliar with the haxe.ui errors you are having

Oh, I’m so sorry, looks like I posted wrong screenshot.

Does openfl test html5 -Dwebgl1 behave any differently?

I tried with: lime test html5 -Dwebgl1 but have same errors in FF. Now I have 60 FPS in game, but animations is stil too slow (like 2-3 FPS).
This is my code for playing animation:

public var fps(get, set) = 60;

timer = new Timer(1000 / fps);
timer.addEventListener(TimerEvent.TIMER, onFrame);

public function onFrame():Void 
	{
		
		nextFrame++;
		
		if(nextFrame<frames.length)
		{
			
			bmpSource.bitmapData = frames[nextFrame];
			currentFrame = nextFrame;
		}else {
		
			nextFrame = -1;
			onMovieCompleted();
		}
	}

Perhaps it would work better to use Event.ENTER_FRAME, and to use Lib.getTimer to compare the current time to the previous time, to determine which frame you should display. This way you can skip frames, and make sure that you are synchronizing your changes with requestAnimationFrame in the browser

I update MC animation from Timer based to EnterFrame: I use single EnterFrame event and then call

public function onFrame():Void 

function described above. Performance are really better. Now in FF everything looks nice and smooth. I’m not familiar with requestAnimationFrame: how can I synchronize it with browser request? Any suggestions?

Event.ENTER_FRAME in OpenFL is based upon requestAnimationFrame in the browser, which tends to work much better for smooth results, so you’re good it sounds like :slight_smile:

A challenge I face while running movieclip with open fl on html target, is when I have to run the movieclip from ‘x’ framenumber to ‘y’ frame number. And stop it on yth frame. Not to loop back, or go ahead. If you try to put a stop inside onEnterFrame, it will stop fine on Flash target. But on html5 target the problem is that it may skip some frames. And if the frame where you want to stop it gets skipped, there is no good way to detect if the frame number has approached or not.

For this, I am now thinking about using the spritesheet class that comes with the open fl samples. Spritesheet can handle this problem through the code itself.

I mentioned this especially to know, if you have been able to handle this issue on html5 target ?

There is a define called -Dswf-parent-fps that will use the parent frame rate for animation (like Flash) rather than using the frame rate of the SWF asset

The reason we have this implemented (despite being different than Flash) is that requestAnimationFrame is the ideal method of animation for HTML5, which will often run at 60 FPS, or even 120-144 FPS on gaming monitors. This will ruin almost any keyframe animation :wink:

Have you tried clip.addFrameScript to add a function to be called on the frame you want (such as a stop())? Just be aware it’s zero-based, not 1-based, for the frame index

2 Likes

if frame scripts will still be executed when the timeline skips over a frame, my project could definitely benefit from it!

Edit: I notice there’s no removeFrameScript, and honestly, I’ve never actually needed to use this in flash development, are there any memory management caveats I should know about with addFrameScript?

Edit2: It seems you’ve answered whether skips affect frame scripts in my other thread

I think clip.addFrameScript (0, null) will remove the script :slight_smile:

tried lime run project.xml neko -debug -Dswf-parent-fps
and I get
Error: You must have a "project.xml" file or specify another valid project file when using the 'run' command
I’m still a total idiot when it comes to cmd line building, is there something I’m doing wrong? can I just define this in the project.xml?

You can try and omit “project.xml” if you are in the same directory as your project file.

It looks like it should work, unless “project.xml” wasn’t a valid path from your working directory?

Sure, you can try <haxedef name="swf-parent-fps" /> in your project file and see how that works :slight_smile:

Ugh, I did a cd .. earlier to test something in the parent folder and totally forgot

yeah this works, haxedef works too. Unfortunately, the frame script in neko seems to happen in a different order than flash.
trace('${_clip.currentFrame} - ${_clip.currentLabel}');
in flash (correct): ChoiceMenu.hx:36: 33 - choice_1
in neko (incorrect): ChoiceMenu.hx:36: 33 - start
Furthermore, the children expected on that frame don’t exist, yet.

Would you mind sharing a sample, or what does the timeline look like? Does something appear to be off by one frame, or something more significant?

frame 1-32 has the label start, frame 33 has the label chioce_1, 34-47 has the label door1. frame 33 has some buttons, text fields and ui art on it. the label prefix ‘choice’ tells my code to look and initialize certain art assets. I can be more descriptive if needed

It looks like we run the frame script before we update the current label and child display objects:

https://github.com/openfl/openfl/blob/develop/openfl/display/MovieClip.hx#L225-L258

seems like a pretty simple line swap, I’ll try it out

calling __updateFrame () before __frameScripts.get might fix it – it means that if the frameRate requires skipping four frames with scripts, it will render those four frames instead of skipping entirely, but it would fix scripts that rely on those symbols being present

Yup, adding this code here would work for people looking to recreate the standard flash timeline
#if (swflite_parent_fps || swf_parent_fps)
__updateFrame ();
#end

though, honestly, if at any point I can access a movieclip at frame X, I would expect to have full access to the movieclip at the frame. So this might be a good idea even if swf_parent_fps is false