Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/src/avm1/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 7 additions & 5 deletions core/src/avm1/object/stage_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -136,8 +136,10 @@ pub fn enumerate_keys<'gc>(dobj: DisplayObject<'gc>, keys: &mut Vec<AvmString<'g
if let Some(ctr) = dobj.as_container() {
// Button/MovieClip children are included in key list.
for child in ctr.iter_render_list().rev() {
if child.as_interactive().is_some() {
keys.push(child.name().expect("Interactive DisplayObjects have names"));
// All named DOs are included in the list, even if they're not
// accessible by AVM1 code (e.g. `MorphShape`)
if let Some(name) = child.name() {
keys.push(name);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/display_object/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Bitmap display object
use crate::avm1;
use crate::avm1::Object as Avm1Object;
use crate::avm2::{
Activation as Avm2Activation, BitmapDataObject as Avm2BitmapDataObject,
ClassObject as Avm2ClassObject, FunctionArgs as Avm2FunctionArgs,
Expand Down Expand Up @@ -312,13 +312,15 @@ impl<'gc> TDisplayObject<'gc> for Bitmap<'gc> {
fn post_instantiation(
self,
context: &mut UpdateContext<'gc>,
_init_object: Option<avm1::Object<'gc>>,
_init_object: Option<Avm1Object<'gc>>,
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()
Expand Down
12 changes: 12 additions & 0 deletions core/src/display_object/loader_display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::avm1::Object as Avm1Object;
use crate::avm2::Activation;
use crate::avm2::StageObject as Avm2StageObject;
use crate::context::RenderContext;
Expand All @@ -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};
Expand Down Expand Up @@ -117,6 +119,16 @@ impl<'gc> TDisplayObject<'gc> for LoaderDisplay<'gc> {
}
}

fn post_instantiation(
self,
context: &mut UpdateContext<'gc>,
_init_object: Option<Avm1Object<'gc>>,
_instantiated_by: Instantiator,
_run_frame: bool,
) {
self.set_default_instance_name(context);
}

fn movie(self) -> Arc<SwfMovie> {
self.0.movie.clone()
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/display_object/morph_shape.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -151,6 +153,18 @@ impl<'gc> TDisplayObject<'gc> for MorphShape<'gc> {
false
}

fn post_instantiation(
self,
context: &mut UpdateContext<'gc>,
_init_object: Option<Avm1Object<'gc>>,
_instantiated_by: Instantiator,
_run_frame: bool,
) {
if self.movie().is_action_script_3() {
self.set_default_instance_name(context);
}
}

fn movie(self) -> Arc<SwfMovie> {
self.0.shared.get().movie.clone()
}
Expand Down
24 changes: 16 additions & 8 deletions core/src/display_object/text.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -254,15 +255,10 @@ impl<'gc> TDisplayObject<'gc> for Text<'gc> {
false
}

fn post_instantiation(
self,
context: &mut UpdateContext<'gc>,
_init_object: Option<crate::avm1::Object<'gc>>,
_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
Expand All @@ -273,6 +269,18 @@ impl<'gc> TDisplayObject<'gc> for Text<'gc> {
}
}

fn post_instantiation(
self,
context: &mut UpdateContext<'gc>,
_init_object: Option<Avm1Object<'gc>>,
_instantiated_by: Instantiator,
_run_frame: bool,
) {
if self.movie().is_action_script_3() {
self.set_default_instance_name(context);
}
}

fn object1(self) -> Option<crate::avm1::Object<'gc>> {
None
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/display_object/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
30 changes: 30 additions & 0 deletions tests/tests/swfs/avm1/place_and_lookup/output.txt
Original file line number Diff line number Diff line change
@@ -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:
14 changes: 14 additions & 0 deletions tests/tests/swfs/avm1/place_and_lookup/test.as
Original file line number Diff line number Diff line change
@@ -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);
}
}
Binary file added tests/tests/swfs/avm1/place_and_lookup/test.swf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/place_and_lookup/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 1
55 changes: 55 additions & 0 deletions tests/tests/swfs/avm2/place_and_lookup/Test.as
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}

33 changes: 33 additions & 0 deletions tests/tests/swfs/avm2/place_and_lookup/swf10/output.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/place_and_lookup/swf10/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 1
33 changes: 33 additions & 0 deletions tests/tests/swfs/avm2/place_and_lookup/swf9/output.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/tests/swfs/avm2/place_and_lookup/swf9/test.swf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm2/place_and_lookup/swf9/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_frames = 1
Loading