by
kirupa | 19 July 2010
In the
previous page, you received an introduction to code
snippets and learned how to access the Code Snippets panel
in the Flash CS5 panel.
According to how I use code snippets, the most common way to
add a code snippet is to look at something that you are
interested in and copy it to your clipboard for pasting in
the appropriate location in your code later.
To copy a code snippet, from the Code Snippets panel,
find a code snippet you are interested in and select it:
[ select a code snippet you want to use ]
Once a snippet is selected, click on the Copy button
found in the top-left corner of your Code Snippets panel:
[ go ahead and copy a code snippet first ]
Click on that copy button to copy your snippet into
memory. A dialog will appear with suggestions on what you
can do with your copied snippet:
As the dialog says, you can copy this snippet into your
Actions panel or AS file, but you can actually pretty much
paste this snippet anywhere that you want. It is just some
text stored in memory.
Below is a scaled down view of my Actions panel where I
pasted my code snippet:
[ what my pasted snippet looks like ]
You can also copy a code snippet by just right-clicking
on a snippet in your Code Snippets panel and selecting Copy
to Clipboard:
[ all the cool kids actually use the right-click menu ]
The end result would be exactly identical to the behavior
you would have had when you clicked on the Copy button to
copy your code snippet instead.
Besides copying a code snippet to your clipboard for pasting
later, you can associate a code snippet with a particular
object. That�s what the first button found to the left of
the Copy button does:
[ the insert a frame button ]
You need to have an element selected on your artboard in
order to do this, and if your selected element isn�t an
object with an instance name, it will automatically be taken
care off for you.
The only advantage of using this approach over the Copy
to clipboard approach is that some of your code snippets
will auto-fill the instance name of your selected element to
save you from having to manually type it in.
Code snippets
provide some much-needed assistance to help you navigate
some of the common pieces of ActionScript that you can
easily forget. While this article only talked about how to
consume code snippets, note that you can actually create
code snippets as well as import code snippets from a 3rd
party! Pretty cool.
Just a final word before we wrap up. If you have a question and/or want to be part of a friendly, collaborative community of over 220k other developers like yourself, post on the forums for a quick response!
|