Your First Script / Basic Timeline Navigation pt. 2
Subtitles of the Movie
Continuing from the previous movie we're now ready to write out the rest of the script to get our navigation working. Open up the Actions Window and click after the open curly brace and let's add the next two lines of script. You'll notice that the cursor should be blinking in an indent position. I'm going to go ahead and write out the next two lines of script for you. Let's move this over. The first one is a remark, conditional, to check which button has been clicked and we're going to go ahead and add an If Conditional for notice not the Home button, for the Page 1 button. That's because we're going to go ahead and test this script first and because our Stop action is keeping the Playback Head in the first frame or the Home page, we want to write the script out for the Page 1 button so we can check and move that off of that page. Now click after that last closing parentheses and press the Enter key to add a couple lines here. You'll notice right away that the lines don't really matter so I like to add a lot of spaces between my code lines so I can read it very easily. Now the next line is going to be an open curly brace and then I'm going to go ahead and go to and stop page 1. Now let's go ahead and close this opening curly brace right there. You'll notice that you'll need matching curly braces everywhere we write them as well as matching parentheses. You'll also notice that the closing curly brace is no longer indented so that these curly braces not only match in type, open close, open close, but also match in position. Go ahead and let Flash do that formatting for you. So we're almost ready to test this first button. Remember I mentioned that you want to be checking your scripts as you write them. I can't check this conditional yet. I need to add now something called an Event Listener. I'll be covering more theory about why you are scripting this the way you are, but let's go ahead and add now a couple extra lines and now the next several lines of script look like this: forward //for the comment, my event handlers after the last function curly brace, home btn.addEventListener and the addEventListener is in blue, that represents a reserved word for Flash and then MouseEvent.CLICK handleClick. Now this is the event listener for the home button, see right there, home btn. We need to add an event listener. Let's move that back over there for the page1 button because I can't test my home button yet. Let's do the page1 button next, so I'm going to add the script. Add a couple lines. Here is the event listener for page1, page1 underscore btn.addEventListener. Don't forget the open parentheses and then MouseEvent.CLICK, handleClick. So now I'm finally ready to test the lines of script that I've added here since I added the stop action. Before we do that you might want to make one last check that all your scripting matches mine. You may even want to pause the movie. Notice that you have different color indicators here. The page1 over here for the gotoAndStop method is in green. I have some blue text and some black text, also some gray text for the comments. There is my function conditional, my event handlers are down here; I've written two, one for the home button and one for the page 1 button. I haven't written the conditional for the home button yet. That's OK. I've got my event listener ready for us. Now to test our scripts do Control, Test Movie and again you want to do a little mind test and see, OK, now what should happen when I click on the various buttons? Now I haven't added the scripting for the home button. I've added the event listener, but I have added the event listener and the method, the gotoAndStop method for page1, so what should happen now when I click on page1 is that this label should change from home to page1 and it does. Notice that none of the other buttons are working, including the Home button, so everything looks good so far.
Tutorial Information
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 