Archive for the 'Flash/ActionScript' Category

Mute and unmute FLVPlayback in ActionScript 3

Thursday, February 12th, 2009

I've been working rather alot with ActionScript lately (both my main job, and also some side projects), learning ins and outs of ActionScript 3, which is great, but differs a great deal from ActionScript 2.. Still alot of ground to cover in order to get fluent with all the quirks (or, may be, features) of the language.

One problem I faced was that I had a need to mute and un-mute a video played inside the FLVPlayback container, programmatically from ActionScript 3.0.

I spent like may be half an hour searching for answers on google and in Flash debugger (man.. will they ever add variables watch there?..). Anyways, the solution to mute and unmute is pretty straightforward. You just have to send the FLVPLayback's mute button a mouse click event. No need to juggle with setting volume to zero and stuff like that..

I also keep the state of mute/unmute in a variable (it was faster to do it this way, rather than research one more topic ;). So here's how you mute (in case your FLVPlayback instance is called flvbox):

Define isMuted var somewhere in the code:

var isMuted:Boolean = false;

And now the real thing:

if (!isMuted) {
MovieClip(flvbox.muteButton).on_mc.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
isMuted = true;
}

and here's how you unmute:

if (isMuted) {
MovieClip(flvbox.muteButton).off_mc.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
isMuted = false;
}

That's it! I guess one can get status of a video being on mute or not, but I'll leave it to you :)

PS: You can have a look at this code in action (well.. sorta..) at one of our company's homepages (the middle-top video thingy): http://www.mj-dvd.jp (warning! Japanese content :)