Skip to main content
Inspiring
March 8, 2007
Question

Finding Movie Clip Name

Hello,

I have 108 movie clips on my stage which make up a grid. The grid was generated dynamically using movieclips a while loop.

Each movie clip has been given its own unique instance name.

Now i want all the movie clips to have the same functions. I did not want to write lines and lines of:

mc1.onRelease = function () {
actions();
}
mc2.onRelease = function () {
actions();
}
mc3.onRelease = function () {
actions();
}
mc4.onRelease = function () {
actions();
}
mc5.onRelease = function () {
actions();
}

etc..etc...etc....etc.....etc
as this would make my code very long, ugly and a little difficult and time consuming to debug.

INSTEAD....

I want to know if there is a way of being able to click on any movie clip and its name will be recalled, without having to know the name of the movie clip, by using a MouseUp action or equivalent and be stored in a variable.

For example.

If i click on one of my movie clips, its name is then stored into a variable called (myButton). That variable will then act as the name of the function:

myButton.onRelease = function() {
actions();
}

the myButton variable will then tell the onRelease function which button to use its functions on. This would mean that i could use 3 lines of code instead of 300+ lines of code.

Firstly, does anyone know if this can be done? And if it can it would be greatly appreciated if you could show me how to do this.

If you are wanting to have a look at my script for a guide as to what im doing, please let me know

Thank You
Ce sujet a été fermé aux réponses.

1 commentaire

kglad
Community Expert
Community Expert
March 8, 2007
you could but why bother? if every movieclip in your swf is going call actions() why not just call actions() when a movieclip (on the main timeline) is pressed? or are there movieclips in your swf that aren't supposed to call actions()?
Inspiring
March 9, 2007
basically its a word search application i need to create.

Which is the reason for the grid and each grid has its own letters which are stored in an array and are called into the text boxes which are embedded within each squars movie clip when my script initializes. I need all the movie clips to initially have all the same actions which will eventually be., on roll over change colour, on roll out change colour, on click change colour, if correct change colour if incorrect change colour. they are the actions i will be applying.

However because each one has its own letter i also need each one to have their own unique properites which i will programme seperately.

just knowing whether i can click anywhere on the stage and find out the movie clip name so that it can then be stored into a variable would be really helpful if anyone could show me how to do this if it is possible to do.

thanks

lee
kglad
Community Expert
Community Expert
March 9, 2007
you can't click anywhere on-stage but you can click on any movieclip and store its instance name in a variable (say mcName). if you DON'T have any onPress methods defined for your movieclip you can use the following. if you have onPress methods already defined and you want both your previously defined onPress handlers and the new onPress handler to work, this can be done too.