A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Two buttons pressed

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    19

    Two buttons pressed

    I'm having trouble with an on Press action, what I'm trying to work out is to click on two buttons in a specific order to activate a script.
    sw1 and sw2 is the buttons instance names.


    if ((press) == sw1 &&(press) == sw2){

    }

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Does it need to be in order or maybe just both together ish?
    Attach your *.fla, lets look

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    This might help you along, make a new AS2 document, paste this and test it.
    PHP Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function()
    {
        if (
    Key.isDown(Key.UP) && Key.isDown(Key.DOWN))
        {
            
    trace("Bingo");
        }
    };
    Key.addListener(keyListener); 

  4. #4
    Junior Member
    Join Date
    Jul 2013
    Posts
    19
    Thank you for your help but by buttons I mean the picture ones on the stage that have instance names, not the keyboard. Sorry about not explaining it better before.
    on (press) {
    }
    The stage buttons to be both hit in order to activate script.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,
    well attach your *.fla so I dont need to make my own file

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is roughly put together effort, 3 buttons on stage, named btn1, btn2, btn3, code placed on timeline, not on the buttons

    PHP Code:
    var code:String "";

    btn1.onPress = function()
    {
        
    code += "1";
        
    test();
    };

    btn2.onPress = function()
    {
        
    code += "2";
        
    test();
    };

    btn3.onPress = function()
    {
        
    code += "3";
        
    test();
    };

    function 
    test()
    {
        
    trace(code);
        if (
    code == "123")
        {
            
    trace("Bingo");
            
    code "";
        }
        if (
    code.length 3)
        {
            
    code "";
        }


  7. #7
    Junior Member
    Join Date
    Jul 2013
    Posts
    19
    Wow thanks so much! I appreciate it!
    I was about to post my file after cutting down the size but this works just the way I needed it to, thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center