4 Replies Latest reply on Mar 2, 2007 11:01 PM by IwannaFlashU

    simulate button click

    IwannaFlashU
      Hi,

      I'm making a game that pits the user against two other computer players (think jeopardy). I had made this game years ago in other software, and when I first made it in flash, I made it a "single player" version....now I want my bot players in there!

      Anyhow, I already have the code in the buttons (that represent category and question value) to do what needs to be done and I need to write code to CALL the button's onRelease function.

      Can this be done? If so, how.......I played with the CALL command and can't get it to work.

      If this can't be done, I know I can fall back on making the code inside of the buttons, regular functions and having the buttons' onRelease function call those, as well as my bot players' code that I'm working on now.

      But I've always wanted to be able to do this in other applications and will in future ones, so can someone help me out here? It IS a function (mybutton.onRelease();) so you SHOULD be able to call it just like any other established function. right?

      thanks
        • 1. Re: simulate button click
          crazyjoemilan Level 2
          function ButtonOneFunction() {
          //whatever you would put on your button
          }

          button1.onRelease = function() {
          ButtonOneFunction();
          }

          The first would just be your defined function to do your bidding. (which you could then call anytime you want as your bot player.

          The second assigns that function to that button.
          • 2. Re: simulate button click
            IwannaFlashU Level 1
            Yeah, I know how to write a function and also know I can then call that function from a button click............What I'm asking is, is there a way you can call the built in functions of a button?

            ie, using your example, how can i call button1.onRelease? this function is called when the user clicks on that button..........but I want my CODE to call that same function.

            I'm guessing the answer is no, which is stupid because these are functions and you should be able to call them.
            • 3. simulate button click
              willrose Level 1
              If I remember correctly you can do this:

              btn1.onRelease = function():Void
              {
              //function here
              }

              //invoke the event
              btn1.onRelease();


              Storing your reusable code in a function however, as described above, is probably better practice.
              • 4. Re: simulate button click
                IwannaFlashU Level 1
                ah.......so if you write the code for the onRelease in an AS keyframe, as opposed to putting the code directly on / in the button, THEN you can call it.

                I tried your way and it works .......... for some reason, it doesn't work when you put it directly on the button tho, which is what I'm used to doing.

                kewl. thanks!