0
votes

I have a button which I want to use to mute audio, which will change to a un-mute icon when it is clicked, and toggle back and forth.

The thing is, its still visible in the stage after my code. The weirdest bit is that if I trace the visibility after I call the function, it actually says that its hidden: but its clearly visible on the stage.

play_pause.addEventListener(MouseEvent.CLICK, change_sound);

function change_sound (e:MouseEvent):void{
        fl_NS.soundTransform = muteAudio;
        e.target.visible = false;
        trace(play_pause.visible);
        muted = true;
}

Here are some other things I've tried which didn't work:

play_pause.addEventListener(MouseEvent.CLICK, change_sound);

function change_sound (e:MouseEvent):void{
        fl_NS.soundTransform = muteAudio;
        play_pause.visible = false;
        trace(play_pause.visible);
        muted = true;
}

Another version:

play_pause.addEventListener(MouseEvent.CLICK, change_sound);

function change_sound (e:MouseEvent):void{
        fl_NS.soundTransform = muteAudio;
        play_pause.gotoAndPlay(2);
        muted = true;
}

No visual change again. Just to state some key points:

  • my movieclip is definitely called play_pause
  • it traces that it is visible before the click, and invisible after the click (the trace statement comes back false) but there is no visual change
  • the function definitely fires

I haven't used AS3 for a while, I'm guessing I'm making a really noob mistake? Full code: http://pastebin.com/RirGdS1w

Link to .fla file: http://db.tt/51DD0Fbl

2
try play_pause.gotoAndPlay(2); to 'play_pause.gotoAndStop (2);' it works like a timeline, if u ask it to play it will skip to the next frame until it's told to stop.tailedmouse
Thanks for taking the time to lookDjave

2 Answers

0
votes

Perhaps someone else could fully explain this, but I found that once the SWF was embedded into an HTML page it worked as expected. It was when it was being run in Flash CS5.5 that it wasn't working. This will now be a nightmare to debug but for the purposes of the project tonight I have it working.

0
votes

Try e.currentTarget inside the listener function

target is the deepest element, like a moviclip inside another movieclip

currentTarget is the one associated with the addEventListener method