Our website will be down for scheduled maintenance on Thursday, September 18, at 11 p.m. Pacific Time and should be back up by Midnight. We apologize for any inconvenience.

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

Creating a simple slide presentation app in the timeline

From: ActionScript 3.0 in Flash Professional CS5 Essential Training

Video: Creating a simple slide presentation app in the timeline

To get practice navigating through Timelines, we'll build a simple slide presentation app. I've taken this bear animation, and I've broken it up into different frames. So we have this one, and this one, and this one, and then the basket goes up into the tree, and the bear tries to get it. So, I'll just scroll up a little bit. So you can see the bear trying to get the basket. These are all just still images that I exported using the File > Export > Export Image command.

Creating a simple slide presentation app in the timeline

To get practice navigating through Timelines, we'll build a simple slide presentation app. I've taken this bear animation, and I've broken it up into different frames. So we have this one, and this one, and this one, and then the basket goes up into the tree, and the bear tries to get it. So, I'll just scroll up a little bit. So you can see the bear trying to get the basket. These are all just still images that I exported using the File > Export > Export Image command.

If you want to do the same thing with your animation, it's really best to do this on the main Timeline and not inside of a movie clip, because the coordinates inside of the movie clip are relative. So just keep that in mind. So on the Stage, I have a button called back_btn and a button called forward_btn. And then in my code, I've just created some simple EventListeners and EventHandlers for them. So I don't have any code inside of them, but I've just built this already.

So you've seen this function before, the previous frame function, which is prevFrame and parentheses. So we can do that when we click the Back button, and when we click the Forward button, we can go to the next frame. So we'll type nextFrame with capital F, add some parentheses and Before I test the movie I want to add one more line of code. I'm just going to put a stop action. I'll put that at the top of the code, below line 2. So I'll go to the next line and just type stop, some parentheses, and a semicolon, because we don't want the movie to plat by default.

So let's test the movie, and then we have our little slide show, so we can click the Next button to advance through the slides and the Previous button to step backwards through the slides. So if you ever want to make a slideshow, just whip up this code real fast, and there you have it. Let's say you wanted to advance in a loop, so you go to the last frame and you click the Next button, and you want to go back to the first frame again, and vice versa.

You want to go from the first frame to the last frame if you click the Back button. Let's take a look at how to do that. So go to forwardClicked and right below nextFrame, type if, some curly braces. Now, what we can do is check to see if the current frame is the last frame. So to do that, we could say, if currentFrame is equal to - what's the last frame? 6 - we could put 6 right there, but the better way to do it is to use the totalFrames property.

So if the currentFrame is the last frame, or in other words, if the currentFrame is equal to totalFrames, you see why that's better? That's because, if you add more frames or take away frames, the code won't break. So it's always better to make it so that the code won't break if you change the design, because it is pretty likely that you will change the design in your app. So the more solid the code is, the better. So if the currentFrame is equal to totalFrames, then we'll go back to frame 1.

Take a second to think of the code that you would use to go back to the first frame. Simply type gotoAnd with a capital A, Stop, capital S, and 1 in parenthesis. Now, I've stressed the importance of using frame labels before. So you could use one if you want here, but actually, if I go to the last frame and click the Next button, I'm always going to want to go to the first frame. So unless I completely redesign this app, then this code is going to be solid, no matter how many frames I have.

So using the number 1 is okay in this case. So I have my code set up here, and we'll test the movie and then click the Forward button and watch as we advance through the frames. See if you notice anything off. When the basket is up, I click the Next button, and it goes back to the beginning. But what about the frame where the bear is trying to reach for the basket? We don't see that. Let's take a look at why that is happening.

So the function goes to the nextFrame, and then checks to see if the currentFrame is equal to the total number of frames. If so, gotoAndStop. Here is the problem. The fact that nextFrame is before this if statement makes the frame updated before you see it updated. So it happens without you seeing it. Flash makes the frame go to the last frame with the bear, but before you see it, Flash runs this code to go back to the first frame.

Occasionally, you'll run into these problems when you're working with frames. You have to make sure that you change the frame last, so that the last thing you see is the new frame. To make sure this happens correctly, cut nextFrame with Command+X or Ctrl+X. Then below the if statement, let's write an else statement. So write else, and then some curly braces, and then paste the code.

So if the playhead is on the last frame, we'll go back to the beginning. If not, then we'll go to the nextFrame. So we don't have the nextFrame code running every single time, like we did before. It only runs when we're not on the last frame. So let's test the movie now, and you should see all the frames of animation. So bear comes up, basket goes up, and there is the bear. Click the Next button, and you go back to the beginning. So now what we'll do is we'll apply the same technique, but in reverse, to the backClicked function.

So let's scroll up. Then above prevFrame, let's write an if statement: so if, some parentheses, and some curly braces. In the if statement, we want to see if we're on the first frame. So all we have to do is check to see if currentFrame - capital F - is equal to 1. If so, then we're going to go to the last frame. So gotoAndStop and then parentheses, pass in that totalFrames property - capital F.

It should be blue after you type it. Then we'll wrap prevFrame in an else statement. So we only go to the previous frame if we're not on the first frame. I'll just tab that in and write some curly braces around it. So if the current frame is 1, we're going to go back to the end, which is represented by totalFrames. Again, we're using that just in case we increase or decrease the length of the animation. And then the else statement says if we're not on frame 1, then we're going to go back to the previous frame.

So let's test the movie, and if you click the Back button, you'll go to the last frame. Continue to click it, and you'll step backwards through the animation, and the Forward button still works as well. So by using these conditional statements, along with the next frame and previous frame commands, we can navigate through each frame of the Timeline and have the slideshow play in a loop. So navigating through Timelines is a key component in many apps, and as you get more practice using these commands, you'll be able to add Timeline navigation to all sorts of applications.

Show transcript

This video is part of

Expand all | Collapse all
  1. 3m 22s
    1. Welcome
      1m 23s
    2. Using the exercise files
      1m 17s
    3. Using the function keys
      42s
  2. 23m 38s
    1. Adjusting preferences for ActionScript fonts, colors, and formatting
      3m 25s
    2. Changing Flash Player and ActionScript versions in the Publish settings
      1m 35s
    3. Reading and solving errors through the Compiler Errors window
      2m 49s
    4. Using the Actions panel buttons to add and remove comments
      2m 33s
    5. Using the Actions panel to format code
      1m 49s
    6. Using the Actions panel Toolbox
      2m 4s
    7. Seldom-used but helpful functions of the Actions panel
      3m 14s
    8. Understanding code hinting
      2m 3s
    9. Reviewing the Code Snippets panel
      3m 7s
    10. Using help
      59s
  3. 45m 50s
    1. Understanding how ActionScript 3.0 code is processed in the Flash Player
      3m 22s
    2. Understanding variables
      4m 56s
    3. Understanding functions
      9m 1s
    4. Understanding events and event listeners
      5m 47s
    5. Working with conditional statements
      9m 49s
    6. Creating arrays and vectors
      6m 50s
    7. Using the For command to create a loop
      6m 5s
  4. 49m 9s
    1. Reviewing the display list
      3m 0s
    2. Understanding instances referenced through ActionScript
      2m 27s
    3. Using dot syntax to modify properties in an instance
      3m 25s
    4. Placing objects at the center of the stage
      4m 2s
    5. Placing objects at the edges of the stage
      5m 53s
    6. Using the methods of an instance
      3m 44s
    7. Accessing the parents, children, and grandchildren of objects
      5m 50s
    8. Creating instances from Library movie clips using ActionScript
      4m 23s
    9. Adding objects to the stage and changing parents with the addChild method
      5m 45s
    10. Removing objects from the stage with the removeChild method
      4m 17s
    11. Using the numChildren property to loop through a container's child objects
      3m 17s
    12. Using the getChildByName method
      3m 6s
  5. 56m 20s
    1. Understanding timelines
      4m 15s
    2. Using common timeline navigation methods
      5m 34s
    3. Using the currentFrame and totalFrames properties
      8m 2s
    4. Controlling the timeline of an instance
      6m 41s
    5. Detecting and navigating frame labels with ActionScript
      7m 57s
    6. Solving problems when timelines and ActionScript animation collide
      4m 16s
    7. Condensing a multi-frame timeline into one frame
      8m 33s
    8. Creating a simple slide presentation app in the timeline
      7m 51s
    9. Using one event handler with multiple buttons
      3m 11s
  6. 36m 5s
    1. Creating a class using Flash templates
      4m 43s
    2. Setting a document class
      6m 51s
    3. Preparing a class to be connected to a symbol
      4m 31s
    4. Using the Symbol Properties menu to connect a symbol to a class
      4m 55s
    5. Resolving problems with instances in a linked class
      7m 53s
    6. Understanding packages
      3m 17s
    7. Working with ActionScript source paths
      3m 55s
  7. 44m 32s
    1. Viewing the finished game
      51s
    2. Viewing the FLA file
      2m 9s
    3. Creating the DragDrop and Map classes
      2m 51s
    4. Linking the draggable class to Library symbols
      2m 47s
    5. Adding drag-and-drop functionality
      3m 38s
    6. Saving and resetting an object's position
      3m 33s
    7. Giving a target drop object to the draggable objects
      13m 16s
    8. Showing a Win screen
      7m 3s
    9. Resetting the game
      8m 24s
  8. 29m 6s
    1. Loading bitmap images from the Library
      4m 6s
    2. Loading bitmap images from external files
      5m 22s
    3. Adding mouse functionality to bitmap images
      3m 31s
    4. Using a loop to load multiple images
      6m 14s
    5. Creating a simple slideshow
      8m 37s
    6. Using Flash Player 10 color management
      1m 16s
  9. 27m 13s
    1. Loading an external SWF
      4m 14s
    2. Running ActionScript code in an external SWF from its parent
      5m 30s
    3. Running parent code in a child SWF
      5m 7s
    4. Creating a timeline-based preloader to load an external SWF file
      5m 3s
    5. Displaying playback progress of a loaded SWF file
      7m 19s
  10. 40m 10s
    1. Creating plain text files
      2m 8s
    2. Loading text from an external text file
      6m 26s
    3. Loading multiple text files
      6m 43s
    4. Rendering simple HTML in a text field
      5m 51s
    5. Creating a scroll bar for a text field
      5m 29s
    6. Scrolling a text field
      4m 59s
    7. Scrolling movie clips and other objects using masks
      5m 42s
    8. Modifying TLF text properties through ActionScript
      2m 52s
  11. 23m 40s
    1. Reviewing XML and E4X syntax
      3m 29s
    2. Loading an XML file
      3m 26s
    3. Using dot syntax to access XML data
      4m 2s
    4. Using XML data to populate a DataGrid component
      7m 4s
    5. Using XML data to load image files
      5m 39s
  12. 23m 33s
    1. Loading audio from the Library
      1m 41s
    2. Loading audio from external files
      3m 41s
    3. Playing, pausing, and stopping sounds
      5m 39s
    4. Muting all audio with the SoundMixer.stopAll method
      1m 28s
    5. Tracking load progress
      2m 38s
    6. Displaying sound position
      5m 5s
    7. Adjusting volume
      3m 21s
  13. 19m 54s
    1. Touring the FLA file
      5m 57s
    2. Controlling video playing and pausing with ActionScript
      1m 56s
    3. Working with ActionScript cue points to add closed captioning
      3m 35s
    4. Displaying video playback position
      3m 44s
    5. Adjusting video volume
      4m 42s
  14. 5m 32s
    1. Using new code snippets for AIR and mobile
      1m 13s
    2. Viewing the new code snippets HUD
      1m 17s
    3. Loading assets with the new ProLoader class
      1m 8s
    4. Understanding Flash Player premium features
      1m 54s
  15. 16s
    1. Goodbye
      16s

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.

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 ActionScript 3.0 in Flash Professional CS5 Essential Training.

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.