Skip to main content
Known Participant
October 27, 2010
Answered

AS2 Timer needs to pause

  • October 27, 2010
  • 1 reply
  • 2282 views

Good morning everyone,

I'm making a bannerslider that's going every 7 seconds to the next Movieclip/Image.

But i made a play and pause button in it so that the timer would pause.

But my problem is that the Timer doesn't pause. And I can't see the problem !

Maybe can somebody put me in the rigth direction?

My AS is as follows:

slides = 5; //<------- Hoeveel afbeeldingen er staan
wait = 7; // <------- Aantal seconde per afbeelding
playclip._visible = false;

contentHold.content1.button.onPress = function() {
getURL("
www.visualbrand.nl/kijken.html", "_self");
};
contentHold.content2.button.onPress = function() {
getURL("
http://www.bestsellers.nl/catalog/category/view/id/249", "_self");
};
contentHold.content3.button.onPress = function() {
getURL("
http://www.bestsellers.nl/music/8718036994508.html", "_self");
};
contentHold.content4.button.onPress = function() {
getURL("
http://http://www.bestsellers.nl/5099990631825.html", "_self");
};
contentHold.content5.button.onPress = function() {
getURL("
http://www.bestsellers.nl/catalog/category/view/id/270", "_self");
};
contentHold.content6.button.onPress = function() {
getURL("
http://www.visualbrand.nl", "_self");
};
var currentPosition = contentHold.content1._x;
var startFlag = false;
menuSlide = function (input) {
if (startFlag == false) {
  startFlag = true;
  var _loc1 = input._x;
  var distanceMoved = 0;
  var distanceToMove = Math.abs(_loc1-currentPosition);
  var finalSpeed = 3.000000E-001;
  var currentSpeed = 0;
  var dir = 1;
//----------> SLIDE VAN LINKS/RECHTS NAAR RECHTS/LINKS <-----------
  if (currentPosition<=_loc1) {
   dir = -1;
  } else if (currentPosition>_loc1) {
   dir = 1;
  }
  // end else if
  contentHold.onEnterFrame = function() {
   currentSpeed = Math.round((distanceToMove-distanceMoved+1)*finalSpeed);
   distanceMoved = distanceMoved+currentSpeed;
   contentHold._x = contentHold._x+dir*currentSpeed;
   if (Math.abs(distanceMoved-distanceToMove)<=1) {
    contentHold._x = maskMovie._x-currentPosition+dir*distanceToMove;
    currentPosition = input._x;
    startFlag = false;
    delete contentHold.onEnterFrame;
   }
   // end if
  };
}
// end if
};
bAll.mov1.b1.onRelease = function() {
menuSlide(contentHold.content1);
bAll.mov1.gotoAndPlay(1);
bAll.mov2.gotoAndPlay(1);
bAll.mov3.gotoAndPlay(1);
bAll.mov4.gotoAndPlay(1);
bAll.mov5.gotoAndPlay(1);
bAll.mov6.gotoAndPlay(1);
bAll.mov7.gotoAndPlay(1);
};
bAll.mov2.b2.onRelease = function() {
menuSlide(contentHold.content2);
bAll.mov1.gotoAndPlay(175);
bAll.mov2.gotoAndPlay(175);
bAll.mov3.gotoAndPlay(175);
bAll.mov4.gotoAndPlay(175);
bAll.mov5.gotoAndPlay(175);
bAll.mov6.gotoAndPlay(175);
bAll.mov7.gotoAndPlay(175);
};
bAll.mov3.b3.onRelease = function() {
menuSlide(contentHold.content3);
bAll.mov1.gotoAndPlay(350);
bAll.mov2.gotoAndPlay(350);
bAll.mov3.gotoAndPlay(350);
bAll.mov4.gotoAndPlay(350);
bAll.mov5.gotoAndPlay(350);
bAll.mov6.gotoAndPlay(350);
bAll.mov7.gotoAndPlay(350);
};
bAll.mov4.b4.onRelease = function() {
menuSlide(contentHold.content4);
bAll.mov1.gotoAndPlay(525);
bAll.mov2.gotoAndPlay(525);
bAll.mov3.gotoAndPlay(525);
bAll.mov4.gotoAndPlay(525);
bAll.mov5.gotoAndPlay(525);
bAll.mov6.gotoAndPlay(525);
bAll.mov7.gotoAndPlay(525);
};
bAll.mov5.b5.onRelease = function() {
menuSlide(contentHold.content5);
bAll.mov1.gotoAndPlay(700);
bAll.mov2.gotoAndPlay(700);
bAll.mov3.gotoAndPlay(700);
bAll.mov4.gotoAndPlay(700);
bAll.mov5.gotoAndPlay(700);
bAll.mov6.gotoAndPlay(700);
bAll.mov7.gotoAndPlay(700);
};
bAll.mov6.b6.onRelease = function() {
menuSlide(contentHold.content6);
bAll.mov1.gotoAndPlay(875);
bAll.mov2.gotoAndPlay(875);
bAll.mov3.gotoAndPlay(875);
bAll.mov4.gotoAndPlay(875);
bAll.mov5.gotoAndPlay(875);
bAll.mov6.gotoAndPlay(875);
bAll.mov7.gotoAndPlay(875);
};
bAll.mov7.b7.onRelease = function() {
menuSlide(contentHold.content7);
bAll.mov1.gotoAndPlay(1050);
bAll.mov2.gotoAndPlay(1050);
bAll.mov3.gotoAndPlay(1050);
bAll.mov4.gotoAndPlay(1050);
bAll.mov5.gotoAndPlay(1050);
bAll.mov6.gotoAndPlay(1050);
bAll.mov7.gotoAndPlay(1050);
};

playclip.onRelease = function () {
lastTime.play();
pauze._visible = true;
playclip._visible = false;
};

pauze.onRelease = function () {
lastTime.stop();
playclip._visible = true;
pauze._visible = false;
};

count = 1;
delay = 1;
lastTime = 0;
_root.onEnterFrame = function() {
if (delay == 1) {
  if (Math.floor(getTimer()/1000) == lastTime+1) {
   delay = 0;
  }
  // end if
} else if (Math.floor(getTimer()/1000) == lastTime+wait) {
  lastTime = Math.floor(getTimer()/1000);
  delay = 1;
  if (count == 1) {
   move = 1;
  } else if (count == slides) {
   move = 1-slides;
  }
  // end else if
  count = count+move;
  trace(count);
  menuSlide(contentHold["content"+count]);
}
// end else if
};

Thank you in advance !

This topic has been closed for replies.
Correct answer kglad

Almost !!!

But now i've got an error with the code:

*count = (count+1)%slides;*

I did what you sad but the error doesn;t make sence rigth?!

slides = 7;

wait = 7;

playclip._visible = false


contentHold.content1.button.onPress = function() {

getURL("www.visualbrand.nl/kijken.html", "_self");

};

contentHold.content2.button.onPress = function() {

getURL("http://www.bestsellers.nl/catalog/category/view/id/249", "_self");

};

contentHold.content3.button.onPress = function() {

getURL("http://www.bestsellers.nl/music/8718036994508.html", "_self");

};

contentHold.content4.button.onPress = function() {

getURL("http://http://www.bestsellers.nl/5099990631825.html", "_self");

};

contentHold.content5.button.onPress = function() {

getURL("http://www.bestsellers.nl/catalog/category/view/id/270", "_self");

};

contentHold.content6.button.onPress = function() {

getURL("http://www.visualbrand.nl", "_self");

};

var currentPosition = contentHold.content1._x;

var startFlag = false;

menuSlide = function (input) {

if (startFlag == false) {

startFlag = true;

var _loc1 = input._x;

var distanceMoved = 0;

var distanceToMove = Math.abs(_loc1-currentPosition);

var finalSpeed = 3.000000E-001;

var currentSpeed = 0;

var dir = 1;

//----------> SLIDE VAN LINKS/RECHTS NAAR RECHTS/LINKS <-----------

if (currentPosition<=_loc1) {

dir = -1;

} else if (currentPosition>_loc1) {

dir = 1;

}

// end else if

contentHold.onEnterFrame = function() {

currentSpeed = Math.round((distanceToMove-distanceMoved+1)*finalSpeed);

distanceMoved = distanceMoved+currentSpeed;

contentHold._x = contentHold._x+dir*currentSpeed;

if (Math.abs(distanceMoved-distanceToMove)<=1) {

contentHold._x = maskMovie._x-currentPosition+dir*distanceToMove;

currentPosition = input._x;

startFlag = false;

delete contentHold.onEnterFrame;

}

// end if

};

}

// end if

};

bAll.mov1.b1.onRelease = function() {

menuSlide(contentHold.content1);

bAll.mov1.gotoAndPlay(1);

bAll.mov2.gotoAndPlay(1);

bAll.mov3.gotoAndPlay(1);

bAll.mov4.gotoAndPlay(1);

bAll.mov5.gotoAndPlay(1);

bAll.mov6.gotoAndPlay(1);

bAll.mov7.gotoAndPlay(1);

};

bAll.mov2.b2.onRelease = function() {

menuSlide(contentHold.content2);

bAll.mov1.gotoAndPlay(175);

bAll.mov2.gotoAndPlay(175);

bAll.mov3.gotoAndPlay(175);

bAll.mov4.gotoAndPlay(175);

bAll.mov5.gotoAndPlay(175);

bAll.mov6.gotoAndPlay(175);

bAll.mov7.gotoAndPlay(175);

};

bAll.mov3.b3.onRelease = function() {

menuSlide(contentHold.content3);

bAll.mov1.gotoAndPlay(350);

bAll.mov2.gotoAndPlay(350);

bAll.mov3.gotoAndPlay(350);

bAll.mov4.gotoAndPlay(350);

bAll.mov5.gotoAndPlay(350);

bAll.mov6.gotoAndPlay(350);

bAll.mov7.gotoAndPlay(350);

};

bAll.mov4.b4.onRelease = function() {

menuSlide(contentHold.content4);

bAll.mov1.gotoAndPlay(525);

bAll.mov2.gotoAndPlay(525);

bAll.mov3.gotoAndPlay(525);

bAll.mov4.gotoAndPlay(525);

bAll.mov5.gotoAndPlay(525);

bAll.mov6.gotoAndPlay(525);

bAll.mov7.gotoAndPlay(525);

};

bAll.mov5.b5.onRelease = function() {

menuSlide(contentHold.content5);

bAll.mov1.gotoAndPlay(700);

bAll.mov2.gotoAndPlay(700);

bAll.mov3.gotoAndPlay(700);

bAll.mov4.gotoAndPlay(700);

bAll.mov5.gotoAndPlay(700);

bAll.mov6.gotoAndPlay(700);

bAll.mov7.gotoAndPlay(700);

};

bAll.mov6.b6.onRelease = function() {

menuSlide(contentHold.content6);

bAll.mov1.gotoAndPlay(875);

bAll.mov2.gotoAndPlay(875);

bAll.mov3.gotoAndPlay(875);

bAll.mov4.gotoAndPlay(875);

bAll.mov5.gotoAndPlay(875);

bAll.mov6.gotoAndPlay(875);

bAll.mov7.gotoAndPlay(875);

};

bAll.mov7.b7.onRelease = function() {

menuSlide(contentHold.content7);

bAll.mov1.gotoAndPlay(1050);

bAll.mov2.gotoAndPlay(1050);

bAll.mov3.gotoAndPlay(1050);

bAll.mov4.gotoAndPlay(1050);

bAll.mov5.gotoAndPlay(1050);

bAll.mov6.gotoAndPlay(1050);

bAll.mov7.gotoAndPlay(1050);

};


var autoAdvanceI:Number = setInterval(autoAdvanceF,7000);

var count:Number = 0;


playclip.onRelease = function () {

delay.play();

pauze._visible = true;

playclip._visible = false;

clearInterval(autoAdvanceI);

//  start a loop that calls autoAdvanceF() every 7000 ms = 7 seconds

var autoAdvanceI:Number = setInterval(autoAdvanceF,7000);

// my count variable ranges from 0 to slides-1

var count:Number = 0;


pauze.onRelease = function () {

delay.pause();

playclip._visible = true;

pauze._visible = false;

clearInterval(autoAdvanceI);

};


function autoAdvanceF():Void{

// increment count and reset count if incremented to slides

*count = (count+1)%slides;*

// pass contentHold["content"+(count+1)] to menuSlide()

menuSlide(contentHold["content"+(count+1)]);

}


//count = 1;

//delay = 1;

//lastTime = 0;

//_root.onEnterFrame = function() {

// if (delay == 1) {

// if (Math.floor(getTimer()/1000) == lastTime+1) {

// delay = 0;

// }

// // end if

// } else if (Math.floor(getTimer()/1000) == lastTime+wait) {

// lastTime = Math.floor(getTimer()/1000);

// delay = 1;

// if (count == 1) {

// move = 1;

// } else if (count == slides) {

// move = 1-slides;

// }

// // end else if

// count = count+move;

// trace(count);

// menuSlide(contentHold["content"+count]);

// }

// // end else if

//};


remove those asterisks.

1 reply

kglad
Community Expert
Community Expert
October 27, 2010

use the trace() function to debug your code.

but i can tell you checking for equality in those timer if-statements like

Math.floor(getTimer()/1000) == lastTime+1

are pretty unlikely to ever resolve to true.

T__BackxAuthor
Known Participant
October 27, 2010

Thank you for replying!

And I did what you sad to me. I used the trace fuction 3 times. And I now know a bit how the timer works.

But after I changed the code. It still doesn't pause.

But there is a change like you say that this problem can't be solved?

Here are my changes:

playclip.onRelease = function () {

delay.play();

pauze._visible = true;

playclip._visible = false;

};


pauze.onRelease = function () {

delay.pause();

playclip._visible = true;

pauze._visible = false;

};


count = 1;

delay = 1;

lastTime = 0;

_root.onEnterFrame = function() {

if (delay == 1) {

if (Math.floor(getTimer()/1000) == lastTime+1) {

delay = 0;

trace ("after one second")

}

// end if

} else if (Math.floor(getTimer()/1000) == lastTime+wait) {

lastTime = Math.floor(getTimer()/1000);

delay = 1;

if (count == 1) {

move = 1;

trace ("begins")

} else if (count == slides) {

move = 1-slides;

trace ("return")

}

// end else if

count = count+move;

trace(count);

menuSlide(contentHold["content"+count]);

}

// end else if

};

And Thank you for your help so far !

kglad
Community Expert
Community Expert
October 27, 2010

do you ever see any of those if-conditions met?  if not you need to use something like the following.  notice how, instead of testing for exact equality, you're testing for getTimer()/1000 to be close to (lastTime+1):


playclip.onRelease = function () {

delay.play();

pauze._visible = true;

playclip._visible = false;

};


pauze.onRelease = function () {

delay.pause();

playclip._visible = true;

pauze._visible = false;

};


count = 1;

delay = 1;

lastTime = 0;

_root.onEnterFrame = function() {

if (delay == 1) {

// assign tolerance to something your expect to be met

if (Math.abs(Math.floor(getTimer()/1000) - (lastTime+1))< tolerance) {

delay = 0;

trace ("after one second")

}

// end if

} else if (Math.floor(getTimer()/1000) == lastTime+wait) {

lastTime = Math.floor(getTimer()/1000);

delay = 1;

if (count == 1) {

move = 1;

trace ("begins")

} else if (count == slides) {

move = 1-slides;

trace ("return")

}

// end else if

count = count+move;

trace(count);

menuSlide(contentHold["content"+count]);

}

// end else if

};

And Thank you for your help so far !

then do the same for your other if-conditions that are never met.