File tree Expand file tree Collapse file tree 6 files changed +31
-14
lines changed Expand file tree Collapse file tree 6 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,26 @@ impl<'gc> AudioManager<'gc> {
532532 } ) ;
533533 }
534534
535+ /// Stops any sound associated with the given Display Object and its children. The DO must represent the parent.
536+ /// Sounds associated with DOs are an AVM1/Timeline concept and should not be called from AVM2 scripts.
537+ pub fn stop_sounds_on_parent_and_children (
538+ & mut self ,
539+ audio : & mut dyn AudioBackend ,
540+ display_object : DisplayObject < ' gc > ,
541+ ) {
542+ self . sounds . retain ( move |sound| {
543+ let mut other = sound. display_object ;
544+ while let Some ( other_do) = other {
545+ if DisplayObject :: ptr_eq ( other_do, display_object) {
546+ audio. stop_sound ( sound. instance ) ;
547+ return false ;
548+ }
549+ other = other_do. parent ( ) ;
550+ }
551+ true
552+ } ) ;
553+ }
554+
535555 pub fn stop_all_sounds ( & mut self , audio : & mut dyn AudioBackend ) {
536556 self . sounds . clear ( ) ;
537557 audio. stop_all_sounds ( ) ;
Original file line number Diff line number Diff line change @@ -287,6 +287,11 @@ impl<'gc> UpdateContext<'gc> {
287287 . stop_sounds_with_display_object ( self . audio , display_object)
288288 }
289289
290+ pub fn stop_sounds_on_parent_and_children ( & mut self , display_object : DisplayObject < ' gc > ) {
291+ self . audio_manager
292+ . stop_sounds_on_parent_and_children ( self . audio , display_object)
293+ }
294+
290295 pub fn stop_all_sounds ( & mut self ) {
291296 self . audio_manager . stop_all_sounds ( self . audio )
292297 }
Original file line number Diff line number Diff line change @@ -2147,10 +2147,6 @@ pub trait TDisplayObject<'gc>:
21472147 }
21482148 }
21492149
2150- context
2151- . audio_manager
2152- . stop_sounds_with_display_object ( context. audio , ( * self ) . into ( ) ) ;
2153-
21542150 self . set_avm1_removed ( context. gc_context , true ) ;
21552151 }
21562152
Original file line number Diff line number Diff line change @@ -404,9 +404,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
404404 } else if let Some ( node) = self . masker ( ) {
405405 node. set_maskee ( context. gc ( ) , None , true ) ;
406406 }
407- context
408- . audio_manager
409- . stop_sounds_with_display_object ( context. audio , ( * self ) . into ( ) ) ;
407+
410408 self . set_avm1_removed ( context. gc ( ) , true ) ;
411409 }
412410}
Original file line number Diff line number Diff line change @@ -2413,10 +2413,6 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
24132413 . retain ( |& text_field| !DisplayObject :: ptr_eq ( text_field. into ( ) , ( * self ) . into ( ) ) ) ;
24142414 }
24152415
2416- context
2417- . audio_manager
2418- . stop_sounds_with_display_object ( context. audio , ( * self ) . into ( ) ) ;
2419-
24202416 self . set_avm1_removed ( context. gc_context , true ) ;
24212417 }
24222418}
Original file line number Diff line number Diff line change @@ -2925,9 +2925,11 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
29252925 mc. stop_audio_stream ( context) ;
29262926 }
29272927
2928- context
2929- . audio_manager
2930- . stop_sounds_with_display_object ( context. audio , ( * self ) . into ( ) ) ;
2928+ if self . is_root ( ) {
2929+ context
2930+ . audio_manager
2931+ . stop_sounds_on_parent_and_children ( context. audio , ( * self ) . into ( ) ) ;
2932+ }
29312933
29322934 // If this clip is currently pending removal, then it unload event will have already been dispatched
29332935 if !self . avm1_pending_removal ( ) {
You can’t perform that action at this time.
0 commit comments