views:

125

answers:

1

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. 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). 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

+2  A: 

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. 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; otherwise it would be possible that your header swf loaded partially and started to play back sounds before your complete handler is called.

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).

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.

Juan Pablo Califano
looking back at it the holder variable is not really needed. after removing it and simply using addChild(mLoader); it loaded the swf as expected. However, after viewing in the debug player I found out the the loaded swf is an AVM1Movie. I am going to have to do some more research as to how to properly load and mute that.
tomfmason
In that case, you cannot directly communicate with it. But maybe (I never had to do this) having a holder `Sprite` and muting it could work to mute the loaded swf.
Juan Pablo Califano
I tried that(see edited OP) but it is still playing the audio from the loaded swf. Any suggestions?
tomfmason
@tomfmason. Check my edit.
Juan Pablo Califano
awesome.. thanks. I edited the OP to show the working code.Thanks again
tomfmason
No problem. I'm glad this was of help.
Juan Pablo Califano
this does mute the original header but it skews it. Here are a couple screen shots: http://tomfmason.net/container.jpg http://tomfmason.net/original.jpg
tomfmason
@tomfmason. Looks like the swf is being scaled. Make sure the widht and height of your container matches the header size (in FD you can change that form porject settings). Also check that in your embed code you're setting a scale param to "noscale". You can also do this in actionscript with `stage.scaleMode = StageScaleMode.NO_SCALE;`.
Juan Pablo Califano