Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading bundles on Flash #32

Merged
merged 2 commits into from
Oct 23, 2024
Merged

Conversation

dpomier
Copy link

@dpomier dpomier commented Oct 9, 2024

This PR add missing fences around Sprite.__constructor for flash.

@joshtynjala
Copy link
Member

This is likely not the correct solution. OpenFL has a custom extern for MovieClip that defines __constructor to support the swf library. It's likely that the extern for Sprite should also define its own __constructor for the same reason.

https://github.com/openfl/openfl/blob/6755608/lib/flash-externs/src/flash/display/MovieClip.hx#L11

@joshtynjala
Copy link
Member

Actually, in the following commit, I can see where (on non-Flash targets) __constructor was moved from MovieClip to Sprite.

openfl/openfl@d579268

It appears that the Flash externs were accidentally omitted from this change. So my previous comment is on the right track, but may have some of the details wrong. __constructor may need to move from MovieClip to Sprite in the Flash externs too (rather than duplicating it). And then some mechanism needs to exist to call __constructor. Unfortunately, I don't have time at the moment to figure out the exact details.

@jgranick made the change for non-Flash targets. If he's available, he might know better what's needed to fix the Flash externs here.

@jgranick
Copy link
Member

The trick here is we need to new MovieClip() then execute code immediately before we leave the class constructor.

MovieClip.__constructor is OpenFL's internal method to accomplish this. Later I moved it to Sprite.__constructor because Flash Professional/Adobe Animate allows a base class for Sprite and MovieClip symbols.

We're not in Flash internals, so non-Flash targets use a base class called flash.display.MovieClip2 which limps us to much of the same result:

https://github.com/openfl/openfl/blob/develop/lib/flash-externs/src/flash/display/MovieClip.hx

Options:

1.) Promote Sprite symbols to MovieClip on Flash (in order to use MovieClip2)
2.) Create an additional Sprite2 class on Flash
3.) Call __constructor on Flash manually after the object has been created
4.) Check if the object is MovieClip2 (__constructor was called automatically). If not, call __constructor manually before returning the object.

Option 4 seems like a good bet. There's already a check here (though seems redundant?)

if (!#if (haxe_ver >= 4.2) Std.isOfType #else Std.is #end (sprite, flash.display.MovieClip.MovieClip2))

If not MovieClip2, we could call __constructor manually to run initializeSprite. Presumably, that would work fine.

IMHO options 1 and 2 are poor choices. Option 3 would remove the need for MovieClip2.__constructor, though would be a step back in functionality in some cases.

Here would be my action steps:

1.) Set MovieClip2.__constructor on Flash
2.) Create the object
3.) Check if the created object is a MovieClip2
4.) If yes, do nothing (__constructor was already called)
5.) If no, set MovieClip2.__constructor to null, and call __constructor manually on the object
6.) Return

@dpomier
Copy link
Author

dpomier commented Oct 14, 2024

Thanks for the feedback. I've updated the PR with your suggestion, which seems to work just fine.

When testing, I had somehow the value "null" in frameObject.blendMode which led to an error in AnimateTimeline.__updateDisplayObject on Flash. I assume this is a different topic though.

@jgranick jgranick merged commit 583ba02 into openfl:master Oct 23, 2024
@jgranick
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants