2010-11-06 59 views
2

我有一个脚本,一旦点击(按钮)一些其他的东西隐藏然后一旦再次点击它重新显示。问题是一旦隐藏它再也没有显示这里是脚本:Flash AS3切换可见

menu_start.addEventListener(MouseEvent.CLICK, myClickFunction); 


function myClickFunction(event:MouseEvent) { 

     // Hide the first and show the next here 
     if (menu_menu.visible == true){ 
     menu_menu.visible = false; 

     } 
     if (menu_menu.visible == false) { 
      menu_menu.visible == true; 
     } 

} 

非常感谢。

+0

还有什么事发生在menu_menu的DisplayObject单击该按钮时? – Jordan 2010-11-07 01:05:33

回答

4

的原因是,当你点击 按钮,它不隐藏,而是再次当 你点击相同的按钮它 没有显示回

如果我在上述说法中错了,请纠正我。

现在尝试一下我说的话,有两个按钮隐藏和显示。创建两个新函数并尝试一下,如果这有效,那么你的逻辑中缺少一些东西,如果这不起作用,那就让我们知道。

也请试试这个。

function myClickFunction(event:MouseEvent) { 

     // Hide the first and show the next here 
     if (menu_menu.visible){ 
     menu_menu.visible = false; 

     } else { 
     menu_menu.visible = true; 
     } 

} 

另一个问题可能是,当你点击按钮可能是它没有得到menu_menu属性再次作为其隐藏或销毁。它是在同一个组件中还是从其他地方调用?

+0

“menu_menu.visible == true;”应该是“menu_menu.visible = true;”因为值“真”需要分配没有测试。 – Jordan 2010-11-07 01:07:46

+0

纠正错字,谢谢 – Thalaivar 2010-11-07 16:23:41

2

在您的第二个“if”语句中,您没有将.visible设置为true,而是检查两个等号是否等于true。

function myClickFunction(event:MouseEvent) { 

    // Hide the first and show the next here 
    if (menu_menu.visible == true){ 
    menu_menu.visible = false; 

    } 
    if (menu_menu.visible == false) { 
     menu_menu.visible = true; 
    } 

}

+0

现在当我这样做,它甚至不会隐藏 – DonJuma 2010-11-06 17:43:50

+2

你是最后一个if语句之前缺少一个else,这就是为什么它不再隐藏。 – Allan 2010-11-07 03:34:26

9

我更喜欢在短形式编写这样的逻辑:

menu_menu.visible = !menu_menu.visible; 
+2

+1这是接受的答案。 – Allan 2010-11-07 03:37:55

0

尝试使用阿尔法= 0.1而不是可见=假和α= 1,而不是可见=真。

问题是,当您使用visible = false时,它也会禁用鼠标交互,所以您的第二次单击不会触发。

1

继承人基于Glens的建议,我提出了更好的版本,可以随意使用。

Buttonname.addEventListener (MouseEvent.CLICK, FunctionName); 
function FunctionName(event:MouseEvent) { 

    if (name1.alpha == 1){ 
    name1.alpha = 0;} else {name1.alpha = 1} 
} 

什么这个脚本要说的是如果点击,然后它就会改变阿尔法值设置为0时NAME1(影片剪辑元件)具有阿尔法值等于1,否则将阿尔法值更改为1 。

这也将与“看得见的”职能的工作:

Buttonname.addEventListener (MouseEvent.CLICK, FunctionName); 
function FunctionName(event:MouseEvent) { 

    if (name1.visible == true){ 
    name1.visible = false;} else {name1.visible = true} 
}