简体   繁体   English

在AS3中控制AS2 SWF播放

[英]Controlling as2 swf playback in as3

I am embedding a swf built in flash 8 into an as3 project. 我将内置Flash 8的swf嵌入到as3项目中。 When I call stop() or gotoAndStop(0); 当我调用stop()或gotoAndStop(0); on the MovieClip that represents an instance of the embedded swf it stops for a sec and then continues. 在表示嵌入式SWF实例的MovieClip上,它会停止一秒钟,然后继续。 Trying to call removeChild on the mc removes it from the display but the audio in the swf keeps playing. 尝试在mc上调用removeChild会将其从显示器中删除,但swf中的音频会继续播放。 The swf, in this case must be embedded, I cannot use loader. 瑞士法郎,在这种情况下必须嵌入,我不能使用加载程序。 Any ideas 有任何想法吗

The code: 编码:

    [Embed (source = "t1.swf")]
    private var t1:Class;

    private var mc:MovieClip;

      public function iphoneTest()
      {
       var tf:TextField = new TextField();   
       tf.x = 10;
       tf.y = 100;
       tf.width = 100;
       tf.height = 50;
       tf.text = "Hello worl";
       mc = new t1();
       var button:CustomSimpleButton = new CustomSimpleButton();
       button.width = 50;
       button.height = 50;
       button.x = 10;
       button.y = 150;
       button.addEventListener(MouseEvent.CLICK, onClick);

       this.addChild(mc);
       this.addChild(tf);
       this.addChild(button);
   }

   private function onClick(e:MouseEvent):void {

       mc.stop();    
       this.removeChild(mc);
   }

did you try mc = null; 您是否尝试过mc = null; ?

also since you know it's an as2 swf, should probably use avm1movie instead of MovieClip 也因为您知道它是一个as2 swf,所以可能应该使用avm1movie而不是MovieClip

At very worst you can just kill all sounds in the SWF... 在最坏的情况下,您可以杀死SWF中的所有声音...

Make sure you import the sound mixer class then kill the sound.. 确保导入混音器类,然后终止声音。

import flash.media.SoundMixer; 
SoundMixer.stopAll();

If your SWF has any hierarchy, you'll need to recurse through it to stop all movie clips. 如果您的SWF具有任何层次结构,则需要通过它进行递归才能停止所有影片剪辑。

private function stopAll(do:DisplayObject):void
{
    var clip:MovieClip = do as MovieClip;
    if (clip != null)
        clip.stop();

    var container:DisplayObjectContainer = do as DisplayObjectContainer;
    if (container != null)
    {
        for (var i:int = 0; i < container.numChildren; ++i)
        {
            stopAll(container.getChildAt(i));
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM