Tip:
Highlight text to annotate it
X
instance names of symbols are very important when working with action
script three point o
they allow you to target specific objects and tell them exactly what to do
in your code
to give a practical example of this
imagine your at an event and it's full of people doing a variety of
things and you yell out hey
stop doing that
if you did that
you wouldn't have much success because either no one would listen
or they would all stop in confusion
this is because they don't know number one
who you're talking to and number two
what you want them to stop doing
however
if you were to yell something like
RENAE don't throw that booklet away
you would have a greater chance of success
that direction targets someone by name and give them a specific instruction
instance names perform the same function
let's see this in action
in this solar system game that i've created
we have a game where the first page has the solar system title ADIMATE in
then we have the directions and have them enter an astronauts name
and then we have scrambled planets and scramble labels that they need to put
in order
from the closest to the sun to the furthest away from the sun
and last we have the answers screen
now you'll notice that
on the last two pages
i have two of each planet and two of each label
that doesn't mean i have two Saturn movie clips
i actually only have
one Saturn movie clip
but i've used it twice
the problem is if i want to start adding script to this movie clip
or in my
flash file so that it targets that movie clip so i can drag and drop it
it's going to become a problem because i have two instances of that movie clip on
the stage
so i can't just say
make the movie clip mc saturn
drag-and-drop
because then that it's going to get CONFUSED because it doesn't know which one you
mean which one is the one that you want a drag and drop
so we're gonna target this one specifically
by giving IT an instance name
instance names can be found in the properties panel first so you have to
make sure you selected that movie clip on the stage
so when i clicked this saturn movie clip
i can call this one
saturn
move
this is the one i want to have the user move
if i go to this page and click on this instance of saturn you'll see that it
doesn't have an instance name because even though they came from the same
movie clip
there to instances of that movie clip on the stage
so this one if i wanted to i can call this saturn
answer
because this is just they're not gonna drag and drop it
it's just the answer of to where it is in little the order of
planets
now i can target this specifically with drag-and-drop action script if i double
click this actionscript
in the CODE SENDS PICS
you'll see that it automatically added the instance name and said
for the object with the instance name of Saturn move
if the user presses their mouths down
then let them drag it
and then it says on the stage
if there's a mouse up
release it to drop
the Saturn move
so this is generally where I will take this instance name
copy it
and paste it
so that we're targeting that one specifically
so that way flash knows it's not this one that we want to move
it's specifically this instance of that movie clip
LET'S see this one more time
i don't have Jupiter on here yet i have the movie clip Jupiter
and i want one
on this screen
and i want another one
on this screen
and now that's a super big planet so technically it's supposed to be
a little bit smaller
so it's easier to work with
but when i come back to this screen
for this one
i need to call this one
jupiter
move
and then add my action script and that will make sure
that you are in fact targeting this particular instance of that planet
now if you forget to do an instance name sometimes flash
helps you out with that if i click on well lets click on Neptune
and i can doubleclick drag-and-drop
and it's going to say this selected symbol requires an instance name
so I'll call this one Neptune move
and click ok
now all of a sudden you can see that action script
and it used my instance name
to target that object specifically
so make sure when you're working in flash that you were using instance
names
for all of the things that you want to target with actionscript
so that can include buttons if i look here this button has an instance name of
PLAY
BTN
and if i look on the action script for that
I'm targeting
that instance of that button
and have an event listener
that when somebody clicks
it's going to go to the next frame
so same thing with all of these
this one has an instance of start button
and when i click here all
of a sudden the action script is referring to that object
by its instance name
not by the name it's given in the library or the movie clip name
so if i come over here you can see my movie clip name for the start button
is BTN start
but my instance name
again
is start BTN and that's what it's referring to
so make sure you have everything that you want to target with action script
make sure it has
a instance name in order to be successful