Skip to main content
August 12, 2009
Answered

How do I make my flash banner change frames on a timer?

  • August 12, 2009
  • 1 reply
  • 1821 views

Hello, I'm new to flash and I recently just made a flash banner where you can click buttons to change frames. I also want to add the ability for it to automatically change frames after 7 seconds. I've put all of the pictures on the same frame and gave them frame labels. What would be the actionscript code I should use to make this work, along with making the buttons still functional? Also, how can I put buttons to go to the last frame from the first, and first to the last, while still making them stop at every frame? I keep trying and nothing's working.

If you'd like a more in-depth look, I've provided the .FLA file here:

http://uppit.com/v/ZJOKIQ59

The easiest way to explain it would be to re-upload an .FLA file with all of the above completed bug-free, and show me how you did it. I hope I'm not asking too much with that, but I would be able then to take a look at it and compare it to my code to learn it myself.

Thanks in advance for any help! =]

This topic has been closed for replies.
Correct answer e_optic

Well I done some more work this time. As i had some problems uploading files I'v made these screanshots.

code.jpg

Timeline.jpg

- On the first frame add just this:

var secTimer:Timer=new Timer(1000,7);

startTimer();

- The actual code is on the second frame:

//secTimer.addEventListener(TimerEvent.TIMER, tik);

secTimer.addEventListener(TimerEvent.TIMER_COMPLETE, skipFrameT);

next_btn.addEventListener(MouseEvent.CLICK, playNextFrame);

function playNextFrame(e:MouseEvent):void {

if(currentFrame < 50){

resetTimer();

play();

}

else{

resetTimer();

gotoAndPlay(2);

}

}

prev_btn.addEventListener(MouseEvent.CLICK, previousFrame);

function previousFrame(e:MouseEvent):void {

if(currentFrame <= 11){

gotoAndPlay(42);

}

else{

gotoAndPlay((currentFrame-10));

}

resetTimer();

}

/*function tik(e:TimerEvent):void {

trace("frame ",currentFrame,", tick", secTimer.currentCount);

}*/

function startTimer():void {

secTimer.start();

//trace ("timer Started");

}

function skipFrameT(e:TimerEvent):void {

//trace ("time stoped");

if(currentFrame < 50){

play();

}

else{

gotoAndPlay(2);

}

resetTimer();

}

function resetTimer() {

trace("Timer Reseted");

secTimer.reset();

startTimer();

}

- Remove your code for the buttons;

- And use 10 frames spaceing for the images:

2 to 11; 11 to 21; 21 to 31... and so on.

Hope this will be real help now.

1 reply

Participant
August 12, 2009

I think this will help

the animation and code were to messy for me... so I think this is the easiest way to make it work.

just add a new layer, use the whole time line and add this code to it.

var secTimer:Timer = new Timer(1000, 7);

startTimer();

//secTimer.addEventListener(TimerEvent.TIMER, tik);

secTimer.addEventListener(TimerEvent.TIMER_COMPLETE, skipFrameT);

//next_btn.addEventListener(MouseEvent.CLICK, resetTimer);

//prev_btn.addEventListener(MouseEvent.CLICK, resetTimer);

/*function tik(e:TimerEvent):void

{

trace ("tik");

}*/

function startTimer ():void

{

secTimer.start();

//trace ("timer Started");

}

function skipFrameT (e:TimerEvent):void

{

//trace ("time stoped");

resetTimer();

play();

startTimer();

}

function resetTimer()

{

secTimer.reset();

//trace("Timer Reseted");

}

August 13, 2009

Thanks for the help! =]

It's so close to perfect. The only thing is I need the timer to reset when you click the buttons so it doesnt stay on a frame for like 2 seconds and then switch because of the timer. Is that possible? Also, after the whole thing goes through one cycle, the buttons stop working. Here's a re-uploaded version with a few image revisions by me:

http://uppit.com/v/ZWVX9DO6

Also, whenever the banner goes through all of the frames and comes back to the first frame with the buttons, the first frame next_btn stops working for some reason. Thanks if you can solve this.

Thanks again =)

e_opticCorrect answer
Participant
August 15, 2009

Well I done some more work this time. As i had some problems uploading files I'v made these screanshots.

code.jpg

Timeline.jpg

- On the first frame add just this:

var secTimer:Timer=new Timer(1000,7);

startTimer();

- The actual code is on the second frame:

//secTimer.addEventListener(TimerEvent.TIMER, tik);

secTimer.addEventListener(TimerEvent.TIMER_COMPLETE, skipFrameT);

next_btn.addEventListener(MouseEvent.CLICK, playNextFrame);

function playNextFrame(e:MouseEvent):void {

if(currentFrame < 50){

resetTimer();

play();

}

else{

resetTimer();

gotoAndPlay(2);

}

}

prev_btn.addEventListener(MouseEvent.CLICK, previousFrame);

function previousFrame(e:MouseEvent):void {

if(currentFrame <= 11){

gotoAndPlay(42);

}

else{

gotoAndPlay((currentFrame-10));

}

resetTimer();

}

/*function tik(e:TimerEvent):void {

trace("frame ",currentFrame,", tick", secTimer.currentCount);

}*/

function startTimer():void {

secTimer.start();

//trace ("timer Started");

}

function skipFrameT(e:TimerEvent):void {

//trace ("time stoped");

if(currentFrame < 50){

play();

}

else{

gotoAndPlay(2);

}

resetTimer();

}

function resetTimer() {

trace("Timer Reseted");

secTimer.reset();

startTimer();

}

- Remove your code for the buttons;

- And use 10 frames spaceing for the images:

2 to 11; 11 to 21; 21 to 31... and so on.

Hope this will be real help now.