• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Press and hold button goto

May 26, 2012 May 26, 2012

Copy link to clipboard

Copied

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 !

TOPICS
ActionScript

Views

2.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 26, 2012 May 26, 2012

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
}

f

...

Votes

Translate

Translate
LEGEND ,
May 26, 2012 May 26, 2012

Copy link to clipboard

Copied

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");
     }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
May 26, 2012 May 26, 2012

Copy link to clipboard

Copied

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 !

William

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2012 May 27, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines