4 Replies Latest reply on Apr 6, 2007 11:01 PM by Vertine

    detecting other mc's from a class

    Vertine
      i am making my first game. i have a simple class issue that i don't understand. In the game, the user has to "hang" bikes on hooks. Thus, a simple drag/drop mousevent. The problem i have is detecting the hook mc's on the stage. How do i refrence what/which mc is in contact with the bikes? Each hook mc is named ["hook_"+i]- i being a number from a loop. Ok, so what i have thus far i do not like becuase the mc's are limited to only those named "hook_".... ineed to be able to detect anything it is released upon

      -sorry for the double post...i could not find a place to "move" it.

        • 1. Re: detecting other mc's from a class
          MotionMaker Level 1
          Use an array to track all targets. Loop the array in checkPlace() to see which is hit.

          A bit further
          Your might use a generic Object or a class to define each entry in the array. As such you can know the target mc and an identifier as to the state and action to take for that array entry.
          • 2. Re: detecting other mc's from a class
            Vertine Level 1
            Thanks..sounds like i am on the right track: 2 questions...would such a looping array slow things down. And, is there a method that looks at the objects class? For example, onRelease would have a function that looks to see if the object "below" is a MovieClip, TextField, etc....much like you can use getDepth() to know an objects depth...is there an equivalent to getClass()???
            • 3. Re: detecting other mc's from a class
              MotionMaker Level 1
              I guess the size of the array is the issue. You can easily performance test that against the total number you expect without developing the entire code or even using the code above.

              As I hinted, when you push onto the array, push an Object variable (or a custom class). One propery of the class would include the reference to the MovieClip or TextField. Then you can have another property identifying its type if you like and more properties and methods that determine what ever.

              You might create a loop for each class of object as in the attached code.

              A step above a generic Object is to create a class to define your objects and link to the class to a MovieClip symbol. Then you instantiate those and their instance variable is all you need to push to the array. A more sophisticate OO model might include an interface to define the similarities of the targets and then you build each type of a target as a MovieClip and link the appropriate class.

              • 4. Re: detecting other mc's from a class
                Vertine Level 1
                thanks mm...i am on the right track now, and the Bike Class is now detecting hooks, and there specific properties....time to get to work