diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index a6129fba3..a2504d199 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -2776,6 +2776,7 @@ impl<'a, 'gc, 'gc_context> Activation<'a, 'gc, 'gc_context> { .into(); level.set_depth(self.context.gc_context, level_id as i32); + level.set_default_root_name(&mut self.context); self.context.levels.insert(level_id, level); level.post_instantiation(&mut self.context, level, None, Instantiator::Movie, false); diff --git a/core/src/display_object.rs b/core/src/display_object.rs index 308217599..39e7d65ba 100644 --- a/core/src/display_object.rs +++ b/core/src/display_object.rs @@ -949,6 +949,18 @@ pub trait TDisplayObject<'gc>: } } + /// Assigns a default root name to this object. + /// + /// The default root names change based on the AVM configuration of the + /// clip; AVM2 clips get `rootN` while AVM1 clips get blank strings. + fn set_default_root_name(&self, context: &mut UpdateContext<'_, 'gc, '_>) { + if !matches!(self.object2(), Avm2Value::Undefined) { + self.set_name(context.gc_context, &format!("root{}", self.depth() + 1)); + } else if !matches!(self.object(), Avm1Value::Undefined) { + self.set_name(context.gc_context, ""); + } + } + fn bind_text_field_variables(&self, activation: &mut Activation<'_, 'gc, '_>) { // Check all unbound text fields to see if they apply to this object. // TODO: Replace with `Vec::drain_filter` when stable. diff --git a/core/src/player.rs b/core/src/player.rs index 3fa16f6e9..6469f06ce 100644 --- a/core/src/player.rs +++ b/core/src/player.rs @@ -377,7 +377,7 @@ impl Player { None }; root.post_instantiation(context, root, flashvars, Instantiator::Movie, false); - root.set_name(context.gc_context, ""); + root.set_default_root_name(context); context.levels.insert(0, root); // Load and parse the device font.