Skip to content

Commit ee43c8a

Browse files
avm2: Move child construction work to Sprite constructor
This change should not be observable, as no other `DisplayObject` subclasses can have timeline children
1 parent a797456 commit ee43c8a

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

core/src/avm2/globals/flash/display/DisplayObject.as

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package flash.display {
1717
public class DisplayObject extends EventDispatcher implements IBitmapDrawable {
1818
private var _accessibilityProperties:AccessibilityProperties;
1919

20-
public native function DisplayObject();
21-
2220
public function get accessibilityProperties():AccessibilityProperties {
2321
return this._accessibilityProperties;
2422
}

core/src/avm2/globals/flash/display/Sprite.as

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ package flash.display {
66

77
[Ruffle(InstanceAllocator)]
88
public class Sprite extends DisplayObjectContainer {
9-
109
[Ruffle(NativeAccessible)]
1110
private var _graphics:Graphics;
1211

12+
public function Sprite() {
13+
super();
14+
this.constructChildren();
15+
}
16+
17+
private native function constructChildren():void;
18+
1319
public native function get graphics():Graphics;
1420
public native function get dropTarget():DisplayObject;
1521
public native function get soundTransform():SoundTransform;

core/src/avm2/globals/flash/display/display_object.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,6 @@ pub fn initialize_for_allocator<'gc>(
5353
obj.into()
5454
}
5555

56-
/// Implements `flash.display.DisplayObject`'s native instance constructor.
57-
pub fn display_object_initializer<'gc>(
58-
activation: &mut Activation<'_, 'gc>,
59-
this: Value<'gc>,
60-
_args: &[Value<'gc>],
61-
) -> Result<Value<'gc>, Error<'gc>> {
62-
// No need to call `super()`, it wouldn't do anything
63-
64-
let this = this.as_object().unwrap();
65-
66-
if let Some(dobj) = this.as_display_object() {
67-
if let Some(clip) = dobj.as_movie_clip() {
68-
clip.set_constructing_frame(true);
69-
}
70-
71-
if let Some(container) = dobj.as_container() {
72-
for child in container.iter_render_list() {
73-
child.construct_frame(activation.context);
74-
}
75-
}
76-
77-
if let Some(clip) = dobj.as_movie_clip() {
78-
clip.set_constructing_frame(false);
79-
}
80-
}
81-
82-
Ok(Value::Undefined)
83-
}
84-
8556
/// Implements `alpha`'s getter.
8657
pub fn get_alpha<'gc>(
8758
_activation: &mut Activation<'_, 'gc>,

core/src/avm2/globals/flash/display/sprite.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::avm2::globals::slots::{
99
use crate::avm2::object::{ClassObject, Object, StageObject, TObject as _};
1010
use crate::avm2::parameters::ParametersExt;
1111
use crate::avm2::value::Value;
12-
use crate::display_object::{MovieClip, SoundTransform, TDisplayObject};
12+
use crate::display_object::{MovieClip, SoundTransform, TDisplayObject, TDisplayObjectContainer};
1313
use swf::{Rectangle, Twips};
1414

1515
pub fn sprite_allocator<'gc>(
@@ -58,6 +58,25 @@ pub fn sprite_allocator<'gc>(
5858
unreachable!("A Sprite subclass should have Sprite in superclass chain");
5959
}
6060

61+
pub fn construct_children<'gc>(
62+
activation: &mut Activation<'_, 'gc>,
63+
this: Value<'gc>,
64+
_args: &[Value<'gc>],
65+
) -> Result<Value<'gc>, Error<'gc>> {
66+
let this = this.as_object().unwrap();
67+
let this = this.as_display_object().unwrap();
68+
let clip = this.as_movie_clip().unwrap();
69+
70+
// Construct children of this Sprite
71+
clip.set_constructing_frame(true);
72+
for child in clip.iter_render_list() {
73+
child.construct_frame(activation.context);
74+
}
75+
clip.set_constructing_frame(false);
76+
77+
Ok(Value::Undefined)
78+
}
79+
6180
/// Implements `dropTarget`'s getter
6281
pub fn get_drop_target<'gc>(
6382
_activation: &mut Activation<'_, 'gc>,

core/src/display_object/movie_clip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
24752475
self.construct_as_avm2_object(context);
24762476
self.on_construction_complete(context);
24772477
// If we're in the load frame and we were constructed by ActionScript,
2478-
// then we want to wait for the DisplayObject constructor to run
2478+
// then we want to wait for the Sprite constructor to run
24792479
// 'construct_frame' on children. This is observable by ActionScript -
24802480
// before calling super(), 'this.numChildren' will show a non-zero number
24812481
// when we have children placed on the load frame, but 'this.getChildAt(0)'

0 commit comments

Comments
 (0)