Skip to content

Commit f34ba0c

Browse files
core/avm2: Support SWFv9 code moving around AVM1Movies in the display list
1 parent 06c99e2 commit f34ba0c

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn validate_add_operation<'gc>(
4040
)?));
4141
}
4242

43-
if !proposed_child.movie().is_action_script_3() {
43+
if !proposed_child.movie().is_action_script_3() && activation.context.root_swf.version() > 9 {
4444
return Err(Error::avm_error(argument_error(
4545
activation,
4646
"Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.",

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn get_bytes_loaded<'gc>(
131131

132132
/// `content` getter
133133
pub fn get_content<'gc>(
134-
activation: &mut Activation<'_, 'gc>,
134+
_activation: &mut Activation<'_, 'gc>,
135135
this: Value<'gc>,
136136
_args: &[Value<'gc>],
137137
) -> Result<Value<'gc>, Error<'gc>> {
@@ -145,18 +145,7 @@ pub fn get_content<'gc>(
145145
let loader_stream = loader_info.loader_stream();
146146
match &*loader_stream {
147147
LoaderStream::Swf(_, root) | LoaderStream::NotYetLoaded(_, Some(root), _) => {
148-
if root.movie().is_action_script_3() || !root.movie().is_movie() {
149-
Ok(root.object2())
150-
} else {
151-
// The movie was an AVM1 movie, return an AVM1Movie object
152-
let root_obj = *root;
153-
drop(loader_stream);
154-
155-
let loader_info = this.as_loader_info_object().unwrap();
156-
Ok(loader_info
157-
.get_or_init_avm1movie(activation, root_obj)
158-
.into())
159-
}
148+
Ok(root.object2())
160149
}
161150
_ => Ok(Value::Null),
162151
}

core/src/avm2/object/loaderinfo_object.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::avm2::activation::Activation;
44
use crate::avm2::object::script_object::ScriptObjectData;
5-
use crate::avm2::object::{EventObject, Object, StageObject, TObject};
5+
use crate::avm2::object::{EventObject, Object, TObject};
66
use crate::avm2::{Avm2, Error, Value};
77
use crate::context::UpdateContext;
88
use crate::display_object::DisplayObject;
@@ -314,29 +314,6 @@ impl<'gc> LoaderInfoObject<'gc> {
314314
self.0.content_type.set(content_type);
315315
}
316316

317-
/// Returns the AVM1Movie corresponding to the loaded movie- if
318-
/// it doesn't exist yet, creates it.
319-
pub fn get_or_init_avm1movie(
320-
&self,
321-
activation: &mut Activation<'_, 'gc>,
322-
obj: DisplayObject<'gc>,
323-
) -> Object<'gc> {
324-
let cached_avm1movie = self.0.cached_avm1movie.get();
325-
if cached_avm1movie.is_none() {
326-
let class_object = activation.avm2().classes().avm1movie;
327-
let object = StageObject::for_display_object(activation.gc(), obj, class_object);
328-
329-
unlock!(
330-
Gc::write(activation.gc(), self.0),
331-
LoaderInfoObjectData,
332-
cached_avm1movie
333-
)
334-
.set(Some(object.into()));
335-
}
336-
337-
self.0.cached_avm1movie.get().unwrap()
338-
}
339-
340317
pub fn unload(&self, activation: &mut Activation<'_, 'gc>) {
341318
// Reset properties
342319
let movie = &activation.context.root_swf;

core/src/display_object/movie_clip.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,15 @@ impl<'gc> MovieClip<'gc> {
18741874
}
18751875
}
18761876

1877+
/// Called on an AVM1 MovieClip that has been loaded by AVM2 (i.e. a
1878+
/// mixed-AVM MovieClip) to create its AVM2-side `AVM1Movie` object.
1879+
pub fn set_avm1movie(self, context: &mut UpdateContext<'gc>) {
1880+
let class_object = context.avm2.classes().avm1movie;
1881+
let object = Avm2StageObject::for_display_object(context.gc(), self.into(), class_object);
1882+
1883+
self.set_object2(context, object);
1884+
}
1885+
18771886
pub fn register_frame_script(
18781887
self,
18791888
frame_id: FrameNumber,

core/src/loader.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,9 @@ impl<'gc> Loader<'gc> {
21372137
mc.post_instantiation(uc, None, Instantiator::Movie, false);
21382138

21392139
mc.set_depth(LOADER_INSERTED_AVM1_DEPTH);
2140+
2141+
// We also need to create its AVM2-side object, the `AVM1Movie`.
2142+
mc.set_avm1movie(uc);
21402143
}
21412144

21422145
if from_bytes {

0 commit comments

Comments
 (0)