热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在AS3中最容易实现onReleaseOutside?-EasiestimplementationofonReleaseOutsideinAS3?

Imalong-timeActionScript2user,nowgettingstartedwithActionScript3.TheonethingImmiss

I'm a long-time ActionScript 2 user, now getting started with ActionScript 3. The one thing I'm missing is an easy way to duplicate the functionality of AS2's MovieClip.onReleaseOutside. It is almost always necessary to implement this event, otherwise you get funny bugs like flash thinks your mouse is down when really it's up.

我是一个长期的ActionScript 2用户,现在开始使用ActionScript 3.我缺少的一件事是复制AS2的MovieClip.onReleaseOutside功能的简单方法。几乎总是有必要实现这个事件,否则你会得到一些有趣的错误,比如flash认为你的鼠标已经关闭了。

According to the AS2 to AS3 Migration Guide, I'm supposed to use flash.display.InteractiveObject.setCapture() for this, however it does not exist as far as I can tell. I guess this document is out of date or incorrect. I've found a few posts on the web about how to duplicate this functionality, but they either have their own problems:

根据AS2到AS3迁移指南,我应该为此使用flash.display.InteractiveObject.setCapture(),但据我所知,它不存在。我猜这个文件已经过时或不正确。我在网上发现了一些关于如何复制这个功能的帖子,但是他们有自己的问题:

  • This one triggers onReleaseOutside even if there was no corresponding onPress event.
  • 即使没有相应的onPress事件,也会触发onReleaseOutside。

  • This one seems very inefficient, you'll add and remove an event listener every time the mouse is clicked anywhere inside your app.
  • 这个效率似乎非常低效,每次在应用程序内的任何位置单击鼠标时,您都会添加和删除事件侦听器。

There has to be an easier way, don't tell me Adobe forgot about this when rewriting Actionscript?

必须有一个更简单的方法,不要告诉我Adobe在重写ActionScript时忘了这个吗?

Example AS2 code:

示例AS2代码:

// Assume myMC is a simple square or something on the stage

myMC.OnPress= function() {
  this._rotation = 45;
}

myMC.OnRelease= myMC.OnReleaseOutside= function() {
  this._rotation = 0;
}

Without the onReleaseOutside handler, if you pressed down on the squre, dragged your mouse outside of it, and released the mouse, then the square would not un-rotate, and appear to be stuck.

没有onReleaseOutside处理程序,如果你按下squre,将鼠标拖到它外面,然后松开鼠标,那么方块就不会旋转,并且看起来卡住了。

3 个解决方案

#1


10  

Simple and foolproof:

简单而万无一失:

button.addEventListener( MouseEvent.MOUSE_DOWN, mouseDownHandler );
button.addEventListener( MouseEvent.MOUSE_UP, buttonMouseUpHandler ); // *

function mouseDownHandler( event : MouseEvent ) : void {
    trace( "onPress" );
    // this will catch the event anywhere
    event.target.stage.addEventListener( MouseEvent.MOUSE_UP, mouseUpHandler );
}

function buttonMouseUpHandler( event : MouseEvent ) : void {
    trace( "onRelease" );
    // don't bubble up, which would trigger the mouse up on the stage
    event.stopImmediatePropagation( );
}

function mouseUpHandler( event : MouseEvent ) : void {
    trace( "onReleaseOutside" );
    event.target.removeEventListener( MouseEvent.MOUSE_UP, mouseUpHandler );
}

If you don't care about the difference between onRelease and onReleaseOutside (for example with draggable items) you an skip the mouse up listener on the button itself (commented here with an asterisk).

如果您不关心onRelease和onReleaseOutside之间的区别(例如,使用可拖动的项目),您可以跳过按钮本身的鼠标向上监听器(此处用星号表示)。

#2


3  

root.addEventListener(MouseEvent.UP, onMouseReleaseOutside);

You define onMouseReleaseOutside of course. Basically any MouseEvent.UP (a mouse release) that happens outside of your button (or mc) will hit the stage instead of your button. This is the way i usually catch it.

你定义onMouseReleaseOutside当然。基本上任何在按钮(或mc)之外发生的MouseEvent.UP(鼠标释放)都会触发舞台而不是按钮。这是我通常捕捉它的方式。

#3


3  

Have you looked at this event:

你看过这个事件了吗:

flash.events.Event.MOUSE_LEAVE



From the documentation:

从文档:

Dispatched by the Stage object when the mouse pointer moves out of the stage area. The Event.MOUSE_LEAVE constant defines the value of the type property of a mouseLeave event object.

当鼠标指针移出舞台区域时由Stage对象调度。 Event.MOUSE_LEAVE常量定义mouseLeave事件对象的type属性的值。

It will solve your problem if you are only interested whether the user's mouse if off the stage instead of just outside that particular MovieClip.

如果您只关心用户的鼠标是否离开舞台而不是仅仅在特定的MovieClip之外,它将解决您的问题。


推荐阅读
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • 解决Cydia数据库错误:could not open file /var/lib/dpkg/status 的方法
    本文介绍了解决iOS系统中Cydia数据库错误的方法。通过使用苹果电脑上的Impactor工具和NewTerm软件,以及ifunbox工具和终端命令,可以解决该问题。具体步骤包括下载所需工具、连接手机到电脑、安装NewTerm、下载ifunbox并注册Dropbox账号、下载并解压lib.zip文件、将lib文件夹拖入Books文件夹中,并将lib文件夹拷贝到/var/目录下。以上方法适用于已经越狱且出现Cydia数据库错误的iPhone手机。 ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • JavaScript和HTML之间的交互是经由过程事宜完成的。事宜:文档或浏览器窗口中发作的一些特定的交互霎时。能够运用侦听器(或处置惩罚递次来预订事宜),以便事宜发作时实行相应的 ... [详细]
  • 单页面应用 VS 多页面应用的区别和适用场景
    本文主要介绍了单页面应用(SPA)和多页面应用(MPA)的区别和适用场景。单页面应用只有一个主页面,所有内容都包含在主页面中,页面切换快但需要做相关的调优;多页面应用有多个独立的页面,每个页面都要加载相关资源,页面切换慢但适用于对SEO要求较高的应用。文章还提到了两者在资源加载、过渡动画、路由模式和数据传递方面的差异。 ... [详细]
  • 我用Tkinter制作了一个图形用户界面,有两个主按钮:“开始”和“停止”。请您就如何使用“停止”按钮终止“开始”按钮为以下代码调用的已运行功能提供建议 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 有没有一种方法可以在不继承UIAlertController的子类或不涉及UIAlertActions的情况下 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
author-avatar
端庄的张佳迎
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有