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

Creating code snippets

From: Flash Professional CS5 New Features

Video: Creating code snippets

With the Code Snippets panel, you can also create custom code snippets. We'll take a look at an example in this movie. One of the snippets, in the Code Snippets panel, is for keyboard control of an object. So you can use that in something like a game, to move an object around. However, the functionality is a little bit limited. I added some functionality to the keyboard control. In this movie, we'll look at making that into a custom code snippet. Let's take a look at the code I have in the Actions panel. Here, I have all the code for keyboard control.

Creating code snippets

With the Code Snippets panel, you can also create custom code snippets. We'll take a look at an example in this movie. One of the snippets, in the Code Snippets panel, is for keyboard control of an object. So you can use that in something like a game, to move an object around. However, the functionality is a little bit limited. I added some functionality to the keyboard control. In this movie, we'll look at making that into a custom code snippet. Let's take a look at the code I have in the Actions panel. Here, I have all the code for keyboard control.

At the very bottom, I'm adjusting the x and y position of an object, and the object is instance_name_here. Note that it is red, and that's significant. We'll take a look at that in just a minute. Wherever you want to have the instance name of an object that's going to be manipulated, you need to put instance_ name_here inside of the Actions panel and make sure that it's red. That means you typed it correctly. So once you have your code, select it all, using your computer's keyboard shortcut, and then you can open up the Code Snippets panel.

I like to open it up directly from the Actions panel. To create a custom snippet, all you have to do is go to the Options area of the panel, toward the top-right, and then choose Create New Code Snippet. Here, you can choose a Title and a tooltip and choose whether to use code selected in the Actions panel. I'll click Auto-fill to do that. For the Title, I'll call this Advanced Keyboard Control, and then I'll type for the tooltip, 'Control an object with the keyboard.

Change speed variable to update speed.' And then I'm going to choose the check box that says Automatically replace instance_name_here when applying code snippet. So I'll check that box and then click OK. In the Code Snippets panel, you'll see there's a new folder called Custom, and if you expand it, you'll see Advanced Keyboard Control. To apply it, I'm first going to delete the Actions layer, and then I'll double-click Advanced Keyboard Control. Since I didn't have the object selected on the stage, I'm informed that this action requires an object to be selected.

So I'll select the instance on the stage. Note that its instance name is biker, and then I'm going to double-click Advanced Keyboard Control. Code is then added to the Actions panel, and if I scroll all the way to the bottom, the instance name is inserted in there instead of instance_name_here. So my code is ready to go. All I had to do is select an object on the stage and then double-click. So I'll test the movie, and using my keyboard, I'll move the biker on the stage. So when you're working with the Code Snippets panel, you can add new snippets by writing the code out, selecting it, and then choosing Create New Code Snippet from the Options area of the Code Snippets panel.

All of this data is actually saved in an XML file, which you can edit if you choose Edit Code Snippets XML. If you ever want to reset to default, you can choose Reset to Default XML to delete your custom snippets. You can also import, as well as export, code snippets. So with the Code Snippets panel, you can create customized code snippets, and you can easily reapply them to objects on the stage.

Show transcript

This video is part of

Image for Flash Professional CS5 New Features
Flash Professional CS5 New Features

27 video lessons · 11814 viewers

Todd Perkins
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 Flash Professional CS5 New Features.

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.