FORUMS: list search recent posts

AS3, how to make 'previous, pause & next' button?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ian Rajkumar
AS3, how to make 'previous, pause & next' button?
on Jun 3, 2011 at 1:14:39 am

Hey Guys,

I am creative director at my company, I have been doing animation and motion design for a long time now, but recently I am doing something outside my comfort zone, Adobe flash and I am having a bit of trouble


ok, here's the animation overview:
I have 3 short animation movies(slides)and they blend seamlessly into each other, when the animation slide 1 plays, animation slide 2 can start playing anytime after(transition in) and will blend seamlessly which will transition out slide 1 (and this is repeat for all the slides)

summary: seamless transition between slides; 1 to 2 to 3 (then back) to 1 again

my issue is, I want to create 3 buttons; Previous | Pause | Next
and these buttons should be self-explanatory in what they do.

Also, I want the slides to have a 10 second pause between them, then automatically the next slide should start playing

how do I go about scripting in AS3 to get this result?

Thanks for your help in advance! =)


Return to posts index

Brodd Nesset
Re: AS3, how to make 'previous, pause & next' button?
on Jun 3, 2011 at 7:13:19 am

Hi! You'll find plenty of tutorials on this, but:

1. Create your buttons.
2. Give each an instance name. Using AS3, this is an absolute requirement! Each instance must be unique, of course. In my example I use myPrevBtn, myPauseBtn, myNextBtn.
3. In a frame in the timeline where every button appears on stage, I add this scriptiong:

//This is the general procedure on making a button functon in AS3:

myPrevBtn.addEventlistener(MouseEvent.CLICK, myBtnFunction);

//Attach the above in bold for any other buttons.

function myBtnFunction(e:MouseEvent):void {
var btnClicked:String = e.target.name //the button clicked!

if (btnClicked == "myPrevBtn") { //The name of each button
gotoAndPlay("previous"); //What to do when the specific button is cliked
}
//Repeat the if-chunk only for each button you have, with new name and what to do. Now you have all your button-functionality in one place! End it with an:
}

Adding a pause may appear sligthly more advanced, but follows the same logic:

stop();
var pauseSecs:int = 10;
//Seconds to pause.
var myTimer = new Timer(pauseSecs * 1000, 0);
myTimer.addEventListener(Event.TIMER, goNext);
myTimer.start();


//This part can be separate:
function goNext(e:TimerEvent):void {
gotoAndPlay("next");
//What to do when the pause has elapsed.
myTimer.removeEventListener(Event.TIMER, goNext);
}


Very important principle: Once set up, you can call these functions from anywhere. You only need to create them once. It is very common to have the function-chunks in frame 1, for tidyness, while the .addEventListener-bits are scattered around where needed. It is these who actually trigger the action. The button object must be visible on the stage for the Event-listener to work.



Not everything that can be counted counts, and not everything that counts can be counted.



Return to posts index

Ian Rajkumar
Re: AS3, how to make 'previous, pause & next' button?
on Jun 4, 2011 at 1:42:44 am

Hey Brodd Nesset, Thanks for your help - but I am afraid this is a bit complex for me

I have attached the slides below, I would really appreciate it if you can help me script this, I hope that's not asking too much. Thanks again =)

2430_slides.zip


Return to posts index


demetri tashie
Re: AS3, how to make 'previous, pause & next' button?
on Jun 4, 2011 at 9:54:04 pm

hi ian,

seeing now that these are really video files(FLVs) that you are working with, and not movieclips as was presumed from your first post, you will need to approach it a little differently.

while it can be done working with those 3 videos as separate files, i would strongly suggest you compose the 3 files into one longer FLV which you add cue points to.

then you can have them easily play in sequence,and using the cue points, you have a nice means to code your PREV and NEXT button with, as well as having a much smoother experience with the videos.

if you want to explore that further, let us know.


Return to posts index

Ian Rajkumar
Re: AS3, how to make 'previous, pause & next' button?
on Jun 5, 2011 at 12:02:40 am

Hey demetri,

Thank you so much for clearing that up for me, I think i would prefer to use a single seamless video file, I have attached the the seamless video file.

2431_flippingtitles.flv.zip

Can you help me code this in such a way that if i want to use different video files in the future, the script will be flexible enough to work?


thanks alot, I really appreciate it

- Ian


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]