Fire events directly onto `broadcastMessage` instead of the individual event handlers on the `MovieClipLoader`, so that listeners run correctly.

Also, this fixes a double-borrow for `onClipInit`.
This commit is contained in:
David Wendt 2020-01-17 18:24:06 -05:00
parent 89e5dd97f3
commit b56c3b6aed
2 changed files with 20 additions and 9 deletions

View File

@ -968,6 +968,7 @@ impl<'gc> MovieClipData<'gc> {
if let ClipEvent::Load = event { if let ClipEvent::Load = event {
context.load_manager.movie_clip_on_load( context.load_manager.movie_clip_on_load(
self_display_object, self_display_object,
self.object,
context.root, context.root,
context.action_queue, context.action_queue,
); );

View File

@ -88,13 +88,14 @@ impl<'gc> LoadManager<'gc> {
pub fn movie_clip_on_load( pub fn movie_clip_on_load(
&mut self, &mut self,
loaded_clip: DisplayObject<'gc>, loaded_clip: DisplayObject<'gc>,
clip_object: Option<Object<'gc>>,
root: DisplayObject<'gc>, root: DisplayObject<'gc>,
queue: &mut ActionQueue<'gc>, queue: &mut ActionQueue<'gc>,
) { ) {
let mut invalidated_loaders = vec![]; let mut invalidated_loaders = vec![];
for (index, loader) in self.0.iter_mut() { for (index, loader) in self.0.iter_mut() {
if loader.movie_clip_loaded(loaded_clip, root, queue) { if loader.movie_clip_loaded(loaded_clip, clip_object, root, queue) {
invalidated_loaders.push(index); invalidated_loaders.push(index);
} }
} }
@ -223,8 +224,8 @@ impl<'gc> Loader<'gc> {
broadcaster, broadcaster,
NEWEST_PLAYER_VERSION, NEWEST_PLAYER_VERSION,
uc, uc,
"onLoadStart", "broadcastMessage",
&[Value::Object(broadcaster)], &["onLoadStart".into(), Value::Object(broadcaster)],
); );
avm.run_stack_till_empty(uc)?; avm.run_stack_till_empty(uc)?;
} }
@ -256,8 +257,9 @@ impl<'gc> Loader<'gc> {
broadcaster, broadcaster,
NEWEST_PLAYER_VERSION, NEWEST_PLAYER_VERSION,
uc, uc,
"onLoadProgress", "broadcastMessage",
&[ &[
"onLoadProgress".into(),
Value::Object(broadcaster), Value::Object(broadcaster),
data.len().into(), data.len().into(),
data.len().into(), data.len().into(),
@ -293,8 +295,8 @@ impl<'gc> Loader<'gc> {
broadcaster, broadcaster,
NEWEST_PLAYER_VERSION, NEWEST_PLAYER_VERSION,
uc, uc,
"onLoadComplete", "broadcastMessage",
&[Value::Object(broadcaster)], &["onLoadComplete".into(), Value::Object(broadcaster)],
); );
avm.run_stack_till_empty(uc)?; avm.run_stack_till_empty(uc)?;
} }
@ -322,8 +324,12 @@ impl<'gc> Loader<'gc> {
broadcaster, broadcaster,
NEWEST_PLAYER_VERSION, NEWEST_PLAYER_VERSION,
uc, uc,
"onLoadError", "broadcastMessage",
&[Value::Object(broadcaster), "LoadNeverCompleted".into()], &[
"onLoadError".into(),
Value::Object(broadcaster),
"LoadNeverCompleted".into(),
],
); );
avm.run_stack_till_empty(uc)?; avm.run_stack_till_empty(uc)?;
} }
@ -377,6 +383,7 @@ impl<'gc> Loader<'gc> {
pub fn movie_clip_loaded( pub fn movie_clip_loaded(
&mut self, &mut self,
loaded_clip: DisplayObject<'gc>, loaded_clip: DisplayObject<'gc>,
clip_object: Option<Object<'gc>>,
root: DisplayObject<'gc>, root: DisplayObject<'gc>,
queue: &mut ActionQueue<'gc>, queue: &mut ActionQueue<'gc>,
) -> bool { ) -> bool {
@ -397,7 +404,10 @@ impl<'gc> Loader<'gc> {
ActionType::Method { ActionType::Method {
object: broadcaster, object: broadcaster,
name: "broadcastMessage", name: "broadcastMessage",
args: vec!["onLoadInit".into(), loaded_clip.object()], args: vec![
"onLoadInit".into(),
clip_object.map(|co| co.into()).unwrap_or(Value::Undefined),
],
}, },
false, false,
); );