Skip to main content
Inspiring
May 28, 2008
Question

"generic" MC

  • May 28, 2008
  • 1 reply
  • 296 views
Is there a way to use a "GENERIC" name for all MC's

example: instead of this
_root.myClip.hit1.onPress = function()
_root.myClip.hit2.onPress = function()
_root.myClip.hit3.onPress = function()
_root.myClip.hit4.onPress = function()
etc..

can it be done like this
_root.myClip.GENERIC.onPress = function()

with GENERIC somehow assigned the hit1, hit2, hit3, hit4 elements etc..

I thought about an array but I can't seem to get it to work.

Is this even possible?

Thanks!
D
This topic has been closed for replies.

1 reply

Participating Frequently
May 28, 2008
You could assign those functions iteratively:

for(var i:Number = 1; i <= 4; i++) {
var path:MovieClip = eval("_root.myClip.hit" + i);
path.onPress = function();
}

Or if you want to do that generalization, you should link that "hit" movieClip to a "Hit" class.
Define a class file which extends MovieClip, add a general onPress. In your library, under the movieClip's properties, you want to link it to the "Hit" class. This means that the instant they are created, they have a default onPress.