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

Adding a simple code snippet

From: Flash Professional CS5: Code Snippets and Templates in Depth

Video: Adding a simple code snippet

For your first code snippet, choose something very simple. I'm going to demonstrate the use of one of the simplest code snippets that simply adds a stop command into the Timeline to stop any existing animations. For this demonstration, I'll use a preexisting file that's available from the Exercise Files folder. If you have access to the Exercise Files, go to the Exercise Files folder, and then to the subfolder Ch01_SimpleSnippets. Then open the file SimpleSnippet.fla.

Adding a simple code snippet

For your first code snippet, choose something very simple. I'm going to demonstrate the use of one of the simplest code snippets that simply adds a stop command into the Timeline to stop any existing animations. For this demonstration, I'll use a preexisting file that's available from the Exercise Files folder. If you have access to the Exercise Files, go to the Exercise Files folder, and then to the subfolder Ch01_SimpleSnippets. Then open the file SimpleSnippet.fla.

This presentation has multiple layers. Most of the layers have static, graphical, or movie clip object. This layer named bike has a motion tween. The motion tween causes a movie clip symbol to travel across the screen from right to left. The movie clip symbol itself has a frame-by-frame animation in its Timeline. I'll test the movie by pressing Ctrl+ Enter on Windows or Command+Enter on Mac. You'll see that the biker crosses the screen over and over again, traveling from right to left.

Now I want to add a stop command in the first frame of the movie. This is a simple snippet. It will execute when the playhead gets to the frame that contains the code. So before adding the snippet, I'll place the playhead in frame number 1 of the Timeline. Notice that its position by default. Then I'll go to the menu and choose Window > Code Snippets. I'll go to Timeline Navigation, and then I'll double-click Stop at this Frame. That causes two results.

Notice in the Timeline that a new Actions layer has been added. And you can tell in the first frame by the little scripted a that ActionScript code has been added to that first frame. Now I'm going to expand the size of the Actions panel so we can see all of the code and comments that have been added. You'll see a block comment that describes what the code does, and then the simplest of commands, the stop command. That means that when this command is encountered that the playhead should stop moving on the Timeline.

I'll close the Actions panel and once again test the movie. You'll see that the biker is no longer traveling from right to left, but the legs are continuously moving, and the hairs moving with the wind. That's because of the frame-by-frame animations in the movie clip symbol itself. So I'll close the test movie. Then I'll go to the Library and locate the movie clip symbol, mcBiker. I'll double-click to open that movie clip. Here is the frame-by-frame animation.

Notice all the different frames that are involved in the animation. I'll close the Code Snippets panel. Then I'll scrub through the Timeline within the movie clip symbol, and show you the animation. Notice the legs moving. Now I'll show you that you can also add the code snippet within a movie clip symbol's timeline. Once again, I'll place the playhead in frame number 1, go back to the Code Snippets panel, to Timeline Navigation, and double-click Stop at this Frame. That adds the Stop command into frame number 1 of the Actions layer.

I'll return to Scene 1. I'll test the movie again, and here is the result. The legs are no longer moving. But with the wind still blowing, the hair is blowing in the wind. So the thing to learn from this demonstration is that you can add code snippets into Timeline, either the movie's main timeline or into timelines of any movie clip symbol.

Show transcript

This video is part of

Expand all | Collapse all
  1. 4m 40s
    1. Welcome
      1m 32s
    2. Understanding the prerequisites
      1m 42s
    3. Using the exercise files
      1m 26s
  2. 39m 39s
    1. Using code snippets
      4m 7s
    2. Touring the Code Snippets panel
      2m 51s
    3. Adding a simple code snippet
      3m 28s
    4. Adding a complex code snippet
      7m 45s
    5. Applying code snippets to movie clip instances
      5m 25s
    6. Showing and hiding movie clip instances
      3m 20s
    7. Handling common mouse events
      8m 1s
    8. Handling keyboard events
      4m 42s
  3. 36m 21s
    1. Adding Play and Stop actions
      5m 27s
    2. Handling the enterFrame event
      8m 5s
    3. Managing multi-scene presentations
      8m 14s
    4. Adding drag and drop
      6m 33s
    5. Rotating objects
      5m 5s
    6. Fading objects
      2m 57s
  4. 27m 14s
    1. Starting and stopping sounds
      7m 24s
    2. Showing video with FLV Player and ActionScript
      5m 15s
    3. Showing video with NetStream
      4m 19s
    4. Stopping, pausing, and resuming video
      5m 19s
    5. Seeking a cue point
      4m 57s
  5. 22m 49s
    1. Loading external SWF files
      4m 50s
    2. Adding library symbol instances to the Stage
      6m 40s
    3. Loading external images
      7m 26s
    4. Loading external text
      3m 53s
  6. 14m 36s
    1. Exploring the Code Snippets XML file
      4m 12s
    2. Modifying an existing code snippet
      3m 0s
    3. Adding a custom code snippet
      3m 41s
    4. Managing code snippet categories
      3m 43s
  7. 36m 5s
    1. Understanding template types and categories
      4m 33s
    2. Creating clickable advertising presentations
      6m 10s
    3. Reusing movie clip symbols from templates
      6m 10s
    4. Replacing content in a new file template
      6m 56s
    5. Randomizing movement in movie clip symbols
      6m 1s
    6. Scripting movement in animations
      6m 15s
  8. 18m 50s
    1. Creating a photo album
      4m 38s
    2. Creating a simple slideshow presentation
      4m 13s
    3. Creating an advanced slideshow presentation
      5m 35s
    4. Creating a desktop slideshow with Adobe AIR
      4m 24s
  9. 18m 45s
    1. Counting down dates
      3m 38s
    2. Panning a landscape
      5m 51s
    3. Revealing text with masks
      3m 48s
    4. Animating with inverse kinematics and bones
      5m 28s
  10. 42s
    1. Goodbye
      42s

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 Flash Professional CS5: Code Snippets and Templates in Depth.

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.