Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding button functionality

From: Creating a First Web Site with Flash Professional CS5

Video: Adding button functionality

Essential to any site is the need to add button functionality, which will really enable that user to navigate the site and control contents. So this site is no different, because I do have all these sections set up. So what I want to do is I want to control the Timeline. And I want it to, when you click on any one of these buttons, it will jump to the appropriate section. So the first thing I need to do is I need to stop the Timeline at about Frame 29, because currently it's going to play through all over this content.

Adding button functionality

Essential to any site is the need to add button functionality, which will really enable that user to navigate the site and control contents. So this site is no different, because I do have all these sections set up. So what I want to do is I want to control the Timeline. And I want it to, when you click on any one of these buttons, it will jump to the appropriate section. So the first thing I need to do is I need to stop the Timeline at about Frame 29, because currently it's going to play through all over this content.

So about at Frame 29, this is where I want the Timeline to stop. And this is going to take ActionScript, okay. Luckily, what's available in Flash CS5 is code snippets. So under Window > Code Snippets, I am able to open up this Code Snippets panel. Very powerful, just really helpful in adding interactivity. But I'm going to go ahead and just put this on the side. This is actually loaded, full of ActionScript code.

And I encourage you to check out all of these different folders, because you have general actions. You can control the Timeline. You have animation controls. You can load and unload content, you know SWF files, JPEGs, audio and video as well and even some generic event handlers. But what I'm going to do is I'm just going to open up this Actions panel, just to kind of give you a quick preview. A popular one on this folder is clicking to Go to a web page, but Timeline Navigation is what I want to focus on, because again, at Frame 29, I want to stop at that frame.

So all I need to do is go to the frame I want to stop the Timeline at and double-click on that code snippet. It automatically adds that code snippet. Here it is. This is actual code that does although work, but it also gives you a comment right here, which tells you what is going on. So this is perfect. I can learn and then also see the code and even modify it. I know this is really just a really simple example, but you'd be surprised at how often you'll end up using this stop action right here.

Okay, well, where did I put this stop action? Well, down here it tells me it actually creates this Actions layer and in Frame 29 is where this code exists. So let's take a look at that. I'm going to close my Actions panel. And I'll scroll up to the top. And look at that. There it is, the Actions layer, Frame 29, right there. See that little A right there. That little A says that there are some ActionScript associated to that frame. So I can go to Window > Actions.

And there's my code. Okay, so I have actually stopped the Timeline at this point, but what I want to do next is I want to add functionality to these buttons. Now I'm not going to do that at Frame 29. What I'm going to do is I'm going to do that at Frame 1, okay. So right here at this very first frame, in case the user wants to jump directly to the Contact section, they don't have to wait for this animation to play. So it's all about usability here. One key thing to note is to make sure your graphics exist at the point in time that you apply your actions.

Okay, so again, I want to go ahead and apply some code to each one of these four buttons. And if I go to my Properties panel, and with this button selected, well, let's take a look at it. It's just an instance of the generic button. And in fact there are four of them. So I need to give each one a unique name in order to apply some code to it. I first need to give it a unique instance name. So right up here in my Properties panel, I'm going to give this an instance name of about_btn, just like that.

Now the ActionScript code I apply to the button is going to recognize this as that unique button, but I'm going to go through for each one of these and give each one an instance name, a unique name that clearly defines it. portfolio_btn. Don't use any spaces. Don't start with any special characters or numbers, just to keep it simple. contact_btn, just like that.

So each one of these buttons has an instance name. Now I can apply code to it. All right, so with this button selected, I can go to my Code Snippets panel. And in my Timeline Navigation folder, I can Click to Go to Frame and Play. And that's what I want to do. I actually want to, if I expand up this Timeline more, I'm just going to close this up actually. I want to go to Frame 30, right here. And I want to play it.

And it's going to play through and then right there. But I don't want it play through into the other sections. So again, what I need to do is add some other stop actions. So I'm going to stop at this frame here. It adds the code at Frame 49, as it shows me there. Close that, kind of move on down, right here also for the Portfolio section. Double-click and stop at this frame. And then lastly for the Contact section, I want to double-click on that code snippet to stop it at that frame.

All right, so my stop actions are in place. And again, if I go back here to my very first frame and select that button, I can select Click to Go to Frame and Play. So I'm going to ahead and apply it to that selected button, just by double-clicking on it. And it adds that code to it. Remember, it adds at this very first frame. That's what that little A is. So at the very beginning of this web site is where all my major code is going to live.

So again, here is my code, and I can start to modify it or whatever I need to do. First thing I'm going to do is I'm going to remove this panel off to the side just by clicking that left arrow. There we go. And now I can read this clear, because this comment not only tells me what it does; it gives me instructions on how to modify it. So I need to replace the number 5 with the frame number you want to jump to. Okay, in this case, it's going to be Frame 30, because Frame 30 is where that About content starts to roll in.

All right, and each one's spaced out about 20 frames. So I have just to change that to gotoAndPlay(30). And let's go ahead and test out this button. It's really simple. I still need to apply this, but again, it stops at this point in time. And if I click on this button, it goes to Frame 30, plays it, and then it reaches that second stop action right there and stops. So that's perfect.

You know the next step is to make these other buttons to work, but it follows the same process. Again, I'm going to make sure I'm in Frame 1. I'm going to select the Portfolio button. And keep in mind that I'm not selecting the text. There's text on top. I'm actually selecting the button back there. So I will select Click to Go to Frame and Play. Apply that. And it applies that same code. And still it tells me to modify that frame number. And each one's spaced out about 20 frames.

So this is on Frame 50 is where-- well, actually, let's just double-check that. Yup! There is Frame 50, perfect. So it goes there and it adds this comment. These comments, if I could be honest, are getting kind of annoying because it's just taking up a lot of room. Well, you know what? They're not needed. So I can even delete that right there. Now I can read this better. And if I take a closer look at this code, you can start to see the difference and what's going on here, because it's going to give me my instance name and it adds an event listener to this button that listens for the CLICK.

And on CLICK, it's going to fire off this function right here. So it's great that I list out to this code here. I can modify it further if I wanted to, but in general that's the structure for a common button. All right, let's move on along. Contact button, select it, double-click, Click to Go to Frame and Play. It's about a frame what? 70, right there. That's for the Contact button again. And let's close this, because lastly, I'm just going to select this Home button and do the same thing, which is apply that code.

All right, and I'll delete that comment. Now, this I want to go to about Frame 10 and play. Now you can also move this code around. Since they are going in order from left -to-right, I can always take this Home button code and drag it up near the top like that. So now it's sort of more in order as they're laid out on this page of the nave bar, so Home, About, Portfolio and Contact. It's looking good.

I will do a Test Movie. Stops where it needs to stop, About section, Portfolio section, Contact section and then Home. So everything works exactly as expected. It's perfect. Code snippets not only provide you the code; it gives you direction on modifying and within minutes, you can have a fully functional web site.

Show transcript

This video is part of

Image for Creating a First Web Site with Flash Professional CS5
Creating a First Web Site with Flash Professional CS5

34 video lessons · 28189 viewers

Paul Trani
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Creating a First Web Site with Flash Professional CS5.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.