diff --git a/core/src/avm2/globals/flash/display/movieclip.rs b/core/src/avm2/globals/flash/display/movieclip.rs index f07d17a1f..77073a9ce 100644 --- a/core/src/avm2/globals/flash/display/movieclip.rs +++ b/core/src/avm2/globals/flash/display/movieclip.rs @@ -5,6 +5,7 @@ use crate::avm2::class::Class; use crate::avm2::method::Method; use crate::avm2::names::{Namespace, QName}; use crate::avm2::object::{Object, TObject}; +use crate::avm2::string::AvmString; use crate::avm2::traits::Trait; use crate::avm2::value::Value; use crate::avm2::Error; @@ -64,7 +65,7 @@ pub fn current_frame<'gc>( .and_then(|dobj| dobj.as_movie_clip()) { if let Some((_scene, scene_basis)) = mc.current_scene() { - return Ok((mc.current_frame() - scene_basis + 1).into()); + return Ok(((mc.current_frame() + 1) - scene_basis).into()); } else { return Ok(mc.current_frame().into()); } @@ -73,6 +74,52 @@ pub fn current_frame<'gc>( Ok(Value::Undefined) } +/// Implements `currentFrameLabel`. +pub fn current_frame_label<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(mc) = this + .and_then(|o| o.as_display_object()) + .and_then(|dobj| dobj.as_movie_clip()) + { + return Ok(mc + .current_label() + .and_then(|(label, start_frame)| { + if start_frame < mc.current_frame() { + None + } else { + Some(AvmString::new(activation.context.gc_context, label).into()) + } + }) + .unwrap_or(Value::Null)); + } + + Ok(Value::Undefined) +} + +/// Implements `currentLabel`. +pub fn current_label<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(mc) = this + .and_then(|o| o.as_display_object()) + .and_then(|dobj| dobj.as_movie_clip()) + { + return Ok(mc + .current_label() + .map(|(label, _start_frame)| { + AvmString::new(activation.context.gc_context, label).into() + }) + .unwrap_or(Value::Null)); + } + + Ok(Value::Undefined) +} + /// Construct `MovieClip`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -95,5 +142,15 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> Method::from_builtin(current_frame), )); + write.define_instance_trait(Trait::from_getter( + QName::new(Namespace::package(""), "currentFrameLabel"), + Method::from_builtin(current_frame_label), + )); + + write.define_instance_trait(Trait::from_getter( + QName::new(Namespace::package(""), "currentLabel"), + Method::from_builtin(current_label), + )); + class }