views:

417

answers:

1

Hey guys,

I am trying to create a UI movie clip that can be used across different scenes. It uses variables from the root scope to determine states.

When i press the mute button is works fine, however when i try to un-mute things go weird. Sometimes it takes 2 clicks to unmute, sometimes more. It seems random. Muting however seems to work first time..

Any ideas?


Main Timeline:

var mute:Boolean = false; var playerName = "Fred";

function setMute(vol) { var sTransform:SoundTransform = new SoundTransform(1,0); sTransform.volume = vol; SoundMixer.soundTransform = sTransform; }

function toggleMuteBtn(event:Event) { if (mute) { // Sound On, Mute Off mute = false; setMute(1); ui_mc.muteCross_mc.visible = false; } else { // Sound Off, Mute On mute = true; setMute(0); ui_mc.muteCross_mc.visible = true; } }


ui_mc Action Script:

if (MovieClip(parent).mute == false) { muteCross_mc.visible = false; }

mute_btn.addEventListener(MouseEvent.CLICK, MovieClip(parent).toggleMuteBtn);

A: 

I'm assuming that your code is on the first frame of your timeline.

I won't go into depth with the issues regarding that practice in as3, but you might be better off using a document class. That way the code is initialized only once. I'm guessing when you're switching between the scenes, you keep re-initializing, so you end up resetting mute to false.

To check if this is happening, just add a trace("init") to that script, and see how often you call that., you can also add a trace to your toggleMuteBtn function to see what the mute variable is before you change it.

on a side note, I'm curious why you're typecasting the parentMovieClip(parent) though it won't cause any problems, there is no need for it as you could just use parent

Daniel
document class howto:http://www.youtube.com/watch?v=V01yZnRANLQ
Daniel