3 Replies Latest reply on May 27, 2012 4:14 AM by Ned Murphy

    Press and hold button goto


      Hi ! I need help to update a script from AS2 to AS3.


      I'm simulating a function often found on a phone where you have a button and when you click on it something happens (in that case a gotoAndStop) but when you click and hold for a second that same button other thing happens (in that case another gotoAndStop).


      This is my original script doing exactly what I'm looking for:



      function startTimer(mc, conversionTime) {
      .onEnterFrame = function() {
      if ((getTimer() / 1000) - conversionTime > 1) {
      delete this.onEnterFrame;
      .onPress = function() {
      var conversionTime:Number = getTimer() / 1000;
      (this, conversionTime);
      this.onRelease = function() {
      if (this.onEnterFrame != null) {
      delete this.onEnterFrame;



      Can someone help me to translate it to AS3 ?

      Thank you !


        • 1. Re: Press and hold button goto
          Ned Murphy Adobe Community Professional & MVP

          Here's one approach to doing what you describe... I didn't deal with the goto statements, but you should be able to fill them in place of the traces...


          var quickClick:Boolean;
          var sto:uint;


          function changeClickStatus():void {
               quickClick = false;


          button1.addEventListener(MouseEvent.MOUSE_DOWN, btnPressed);


          function btnPressed(evt:MouseEvent):void {
               quickClick = true;
               button1.addEventListener(MouseEvent.CLICK, makeChoice);
               sto = setTimeout(changeClickStatus,1000);   // delay 1 second


          function makeChoice(evt:MouseEvent):void {
               button1.removeEventListener(MouseEvent.CLICK, makeChoice);
                    trace("clicked quickly");
               } else {
                    trace("delayed click");

          • 2. Re: Press and hold button goto
            Electroclash Level 1

            Hi Ned.


            Your code works perfectly. You are a master. Fast and precise answers. This community would not be the same without you.


            Many thanks !


            • 3. Re: Press and hold button goto
              Ned Murphy Adobe Community Professional & MVP

              You're welcome