1 Reply Latest reply on May 28, 2008 11:20 AM by theTraveler3

    "generic" MC

    cre8ive1974 Level 1
      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()

      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?

        • 1. "generic" MC
          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.