在动作脚本3.0中单击两个不同的按钮后,如何显示符号? [英] How can I make a symbol appear after clicking in two different buttons in actionscript 3.0?

查看:76
本文介绍了在动作脚本3.0中单击两个不同的按钮后,如何显示符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此编程知识中有些新手,需要帮助才能在ActionScript 3.0(Adobe Animate CC)中进行编程.我想使一个符号(图形)可见,但仅在单击两个不同的按钮(button1和button 2)之后才可见.我可以只用一个按钮就能做到,但我不能用两个按钮来做到……有人可以帮助我吗?我尝试了这段代码,但是它没有正常工作:

I am a little bit new in this programming stuff and I need help to program in ActionScript 3.0 (Adobe Animate CC). I want to make a symbol (graph) visible but only after clicking in two different buttons (button1 and button 2). I can make that with just one button, but I can't make it with two buttons... Can anyone help me? I tried this code but it isn't working as it should:

button1.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
button2.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);

function fl_MouseClickHandler_1(event:MouseEvent):void
{
    graph.visible = true;
}

汤姆

推荐答案

最简单的方法是这样做,尽管可能还有其他方法:

Simplest way would be to do this, although there may be other ways to do it as well:

var isButton1Clicked:Boolean = false;
var isButton2Clicked:Boolean = false;

button1.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);
button2.addEventListener (MouseEvent.CLICK, fl_MouseClickHandler_1);


function fl_MouseClickHandler_1(event:MouseEvent):void
{
    if (event.currentTarget == button2)
        isButton2Clicked = true; 
    else if (event.currentTarget == button1)
        isButton1Clicked = true;
    if (isButton1Clicked && isButton2Clicked)
    {
        graph.visible = true;
        isButton1Clicked = isButton2Clicked = false;                    
    }
}

请注意,一旦图形可见,我会将两个布尔值都重置为false,以使其像重置一样工作.

Note that I reset both the Boolean values to false, once the graph is visible so that it works like a reset.

另一方面,我建议对按钮和事件处理程序使用更好的名称.只是最佳实践.

On a side note, I would recommend to use better names for your buttons and your event handlers. Just best practice.

希望这会有所帮助.干杯.

Hope this helps. Cheers.

这篇关于在动作脚本3.0中单击两个不同的按钮后,如何显示符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆