core: Register character 0 with library in Loader
This allows ActionScript code to instantiate the AVM2 class for the root MovieClip of a loaded movie. This instance will have its frames run, including timeline-placed children.
We now store avm2_class in MovieClipStatic, so that processing a SymbolClass tag from a loaded MovieClip will update the class used by the MovieClip stored in the Library.
Fixes #14639
This is technically wrong- the root MovieClip of a loaded movie doesn't always have to be registered under character id #0 (see #12823)- it only has to be registered under a character id that no other character claims. Can the registration logic in loader.rs not hard-code id #0 as the character id that the root MC is registered under?
Are you sure? SymbolClass only links the AVM2 class name with a sprite id. Registering the loaded clip as character 0 will only have an effect if there's an explicit SymbolClass referencing character 0.
The code is all correct, for our current implementation. However, FP allows linking the root MovieClip with a character id other than 0. If we fix that bug (like the PR I linked does), we'll also need to update this logic:
library.register_character(
0,
// Use 'instantiate' to clone movie clip data, so future instantiations
// don't reflect changes made to the loaded main timeline instance.
Character::MovieClip(mc.instantiate(gc_context).as_movie_clip().unwrap()),
);
to use the correct character id instead of always using character id 0.