as3中tileList单元格响应鼠标事件
我正在制作一个 Flash 游戏(基本上是同一个游戏的一个版本),并且我使用了一个 tileList
作为填充有 movieClip
片段的棋盘。我希望这些片段能够响应 mouseOver
、mouseOut
和 mouseClick
事件。
通过查看其他问题/答案,我了解到我需要一个自定义 imageCell
。这是要走的路吗?我希望通过将操作放入 movieClips
本身中来获得我想要的响应,如下所示,但这似乎不起作用。 (顺便说一句,我是这个社区的新手,但通过谷歌搜索多次来到这里……感谢你们的帮助,我已经从你们这些出色的人那里得到了帮助。干杯。)
this.addEventListener(MouseEvent.MOUSE_OVER, OverHandler);
this.addEventListener(MouseEvent.MOUSE_OUT, OutHandler);
this.addEventListener(MouseEvent.CLICK, ClickHandler);
this.stop();
function OverHandler(event:MouseEvent):void
{
event.target.play();
}
function OutHandler(event:MouseEvent):void
{
event.target.stop();
}
function ClickHandler(event:MouseEvent):void
{
event.target.play();
}
I’m making a Flash game (which is basically a version of the same game), and I’ve used a tileList
for the board populated with movieClip
pieces. I would like the pieces to respond to mouseOver
, mouseOut
, and mouseClick
events.
From looking at other question/answers, I get the idea I’ll need a custom imageCell
. Is that the way to go. I was hoping I could get the responses I want by putting the actions into the movieClips
themselves as below, but that doesn’t seem to work.
(btw I’m new to the community but have wound up here several times from Google searches … Thanks for help I’ve received already from you wonderful folks. Cheers.)
this.addEventListener(MouseEvent.MOUSE_OVER, OverHandler);
this.addEventListener(MouseEvent.MOUSE_OUT, OutHandler);
this.addEventListener(MouseEvent.CLICK, ClickHandler);
this.stop();
function OverHandler(event:MouseEvent):void
{
event.target.play();
}
function OutHandler(event:MouseEvent):void
{
event.target.stop();
}
function ClickHandler(event:MouseEvent):void
{
event.target.play();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会为游戏中所有已准备好事件的部件设置一个基类。就像这样:
如果您需要单击、roll_over 或 roll_out 对某些部件执行任何独特的操作,只需扩展并执行此操作:
I'd probably set up a base class for all of your pieces in the game that have the events there and ready.. Like so:
If you need click, roll_over or roll_out to do anything unique on certain pieces, just extend and do this: