【问题标题】:AS3: Two actions on one Click event listenerAS3:一个 Click 事件侦听器上的两个操作
【发布时间】:2014-08-28 08:27:13
【问题描述】:

所以我想做的是让一个菜单在点击时弹出。现在我只想用一个。所以在第一次点击时我需要它移动到 x 130。然后在下一次点击移动到 x -77。我该怎么做?我尝试了一个 if 语句,但对我来说效果不佳。

function clickMove (e:MouseEvent):void{
    smenu_mc.x = 130;
    if(smenu_mc.x == 130){
        smenu_mc.x = -77;
    }
}

【问题讨论】:

  • 发布您的代码。编辑:相关部分。
  • 您使用 if 语句来确定菜单当前是否存在。显示你正在使用的代码,使菜单进入
  • @Fygo 有 if 语句希望有帮助
  • @LDMediaServices 刚刚用我使用的 if 语句更新了它
  • LDMediaServices 已回答您。但只是一个细节:您不能将某些内容设置为 130,然后检查它是否在 130 上并设置其他内容。当然会的。 :)

标签: actionscript-3 function event-handling


【解决方案1】:

您当前所做的总是将其设置为 -77。因为您的 if 语句将始终为真:(请参阅代码旁边的 cmets)

function clickMove (e:MouseEvent):void{
    smenu_mc.x = 130; //you're setting it to 130
    if(smenu_mc.x == 130){ //this will be true, because of the line above...
        smenu_mc.x = -77;
    }
}

你需要做的是切换值:

function clickMove (e:MouseEvent):void{
    if(smenu_mc.x < 130){ //if it's less than 130, then set it to 130, otherwise set it to -77.
        smenu_mc.x = 130;
    }else{
        smenu_mc.x = -77;
    }
}

【讨论】:

  • 出来了却回不去了
  • 是的,您的代码刚出来,但不会在第二次点击时返回。刚刚看到您的新帖子正在试用
  • 您是否在其他地方设置了x 值?这很简单,因此必须有其他一些影响才能使其不起作用。
  • 不,它有效,很抱歉在这一切无效之前您还有其他事情。但是您发布的内容确实如此。感谢您的帮助
  • 哦,好吧,我一开始将它作为内联 if 语句,但更改了它 - 我之前没有校对它,所以我可能只是不小心切换了数字。
猜你喜欢
  • 1970-01-01
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多