Home
Username:
Password:
Adobe Flash ActionScript 3.0 for Designers Tutorials

Your First Script / Basic Timeline Navigation pt. 3

Subtitles of the Movie

Now we're going to use an old programmer's trick to get the scripting finished for the home button. What we're going to do is we're going to copy the code for the page1 button, since we already tested it and we know that it works. So, let's go ahead and add a few lines here in our script and now let's copy wholly this If conditional for the page1, Ctrl-C will copy that on my PC, Command-C will copy it on the Mac and then let's click here and paste it in. Everything looks good. I have to change this line right here from page1 to home. This is why you want to keep your labels real consistent and I'm going to also change this label here, the Target Instance for the button from page1 just to home, just like that. Now I've already written my event handler down here for the home button. I didn't get an error before so that looks like it's going to work OK. Now let's go ahead and test this again. Remember, you want to test each line of code if you can as you write it. Now although I've copied this code from the page1, I did make some changes, so let's go ahead and test the movie just to make sure that everything is still working. I know my page1 button is working so let's click on that and that's going to go to Page 1. Now my home button, I can check it. What should happen now is this should go back to the home page so the label should change from Page 1 to Home and it does. I click back and forth between these two buttons and now I have two of my five buttons working and I can now proceed to use the same trick to script out the rest of the buttons. Go ahead and go after the page1, after the last curly brace there. Remember this curly brace here is closing for the entire function, so don't add anything after that, but I can go ahead and just paste in the page1 script here, change that to page2, change this to page2, again because I used very similar labels it makes modifying the paste very easy. Now all I need to do here is let's copy the event listener for the page1 button, add a few lines of script there, paste in again, make one simple change from page1 to page2 and I'm now ready very quickly to check the next button, the page2 button. So I do Control, Test Movie. Let's go ahead and go right to the page2 button and yes it is working. Go ahead and check the other buttons just in case. Sometimes when you make a change elsewhere in the script it will cause script that you've already tested to break, so I'm going to go ahead and check that and now it looks like everything is working perfectly. Obviously the page3 and the page4 buttons have not been scripted, so you would just repeat that procedure to get those two buttons working and then test all of the buttons when you've finished up adding all the script for the page3 and the page4 buttons. Now one last thing you can do, although it's not entire required, is to go ahead and add Stop actions for the rest of your frame. So I'm going to use the same trick and copy this stop action and now add stops to all of my additional keyframes here. I don't actually need these because I told the script to gotoAndStop to these various frames. Notice right here the script says gotoAndStop, but I always like to add a stop action there just in case. One of the most common beginner mistakes that I notice from my ActionScript students is sloppy naming practices. They don't use the names that I used here, real short similar names, so let me now move on to the next movie and cover some additional naming rules to keep you out of trouble here in your early stages of learning ActionScript.

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