如何用一个按钮制作可见的无限动画片段?

时间:2023-01-12 22:15:25

I'm working on an interactive map in Actionscript-3 (Adobe Flash CS6).

我正在使用Actionscript-3(Adobe Flash CS6)中的交互式地图。

What I'm trying to do is, with a single button, to show multiple objects (movieclips) with each mouse click.

我想要做的是,只需一个按钮,每次点击鼠标即可显示多个对象(动画片段)。

I'm currently working with this code, but I can't manage to find out how to show multiple movieclips, I can only show ONE:

我目前正在使用此代码,但我无法找到如何显示多个动画片段,我只能显示一个:

btn_ally_unit.addEventListener(MouseEvent.CLICK, mostrar_ally_unit2);

function mostrar_ally_unit2(event:MouseEvent):void
{
    map_editor.ally_unit.visible = true;

}   

How do I extend this to apply to any number of movieclips?

如何将其扩展为适用于任意数量的动画片段?

1 个解决方案

#1


0  

I'm sure by infinite you mean indefinite.

我肯定无限的你意味着无限期。

Target the unit clicked by using the target property of the Event class. Looks something like this:

使用Event类的target属性定位单击的单元。看起来像这样:

btn_ally_unit.addEventListener(MouseEvent.CLICK, mostrar_ally_unit2);

function mostrar_ally_unit2(event:MouseEvent):void
{
    event.target.visible = true;

}   

You see? (event:MouseEvent) is saying that this function expects one argument (a MouseEvent) which you are giving the variable name of event. That's a convention but I like to use me as an abbreviation for mouse event. Others just use the letter e. Ok. Now event has a property, target, which is the thing receiving the event. In this case it will be one of your units. Your units have a property of visible which you can toggle off like you have been doing but by using the relative mouse event target, you can use the same line of code for all units.

你看? (event:MouseEvent)说这个函数需要一个参数(一个MouseEvent),你给它提供事件的变量名。这是一个惯例,但我喜欢用我作为鼠标事件的缩写。其他人只使用字母e。好。现在事件有一个属性target,这是接收事件的东西。在这种情况下,它将是您的单位之一。您的单位具有可见的属性,您可以像往常一样切换,但通过使用相对鼠标事件目标,您可以对所有单位使用相同的代码行。

note

Of course you must add the event listener to each unit. You could make it part of the class or just add it when a new unit is instantiated.

当然,您必须将事件侦听器添加到每个单元。您可以将其作为类的一部分,或者在实例化新单元时添加它。

note

Using the event flow in actionscript 3 can be tricky. Seek out a tutorial on this. Here is one link related to event flow from Adobe.

在actionscript 3中使用事件流可能很棘手。寻找关于此的教程。以下是与Adobe事件流相关的一个链接。

#1


0  

I'm sure by infinite you mean indefinite.

我肯定无限的你意味着无限期。

Target the unit clicked by using the target property of the Event class. Looks something like this:

使用Event类的target属性定位单击的单元。看起来像这样:

btn_ally_unit.addEventListener(MouseEvent.CLICK, mostrar_ally_unit2);

function mostrar_ally_unit2(event:MouseEvent):void
{
    event.target.visible = true;

}   

You see? (event:MouseEvent) is saying that this function expects one argument (a MouseEvent) which you are giving the variable name of event. That's a convention but I like to use me as an abbreviation for mouse event. Others just use the letter e. Ok. Now event has a property, target, which is the thing receiving the event. In this case it will be one of your units. Your units have a property of visible which you can toggle off like you have been doing but by using the relative mouse event target, you can use the same line of code for all units.

你看? (event:MouseEvent)说这个函数需要一个参数(一个MouseEvent),你给它提供事件的变量名。这是一个惯例,但我喜欢用我作为鼠标事件的缩写。其他人只使用字母e。好。现在事件有一个属性target,这是接收事件的东西。在这种情况下,它将是您的单位之一。您的单位具有可见的属性,您可以像往常一样切换,但通过使用相对鼠标事件目标,您可以对所有单位使用相同的代码行。

note

Of course you must add the event listener to each unit. You could make it part of the class or just add it when a new unit is instantiated.

当然,您必须将事件侦听器添加到每个单元。您可以将其作为类的一部分,或者在实例化新单元时添加它。

note

Using the event flow in actionscript 3 can be tricky. Seek out a tutorial on this. Here is one link related to event flow from Adobe.

在actionscript 3中使用事件流可能很棘手。寻找关于此的教程。以下是与Adobe事件流相关的一个链接。