3 Replies Latest reply on Dec 27, 2010 11:16 AM by kglad

    gotoAndPlay nested movie clip in class.

    KerShmuckit

      Hi guys. Im relatively new to AS3 and im currently making a shooting game.

       

      I have a class controlling all my targets, I want to play a death scene for each target when they get shot. My targets involve several nested movie clips, I want to put the death scene on the second level of my targets nested clips.

       

      What code do I use to tell flash to go to the second level in my targets and play there?

       

      Here is my class code in it's entirety. I have highlighted the part thats currently playing my targets.

       

      package {
      import flash.display.MovieClip;
      import flash.events.Event;
      import flash.events.MouseEvent;
      import flash.media.Sound;

       

      public class SquaresClass extends MovieClip
      {
      function SquaresClass()
      {
      this.addEventListener(Event.ENTER_FRAME, frameUpdate);
      this.addEventListener(MouseEvent.MOUSE_DOWN, shootMe);
      }

       

      function frameUpdate(e:Event)
      {

       


      if(this.currentFrame == 1)
      {
      if(Math.random() < 0.02)
      this.gotoAndPlay(2);

       


      }

       

      }

       

      function shootMe(e:MouseEvent)
      {


      gotoAndPlay(40);


      }

      }
      }

       

       

      I've done a bit of reading but because im still a beginner alot of it was hard for me to understand. Something about using addFramescript?

       

      Thanks in advance.

        • 1. Re: gotoAndPlay nested movie clip in class.
          kglad Adobe Community Professional & MVP

          there is no second "level" in a movieclip.

           

          you have a movieclip that has a child movieclip and that child movieclip (eg, child_mc) has a child movieclip (eg, grandchild_mc) that you want to control?  if yes, assign instance names to the children and use dot-notation:

           

          child_mc.grandchild_mc.gotoAndPlay(40)

          1 person found this helpful
          • 2. Re: gotoAndPlay nested movie clip in class.
            KerShmuckit Level 1

            I understand what your saying, but I want my code to apply to all my targets not just a specific one, if i used that code it'd only play a death scene on the one target I was specifying.  At the moment my code targets all my movies clips that I export to have my class as its base class and when i click on one, it goes to frame 40, on the movie clips timeline, whatever target it may be. But in my 'parent' movie clip thats where i've tweened the targets moving, my death scenes for each target are in a 'child' movie clip. I want the playhead to go there and the code needs to be inclusive to all my targets. I hope you understand what im getting at!

             

            Thanks for your reply.

            • 3. Re: gotoAndPlay nested movie clip in class.
              kglad Adobe Community Professional & MVP

              if each SquaresClass member had those children, that coding would work for each.

              1 person found this helpful