Mute and unmute FLVPlayback in ActionScript 3
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 :)
April 7th, 2009 at 4:12 am
I found that simulating the more of the mouse click event cycle helped fix a bug I was having. So do this on each button:
on_mc.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN));
on_mc.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
on_mc.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
Sorry I can't recall what the bug was now, but I just stumbled across your post when I was looking for something else.
August 14th, 2010 at 3:19 pm
посмотрел интервью на сайте - понял только пару-тройку слов, которые встречались в анимешках =)
а почему все в рубашках, хотя вроде бы такая расслабленная обстановка и все смеются? :)