diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index 877274cc1fce..e2926a9d994e 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -2655,11 +2655,12 @@ impl<'a, 'gc> Activation<'a, 'gc> { .and_then(|o| o.as_container()) .and_then(|o| o.child_by_name(name, case_sensitive)) { - // If an object doesn't have an object representation, e.g. Graphic, then trying to access it - // Returns the parent instead if path_has_slash { child.object1_or_undef() - } else if let crate::display_object::DisplayObject::Graphic(_) = child { + } else if child.object1().is_none() { + // If an object doesn't have an object representation, + // e.g. Graphic, then trying to access it returns + // the parent instead child .parent() .map(|p| p.object1_or_undef()) diff --git a/core/src/avm1/object/stage_object.rs b/core/src/avm1/object/stage_object.rs index 5347cb63dacb..29a272392dae 100644 --- a/core/src/avm1/object/stage_object.rs +++ b/core/src/avm1/object/stage_object.rs @@ -39,9 +39,9 @@ pub fn get_property<'gc>( { return if is_slash_path { Some(child.object1_or_undef()) - // If an object doesn't have an object representation, e.g. Graphic, then trying to access it - // Returns the parent instead - } else if let crate::display_object::DisplayObject::Graphic(_) = child { + // If an object doesn't have an object representation, e.g. Graphic, + // then trying to access it returns the parent instead + } else if child.object1().is_none() { child.parent().map(|p| p.object1_or_undef()) } else { Some(child.object1_or_undef()) @@ -136,8 +136,10 @@ pub fn enumerate_keys<'gc>(dobj: DisplayObject<'gc>, keys: &mut Vec TDisplayObject<'gc> for Bitmap<'gc> { fn post_instantiation( self, context: &mut UpdateContext<'gc>, - _init_object: Option>, + _init_object: Option>, instantiated_by: Instantiator, _run_frame: bool, ) { let mc = context.gc(); if self.movie().is_action_script_3() { + self.set_default_instance_name(context); + if !instantiated_by.is_avm() { let bitmap_cls = self .avm2_bitmap_class() diff --git a/core/src/display_object/loader_display.rs b/core/src/display_object/loader_display.rs index a15ae17efaa7..0d679d802963 100644 --- a/core/src/display_object/loader_display.rs +++ b/core/src/display_object/loader_display.rs @@ -1,3 +1,4 @@ +use crate::avm1::Object as Avm1Object; use crate::avm2::Activation; use crate::avm2::StageObject as Avm2StageObject; use crate::context::RenderContext; @@ -11,6 +12,7 @@ use crate::prelude::*; use crate::display_object::container::ChildContainer; use crate::display_object::interactive::InteractiveObjectBase; use crate::tag_utils::SwfMovie; +use crate::vminterface::Instantiator; use core::fmt; use gc_arena::barrier::unlock; use gc_arena::lock::{Lock, RefLock}; @@ -117,6 +119,16 @@ impl<'gc> TDisplayObject<'gc> for LoaderDisplay<'gc> { } } + fn post_instantiation( + self, + context: &mut UpdateContext<'gc>, + _init_object: Option>, + _instantiated_by: Instantiator, + _run_frame: bool, + ) { + self.set_default_instance_name(context); + } + fn movie(self) -> Arc { self.0.movie.clone() } diff --git a/core/src/display_object/morph_shape.rs b/core/src/display_object/morph_shape.rs index a60d249ffab9..00a6d89c462b 100644 --- a/core/src/display_object/morph_shape.rs +++ b/core/src/display_object/morph_shape.rs @@ -1,9 +1,11 @@ +use crate::avm1::Object as Avm1Object; use crate::avm2::StageObject as Avm2StageObject; use crate::context::{RenderContext, UpdateContext}; use crate::display_object::DisplayObjectBase; use crate::library::{Library, MovieLibrarySource}; use crate::prelude::*; use crate::tag_utils::SwfMovie; +use crate::vminterface::Instantiator; use core::fmt; use gc_arena::barrier::unlock; use gc_arena::lock::Lock; @@ -151,6 +153,18 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> { false } + fn post_instantiation( + self, + context: &mut UpdateContext<'gc>, + _init_object: Option>, + _instantiated_by: Instantiator, + _run_frame: bool, + ) { + if self.movie().is_action_script_3() { + self.set_default_instance_name(context); + } + } + fn movie(self) -> Arc { self.0.shared.get().movie.clone() } diff --git a/core/src/display_object/text.rs b/core/src/display_object/text.rs index 5ae32636e5d9..4740801fcf61 100644 --- a/core/src/display_object/text.rs +++ b/core/src/display_object/text.rs @@ -1,3 +1,4 @@ +use crate::avm1::Object as Avm1Object; use crate::avm2::StageObject as Avm2StageObject; use crate::context::{RenderContext, UpdateContext}; use crate::display_object::DisplayObjectBase; @@ -254,15 +255,10 @@ impl<'gc> TDisplayObject<'gc> for Text<'gc> { false } - fn post_instantiation( - self, - context: &mut UpdateContext<'gc>, - _init_object: Option>, - _instantiated_by: Instantiator, - _run_frame: bool, - ) { - if self.movie().is_action_script_3() { + fn construct_frame(self, context: &mut UpdateContext<'gc>) { + if self.movie().is_action_script_3() && self.object2().is_none() { let statictext = context.avm2.classes().statictext; + let object = Avm2StageObject::for_display_object(context.gc(), self.into(), statictext); // We don't need to call the initializer method, as AVM2 can't link // a custom class to a StaticText, and the initializer method for @@ -273,6 +269,18 @@ impl<'gc> TDisplayObject<'gc> for Text<'gc> { } } + fn post_instantiation( + self, + context: &mut UpdateContext<'gc>, + _init_object: Option>, + _instantiated_by: Instantiator, + _run_frame: bool, + ) { + if self.movie().is_action_script_3() { + self.set_default_instance_name(context); + } + } + fn object1(self) -> Option> { None } diff --git a/core/src/display_object/video.rs b/core/src/display_object/video.rs index b724804cbf3e..b33b96a2e2a8 100644 --- a/core/src/display_object/video.rs +++ b/core/src/display_object/video.rs @@ -360,6 +360,10 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> { _instantiated_by: Instantiator, _run_frame: bool, ) { + if self.movie().is_action_script_3() { + self.set_default_instance_name(context); + } + let movie = self.0.movie.clone(); let (stream, keyframes) = match self.0.source.get() { diff --git a/tests/tests/swfs/avm1/place_and_lookup/output.txt b/tests/tests/swfs/avm1/place_and_lookup/output.txt new file mode 100644 index 000000000000..773dcbb3d0ce --- /dev/null +++ b/tests/tests/swfs/avm1/place_and_lookup/output.txt @@ -0,0 +1,30 @@ +prop: doPrint +object: [type Function] +object name: undefined +prop: placedButton +object: _level0.placedButton +object name: placedButton +prop: instanceXX +object: _level0.instanceXX +object name: instanceXX +prop: placedVideo +object: _level0.placedVideo +object name: placedVideo +prop: placedImage +object: _level0 +object name: +prop: placedText +object: _level0 +object name: +prop: placedSprite +object: _level0.placedSprite +object name: placedSprite +prop: instanceXX +object: _level0.instanceXX +object name: instanceXX +prop: placedMorph +object: _level0 +object name: +prop: placedShape +object: _level0 +object name: diff --git a/tests/tests/swfs/avm1/place_and_lookup/test.as b/tests/tests/swfs/avm1/place_and_lookup/test.as new file mode 100644 index 000000000000..15ea7bc11763 --- /dev/null +++ b/tests/tests/swfs/avm1/place_and_lookup/test.as @@ -0,0 +1,14 @@ +var doPrint = function(string) { + if(string.indexOf("instance") != -1) { + trace(string.substring(0,string.indexOf("instance")) + "instanceXX"); + } else { + trace(string); + } +}; +for(var key in _root) { + if(key != "$version") { + doPrint("prop: " + key); + doPrint("object: " + _root[key]); + doPrint("object name: " + _root[key]._name); + } +} diff --git a/tests/tests/swfs/avm1/place_and_lookup/test.swf b/tests/tests/swfs/avm1/place_and_lookup/test.swf new file mode 100644 index 000000000000..b884a9c89e8e Binary files /dev/null and b/tests/tests/swfs/avm1/place_and_lookup/test.swf differ diff --git a/tests/tests/swfs/avm1/place_and_lookup/test.toml b/tests/tests/swfs/avm1/place_and_lookup/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm1/place_and_lookup/test.toml @@ -0,0 +1 @@ +num_frames = 1 diff --git a/tests/tests/swfs/avm2/place_and_lookup/Test.as b/tests/tests/swfs/avm2/place_and_lookup/Test.as new file mode 100644 index 000000000000..828aa63802aa --- /dev/null +++ b/tests/tests/swfs/avm2/place_and_lookup/Test.as @@ -0,0 +1,55 @@ +package { + import flash.display.*; + import flash.media.Video; + + public class Test extends MovieClip { + public var placedShape:DisplayObject; + + public var placedMorph:DisplayObject; + + public var placedSprite:DisplayObject; + + public var placedVideo:DisplayObject; + + public var placedButton:DisplayObject; + + public var placedText:DisplayObject; + + public function Test() { + super(); + + trace(this.placedShape); + trace(this.placedMorph); + trace(this.placedSprite); + trace(this.placedVideo); + trace(this.placedButton); + trace(this.placedText); + + for (var i = 0; i < this.numChildren; i ++) { + var child:DisplayObject = this.getChildAt(i); + trace(child); + if (child != null) { + traceInstanceName(child.name); + } + } + + var c:DisplayObject = new Bitmap(); + traceInstanceName(c.name); + + c = new Shape(); + traceInstanceName(c.name); + + c = new Video(); + traceInstanceName(c.name); + } + + static function traceInstanceName(name:String):void { + if (name.indexOf("instance") == 0) { + trace("instanceXX"); + } else { + trace(name); + } + } + } +} + diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf10/output.txt b/tests/tests/swfs/avm2/place_and_lookup/swf10/output.txt new file mode 100644 index 000000000000..c37ddddd717e --- /dev/null +++ b/tests/tests/swfs/avm2/place_and_lookup/swf10/output.txt @@ -0,0 +1,33 @@ +[object Shape] +[object MorphShape] +[object MovieClip] +[object Video] +[object SimpleButton] +[object StaticText] +[object Shape] +instanceXX +[object Shape] +placedShape +[object MorphShape] +instanceXX +[object MorphShape] +placedMorph +[object MovieClip] +instanceXX +[object MovieClip] +placedSprite +[object StaticText] +instanceXX +[object StaticText] +placedText +[object Video] +instanceXX +[object Video] +placedVideo +[object SimpleButton] +instanceXX +[object SimpleButton] +placedButton +instanceXX +instanceXX +instanceXX diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf10/test.swf b/tests/tests/swfs/avm2/place_and_lookup/swf10/test.swf new file mode 100644 index 000000000000..b0fe6649f385 Binary files /dev/null and b/tests/tests/swfs/avm2/place_and_lookup/swf10/test.swf differ diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf10/test.toml b/tests/tests/swfs/avm2/place_and_lookup/swf10/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm2/place_and_lookup/swf10/test.toml @@ -0,0 +1 @@ +num_frames = 1 diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf9/output.txt b/tests/tests/swfs/avm2/place_and_lookup/swf9/output.txt new file mode 100644 index 000000000000..c37ddddd717e --- /dev/null +++ b/tests/tests/swfs/avm2/place_and_lookup/swf9/output.txt @@ -0,0 +1,33 @@ +[object Shape] +[object MorphShape] +[object MovieClip] +[object Video] +[object SimpleButton] +[object StaticText] +[object Shape] +instanceXX +[object Shape] +placedShape +[object MorphShape] +instanceXX +[object MorphShape] +placedMorph +[object MovieClip] +instanceXX +[object MovieClip] +placedSprite +[object StaticText] +instanceXX +[object StaticText] +placedText +[object Video] +instanceXX +[object Video] +placedVideo +[object SimpleButton] +instanceXX +[object SimpleButton] +placedButton +instanceXX +instanceXX +instanceXX diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf9/test.swf b/tests/tests/swfs/avm2/place_and_lookup/swf9/test.swf new file mode 100644 index 000000000000..b1cf363ef44c Binary files /dev/null and b/tests/tests/swfs/avm2/place_and_lookup/swf9/test.swf differ diff --git a/tests/tests/swfs/avm2/place_and_lookup/swf9/test.toml b/tests/tests/swfs/avm2/place_and_lookup/swf9/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm2/place_and_lookup/swf9/test.toml @@ -0,0 +1 @@ +num_frames = 1