1 Reply Latest reply on Oct 18, 2007 7:22 AM by clbeech

    Attached MovieClip

      I have an issue with ActionScript and linking it back to a movieclip. I hope you guys can help.

      I bring a movieclip in from the library as follows:

      on (release) {
      if (_root.HaloMouseD == 2) {
      HM += 1;
      HaloM = attachMovie("HaloM", "HaloM"+HM, HM++);
      HaloM._x = _xmouse;
      HaloM._y = _ymouse;

      So, it "spawns" fine, and the movie clip goes to where the mouse is located when is pressed. The issue, however, is having it hit another object on a hitTest. I have an "Orb" with the following code:

      onClipEvent (enterFrame) {
      if (this.hitTest(HaloM)) {

      Is there anything wrong with the above code? It doesn't work at all, and I have no clue why. The orb is just sitting on the stage so far, but it will also be "spawned" by attachMovie, so basically what I'm asking is how do you add ActionScript to a movieClip that had been taken from the library by attachMovie?

        • 1. Attached MovieClip
          clbeech Level 3
          well this is due to the name of the attached Object not being 'HaloM', in the attachMovie method you have ('HaloM'+HM) so the 'name' of the new MC is 'HaloM'+the current value of HM. additionally I don't think you should use the increment operator within the attachMovie statement (eg ++) you've also already increased that value on the previous line.

          a couple of ways to fix this. first if there will never be more than one 'HaloM' on the Stage at a time then just use that as a name and leave the HM var off the instance name, additionally you then can also place it at the same depth level. second however, is that if there will be more than one HaloM on Stage at a time, you need to check all instances of them against the 'Orb' right, so you will need to run a loop within the enterFrame event, which also means you will need to store references to all of the HaloM(s) on Stage currently, and you would do so with an array. third, you should place these on handlers on the main timeline for easier referencing and path linkages. Also, 'unloadMovie' should not be used here since the MC was not 'loaded' but attached, you should use 'removeMovieClip()'. I think I would write this code as follows, from the timeline: