如何在Flash中点击另一个按钮后隐藏一个按钮?

发布于 2024-11-08 02:16:54 字数 195 浏览 4 评论 0原文

我正在使用 Actionscript 3 制作点击游戏。在第 1 帧上有两个按钮,按钮 1 和 2。在第 3 帧上有两个按钮,按钮 A 和 B。

我希望在单击第 1 帧上的按钮 1 后,第 3 帧上的按钮 A 将被隐藏,或者当我单击第 1 帧上的按钮 2,第 3 帧上的按钮 B 将被隐藏。当您单击隐藏的按钮时,它们不会执行任何操作。

提前致谢

I am using actionscript 3 to make a point and click game. On frame 1 there are two buttons, button 1 and 2. On frame 3 there are two buttons, button A and B.

I want it so that after I click button 1 on frame 1, button A on frame 3 will be hidden or when I click button 2 on frame 1, button B on frame 3 will be hidden. The buttons that are hidden do not do anything when you click them.

thanks in advance

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

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

发布评论

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

评论(2

看海 2024-11-15 02:16:54

如果您尝试删除不在显示列表中的内容,Flash 将抛出错误。我想这里最好的解决方案是设置一个时间线变量来跟踪您按下的按钮。像这样:

在第 1 帧上

var b1:Boolean = false;
var b2:Boolean = false;

button1.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
button2.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);

function checkButton(e:MouseEvent):void
{
   if(e.target.name == button1) b1 = true;
   else b2 = true;

   gotoAndPlay(3);
}

在第 3 帧上

myButtomA.visible = false;
myButtomB.visible = false;   

if (b1) myButtomA.visible = true;
if (b2) myButtomB.visible = true;

If you try to remove something that is not in the display list yet Flash will thrown an error. I guess the best solution here is setting up a timeline variable to keep track of which button you have pressed. Something like this:

on frame 1

var b1:Boolean = false;
var b2:Boolean = false;

button1.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
button2.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);

function checkButton(e:MouseEvent):void
{
   if(e.target.name == button1) b1 = true;
   else b2 = true;

   gotoAndPlay(3);
}

on frame 3

myButtomA.visible = false;
myButtomB.visible = false;   

if (b1) myButtomA.visible = true;
if (b2) myButtomB.visible = true;
梦言归人 2024-11-15 02:16:54

有多种方法可以从显示列表中删除对象,或以其他方式将其隐藏在视图中。例如:

button1.addEventListener(MouseEvent.MOUSE_DOWN, removeButton);

function removeButton(e:MouseEvent):void
{
 buttonContainer.removeChild(otherButton);
}

您还可以将目标按钮的“可见性”属性设置为 false。
非常非常简单,您应该能够根据需要修改此代码片段。

说到另一个话题。

我总是敦促人们不要在时间表上进行互动。它只是让事情变得混乱,特别是当您在 AS3 中拥有如此强大的面向对象工具时......

无论哪种方式 - 干杯,祝你好运。

  • 更新 - 回应OP的最后评论:

当然可以 - 尽管这是一个相当深刻的问题,具体取决于您的经验。主要的事情是参与 AS3 的面向对象功能,并仅通过代码驱动大部分应用程序。

项目看起来像这样:Fla 主要用作资产容器(如果您使用嵌入,则甚至不是),具有单个空时间线框架。然后,主文档类负责启动和构建项目的所有方面 - 从数据的加载和控制到显示列表对象的创建和添加,再到建立和控制用户交互。经典包/类设计用于创建可能的数十或数百个单独的 .AS 文件。时间线仍然用于创建复杂的动画,但很少涉及任何代码(在这里或那里保存一个 stop(); )。

当我刚刚学习这个时 - 我得到了一本好书,并经常在谷歌上搜索,以找出AS3 的要点,就从那里开始。做一些简单的项目,你就能看到你能有多深入,而且速度有多快。

这样工作的好处怎么强调都不为过。

如果您还有任何疑问,请告诉我。祝你好运!

There are many ways to remove an object from the display list, or otherwise hide it from view. For example:

button1.addEventListener(MouseEvent.MOUSE_DOWN, removeButton);

function removeButton(e:MouseEvent):void
{
 buttonContainer.removeChild(otherButton);
}

You could also set the target buttons "visibility" property to false.
Very very simple, and you should be able to modify this snippet as needed.

On another topic.

I always urge people away from developing interactions on the timeline. It just confuses things, especially when you have such potent object oriented tools available in AS3...

Either way - Cheers and good luck.

  • update - In response to the OPs last comment:

Sure thing - although its a fairly deep question, depending on your experience. The main thing is getting involved with AS3's Object Oriented features, and driving the majority of your application via code alone.

Projects look like this: the Fla functions mostly as a container for assets (and if you utilize embeds, not even that), with a single, empty timeline frame. The main document class is then responsible for initiating and constructing all aspects of the project - everything from the load and control of data to the creation and addition of display list objects to establishing and controlling user interactions. Classic Package / Class design is used to create, potentially, dozens or hundreds of individual .AS files. The timeline is still used to create complex animations, but rarely involve any code (save a stop(); here or there).

When I was just learning this - I got a good book, and hit the googles a lot, to figure out the essentials of AS3, and just kind of went from there. Make a few simple projects, and you can see how indepth you can get, and quickly.

The benefit from working like this can not be overstated.

Let me know if you have any further questions. Good luck!

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