0

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);
4

1 回答 1

0

我假设您的代码位于时间轴的第一帧。

我不会深入探讨有关 as3 中的这种做法的问题,但使用文档类可能会更好。这样代码只初始化一次。我猜当你在场景之间切换时,你会不断重新初始化,所以你最终会将静音重置为假。

要检查是否发生这种情况,只需在trace("init")该脚本中添加一个,并查看您调用它的频率。您还可以在您的 toggleMuteBtn 函数中添加一个跟踪,以在更改之前查看静音变量是什么。

在旁注中,我很好奇您为什么要对父级进行类型转换,MovieClip(parent)尽管它不会引起任何问题,但不需要它,因为您可以使用parent

于 2010-03-12T07:13:58.990 回答