Skip navigation
Electroclash
Currently Being Moderated

Press and hold button goto

May 26, 2012 3:33 PM

Tags: #flash #as3 #button #actionscript3 #on_hold #as2-to-as3

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:

 

stop();

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

 

Can someone help me to translate it to AS3 ?

Thank you !

 

 
Replies
  • Currently Being Moderated
    May 26, 2012 5:49 PM   in reply to Electroclash

    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);
         clearTimeout(sto);
         if(quickClick){
              trace("clicked quickly");
         } else {
              trace("delayed click");
         }
    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 27, 2012 4:14 AM   in reply to Electroclash

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points