avm2: Correctly set and use Video class from Rust

This commit is contained in:
Adrian Wielgosik 2023-07-01 22:13:44 +02:00 committed by Adrian Wielgosik
parent 7ad864ca02
commit 7eb7f2ee2c
3 changed files with 19 additions and 1 deletions

View File

@ -725,6 +725,7 @@ fn load_playerglobal<'gc>(
("flash.geom", "ColorTransform", colortransform),
("flash.media", "SoundChannel", soundchannel),
("flash.media", "SoundTransform", soundtransform),
("flash.media", "Video", video),
("flash.net", "URLVariables", urlvariables),
("flash.utils", "ByteArray", bytearray),
("flash.system", "ApplicationDomain", application_domain),

View File

@ -75,6 +75,21 @@ impl<'gc> StageObject<'gc> {
Ok(this)
}
/// Same as for_display_object_childless, but allows passing
/// constructor arguments.
pub fn for_display_object_childless_with_args(
activation: &mut Activation<'_, 'gc>,
display_object: DisplayObject<'gc>,
class: ClassObject<'gc>,
args: &[Value<'gc>],
) -> Result<Self, Error<'gc>> {
let this = Self::for_display_object(activation, display_object, class)?;
class.call_native_init(Some(this.into()), args, activation)?;
Ok(this)
}
/// Create a `graphics` object for a given display object.
pub fn graphics(
activation: &mut Activation<'_, 'gc>,

View File

@ -477,10 +477,12 @@ impl<'gc> TDisplayObject<'gc> for Video<'gc> {
if context.is_action_script_3() && matches!(self.object2(), Avm2Value::Null) {
let video_constr = context.avm2.classes().video;
let mut activation = Avm2Activation::from_nothing(context.reborrow());
match Avm2StageObject::for_display_object_childless(
let size = self.0.read().size;
match Avm2StageObject::for_display_object_childless_with_args(
&mut activation,
(*self).into(),
video_constr,
&[size.0.into(), size.1.into()],
) {
Ok(object) => {
let object: Avm2Object<'gc> = object.into();