AS3 如何让按钮切换功能?

发布于 2024-12-02 07:35:18 字数 472 浏览 0 评论 0原文

单击“button1”时,光标变为“movieclip” 我希望这个影片剪辑光标切换回常规光标 当再次点击button1时,切换该功能的打开和关闭。

我向您提出的问题是,这里是否可能使用某种布尔值来打开和关闭该功能,或者我是否走错了方向? 提前致谢!

button1.addEventListener(MouseEvent.CLICK,wipe);

function wipe(e:Event):void 
{

        Mouse.hide();
        stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
        function follow(evt:MouseEvent)
              {
              cursor.x = mouseX;
              cursor.y = mouseY;
              }
}

When button1 is clicked, the cursor changes into a 'movieclip'
I want this movieclip cursor to switch back into a regular cursor
when button1 is clicked again, so toggle the function on and off.

My question to you is, is it likely to use some kind of boolean here to toggle the function on and off or am I in the wrong direction?
Thanks in advance!

button1.addEventListener(MouseEvent.CLICK,wipe);

function wipe(e:Event):void 
{

        Mouse.hide();
        stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
        function follow(evt:MouseEvent)
              {
              cursor.x = mouseX;
              cursor.y = mouseY;
              }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-12-09 07:35:18

尝试

protected function wipe(e:Event):void {
    if (stage.hasEventListener(MouseEvent.MOUSE_MOVE, follow) {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
    } else {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
    }
}

将跟随的定义移出擦除。这还有效吗?

如果您需要直接在舞台上有其他 MOUSE_MOVE 侦听器,那么您可能想要使用更像以下的内容:

protected var isFollowing:Boolean;
protected function wipe(e:Event):void {
    if (isFollowing) {
       stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
   } else {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
   }
   isFollowing = !isFollowing;
}

注意:我假设您要将代码放入文档类中,因为我总是假设如果您如果您足够细心,可以在 Stack Overflow 等地方询问,那么您会希望采用良好的做法。

Try

protected function wipe(e:Event):void {
    if (stage.hasEventListener(MouseEvent.MOUSE_MOVE, follow) {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
    } else {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
    }
}

I'd move the definition of follow out of wipe. Does that even work?

If you need to have other listeners for MOUSE_MOVE directly on the stage then you might want to go with something more like:

protected var isFollowing:Boolean;
protected function wipe(e:Event):void {
    if (isFollowing) {
       stage.removeEventListener(MouseEvent.MOUSE_MOVE, follow);
   } else {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
   }
   isFollowing = !isFollowing;
}

Note: I've assumed you're going to put your code into a document Class, since I always assume that if you care enough to ask on a place like Stack Overflow, you'd like to use good practice.

神也荒唐 2024-12-09 07:35:18
var isMC:Boolean=false;


button1.addEventListener(MouseEvent.CLICK,wipe);
cursor.visible=false;
function wipe(e:Event):void 
{
if(isMC==false){
    cursor.visible=true;
    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
    function follow(evt:MouseEvent)
          {
          cursor.x = mouseX;
          cursor.y = mouseY;

          }
          isMC=true;}else{Mouse.show();
          cursor.visible=false;
          isMC=false

}}   

希望这有帮助。

var isMC:Boolean=false;


button1.addEventListener(MouseEvent.CLICK,wipe);
cursor.visible=false;
function wipe(e:Event):void 
{
if(isMC==false){
    cursor.visible=true;
    Mouse.hide();
    stage.addEventListener(MouseEvent.MOUSE_MOVE,follow);
    function follow(evt:MouseEvent)
          {
          cursor.x = mouseX;
          cursor.y = mouseY;

          }
          isMC=true;}else{Mouse.show();
          cursor.visible=false;
          isMC=false

}}   

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文