简体   繁体   English

Flash AS3切换可见

[英]Flash AS3 toggle visible

i have a script that once clicked ( a button ) some other thing hides then once clicked again it re-shows. 我有一个脚本,一旦点击(按钮)一些其他东西隐藏然后再次点击它重新显示。 the problem is once hidden it never shows again here is the script: 问题是一旦隐藏它永远不再显示这里是脚本:

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;
      }

}

Thanks so much. 非常感谢。

我更喜欢用简短的形式写这样的逻辑:

menu_menu.visible = !menu_menu.visible;

The reason is when you click on the button, it does hide but again when you click on the same button it does not show back 原因是当你点击按钮时,它会隐藏但是当你点击同一个按钮时它不再显示

Correct me if i am wrong in the above statement. 如果我在上述陈述中错了,请纠正我。

Now try something on what i say, have two buttons Hide and Show. 现在尝试一下我说的话,有两个按钮隐藏和显示。 Create two new function and try it out, if this works then there is something you are missing in your logic, if this does not work then let us know. 创建两个新函数并尝试一下,如果这样有效,那么你的逻辑中就会缺少一些东西,如果这不起作用那么请告诉我们。

Also try this. 也试试这个。

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;
      }

}

The other issue could be, when you click on the button may be its not getting the menu_menu property again as its hidden or destroyed. 另一个问题可能是,当你点击按钮可能是它没有再次获取menu_menu属性作为其隐藏或销毁。 Is it inside the same component or called from somewhere else? 它是在同一个组件内还是从其他地方调用?

In your second "if" statement you are not assigning .visible to true but instead checking to see if it's equal to true because of the two equal signs. 在你的第二个“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;
  }

} }

Heres a better version based on Glens suggestion that I made, feel free to use. 这是一个更好的版本基于格伦斯的建议,我做了,随意使用。

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

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

What this script is saying is if name1 (a Movie Clip symbol) has an Alpha value equal to 1 when clicked then it will then change the Alpha value to 0, otherwise it will change the Alpha value to 1. 这个脚本所说的是,如果name1(一个Movie Clip符号)在点击时Alpha值等于1,那么它会将Alpha值更改为0,否则它会将Alpha值更改为1。

This will also work with the "visible" functions: 这也适用于“可见”功能:

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

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

Try using alpha = 0.1 instead of visible = false and alpha = 1 instead of visible = true. 尝试使用alpha = 0.1而不是visible = false和alpha = 1而不是visible = true。

The problem is that when you use visible = false it also disables mouse interaction so your second click never fires. 问题是,当您使用visible = false时,它还会禁用鼠标交互,因此您的第二次点击永远不会触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM