悬停时更改 MC 的 alpha
这看起来应该对我有用,但显然我做错了什么。我不知道到底是什么,这显然是一个新手在谷歌搜索中寻找答案的错误,所以我们将不胜感激。
this.addEventListener(MouseEvent.MOUSE_OVER,function() {
this.alpha=0
})
在MC中,我希望当鼠标悬停在它上面时它变得不可见。我之所以将此代码放入 MC 中而不是从中创建实例,是因为该 MC 将重复出现多次。经trace() 测试,侦听器确实工作。不管出于什么原因,阿尔法不这样做。感谢您的任何帮助。
This looks like it should work to me, but clearly I've done something wrong. I don't know what exactly and this is apparently to much of a novice mistake to find answers searching Google, so help would be appreciated.
this.addEventListener(MouseEvent.MOUSE_OVER,function() {
this.alpha=0
})
In an MC, I want it to become invisible when the mouse hovers over it. The reason I'm putting this code inside the MC and not making an instance out of it is because this MC will recur numerous times. The listener does work, as tested with trace(). For whatever reason, alpha doesn't. Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您按原样使用闭包(使用内联匿名函数)时,您会失去范围。
this
不是您将鼠标悬停在其上的对象。来解决这个问题,
您可以使用然后(更正的代码)
请注意,我还在您的侦听器中放置了一个 event:MouseEvent 参数,否则您会收到运行时错误(您还没有收到这些错误吗?)
When using closure as you are (using an anonymous function inline) you lose scope.
this
is not the object that you're hovering over.You can get around that using
and then (corrected code)
note that I also put an event:MouseEvent parameter in your listener because otherwise you'd get runtime errors (didn't you get those already?)