简体   繁体   English

AS3加载,播放和静音外部SWF

[英]as3 load, play and mute external swf

I have a file to which I do not have the source - a flash header with an obnoxious sound intro and I need to mute all sounds. 我有一个我没有来源的文件-带有令人讨厌的声音简介的Flash标头,我需要使所有声音静音。 Without the source I am limited as to what I can do. 没有资源,我只能做什么。 I have some as3 code that I am using to try and load the swf into and mute(building in FlashDevelop). 我有一些as3代码,用于尝试将swf加载到静音中(在FlashDevelop中构建)。 Here is the code in question: 这是有问题的代码:

package 
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.media.SoundTransform;

public class Main extends Sprite 
{
    private var mLoader:Loader;
    private var mc1:MovieClip;
    private var holder:Sprite;
    private var mSound:SoundTransform;

    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        var mRequest:URLRequest = new URLRequest('header_v8.swf');
        mLoader = new Loader();
        mLoader.load(mRequest);
        holder = new Sprite();
        holder.addChild(mLoader);
        addChild(holder);
        mSound = new SoundTransform(0);
        holder.soundTransform = mSound;

    }

}

} }

This code above still plays the audio and the original swf is not being displayed. 上面的这段代码仍会播放音频,并且不会显示原始的瑞士法郎。 So, my questions are: 因此,我的问题是:

How would I mute the external audio? 我如何使外部音频静音? How would I display the external swf just as it does when viewing it directly? 与直接查看时一样,我如何显示外部瑞士法郎?

Any suggestions or pointers to useful examples/documentation would be greatly appreciated 任何建议或指向有用的示例/文档的指针将不胜感激

Are you running this in a debug player? 您是否正在调试播放器中运行它? Looking at your code, it seems it should throw at least an Error at this line: 查看您的代码,看来这行应该至少抛出一个错误:

holder.addChild(mLoader);

It seems holder is not initialized at that point. 似乎holder在那时还没有初始化。 Maybe there's an error you're not seeing that breaks your code... The code for muting the sound looks right (though I haven't tried it). 也许您看不到有错误会打断您的代码...使声音静音的代码看起来正确(尽管我没有尝试过)。 Maybe you could apply it to the holder instead of the content itself; 也许您可以将其应用到holder而不是内容本身。 otherwise it would be possible that your header swf loaded partially and started to play back sounds before your complete handler is called. 否则,您的标头swf可能会部分加载,并在调用完整的处理程序之前开始播放声音。

Also SoundMixer lets you control the global volume (I mention it because although it might not be the ideal way of doing this, maybe it just works here). SoundMixer还可以让您控制全局音量(我提到了它,因为虽然这可能不是理想的方式,但也许只在这里起作用)。

Edit 编辑

This effectively mutes the loaded swf in a quick test I did: 在我做的快速测试中,这有效地使加载的瑞士法郎静音:

var mRequest:URLRequest = new URLRequest('banner.swf');
var mLoader:Loader = new Loader();
mLoader.load(mRequest);
var holder:Sprite = new Sprite();
holder.addChild(mLoader);
addChild(holder);
var t:SoundTransform = new SoundTransform(0);
holder.soundTransform = t;

I removed the complete handler, since it's not needed anymore. 我删除了完整的处理程序,因为不再需要它。

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

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