8 Replies Latest reply on Jan 19, 2007 3:51 PM by wesm9787

    attachmovie code

    wesm9787
      i'm trying to do a basic fighting-type game in flash. so far i have the preloader, the enter your name box, the code so it won't let you continue until you enter your name, and the code so that guy moves, the code for the bounding box so people can't leave the screen, and the code so that the different movie clips for each movement are attached when the right, left, up, and down keys are pressed (like when you press the right arrow it makes him move right and the walking right movie clip is attached)... and i have the code so it goes back to the original standing position when you release the key. the only problem is when he moves to the right the movie clip doesn't play... he just moves over and doesn't walk. so far here's the code i have for the moving part...

      onClipEvent (load) {
      moveSpeed = 7;
      this.attachMovie("man", "man", 10);
      }
      onClipEvent (enterFrame) {
      if (Key.isDown(Key.RIGHT)) {
      this._x += moveSpeed;
      this.attachMovie("moving_mc", "moving", 10);
      } else if (Key.isDown(Key.UP)) {
      this._y -= moveSpeed;
      this.attachMovie("moving_mc", "moving", 10);
      } else if (Key.isDown(Key.DOWN)) {
      this._y += moveSpeed;
      this.attachMovie("moving_mc", "moving", 10);
      } else if (Key.isDown(Key.LEFT)) {
      this._x -= moveSpeed;
      this.attachMovie("moving_mc", "moving", 10);
      } else {
      this.attachMovie("man", "man", 10);
      }
      if (this.hitTest(this._parent.leftwall)) {
      _x = _x+10;
      }
      if (this.hitTest(this._parent.topwall)) {
      _y = _y+10;
      }
      if (this.hitTest(this._parent.bottomwall)) {
      _y = _y-10;
      }
      if (this.hitTest(this._parent.rightwall)) {
      _x = _x-10;
      }
      }

      i have no idea why the movie clip isn't playing (i don't have a lot of experience with flash but i've been learning a lot about it lately) so maybe someone could explain to me why it doesn't work or if i'm using the wrong code give me the wrong one. i tried a few different codes from tutorials but so far none of them worked. i figured they were just outdated though since a lot of them seem to be (i'm using flash professional 8). anyway, any help with this would be appreciated. thanks
        • 1. Re: attachmovie code
          kglad Adobe Community Professional & MVP
          does moving_mc have a stop() in its first frame? if not (and it has more than one frame with different graphics in the different frames) the frames should advance and you should be able to see that the frames are changing because the graphics on-stage change.
          • 2. Re: attachmovie code
            wesm9787 Level 1
            no i didn't put a stop () in any of the frames, i forgot to mention it does play but not until i release the button. or at least it did before i added the code to make it go back to the standing movie when i let go of the key. i want the movie to play while i'm holding down the direction, then stop playing when i let go. i got the stop playing part... i just can't figure out how to make it play while i'm holding down the key. i don't know if there's a different code instead of the if (Key.isDown) or if there's another part i'm supposed to add to that or what
            • 3. Re: attachmovie code
              kglad Adobe Community Professional & MVP
              the timeline of a movieclip advances by default. it won't stop unless you're doing something to make it stop.

              in that situation you can use:

              • 4. Re: attachmovie code
                wesm9787 Level 1
                attach that code where? in the frame, the object, or the actual movie clip? i have a stop() on the first frame so that the file stops playing on the first frame, and then i want it to play a movie clip while a directional button is being held down (so he looks like he's walking when you're holding the button instead of just hovering over to the left or right or whatever). i can't figure out why the movie clip doesn't play until i release the key and not while i'm holding the key down. so am i supposed to put that code somewhere in the one i'm already using on the original movie clip in the first frame (the one of the guy just standing) or the movie clip of the one where he's walking?
                • 5. Re: attachmovie code
                  kglad Adobe Community Professional & MVP
                  it doesn't play because you keep attaching it. so, you're seeing a new movieclip replacing the previous one before the timeline can advance on the previous one.
                  • 6. Re: attachmovie code
                    wesm9787 Level 1
                    ok... so you're saying it's attaching the movie clip over and over again while i'm holding down the button? that would explain why it doesn't play until i release the key... so how do i get around that? i know it can be done i just don't know how. is there a code i can use where it attaches the movie when the key is pressed? i know how to remove the clip once the key is released but i couldn't figure out how it make it play a clip when the key is pressed down besides the way i posted above
                    • 7. Re: attachmovie code
                      kglad Adobe Community Professional & MVP
                      try:

                      • 8. Re: attachmovie code
                        wesm9787 Level 1
                        ok well i figured it out... what i ended up having to do was i put the movie clip "man" on frame 1 of the timeline, and put a stop on frame 1. then i put the code to make him move left and right and everything on the actual movie clip, and the code to attach the movie for moving when the arrow keys are pressed on the first frame with a key listener (key.Listener = function(){ if(Key.getcode()==Key.RIGHT)}, blah blah blah, or whatever it is, i forget exactly what it is off the top of my head so that could be completely wrong, but i know i have the right code in my actual document).

                        anyway i had to increase the frame rate and add an updateAfterEvent code after all that so it would keep replaying the movie clip. so i then took that frame and added it to my original document where it has the preloader, the enter your name screen, the little "thank you message", a temporary instructions page where it just tells you to move the guy by pressing the arrow keys, an ok button that takes you to the next frame, and now the frame with the guy that moves. now i just have to figure out how to make a list of selectable characters

                        i'm assuming you just make a button out of the picture of each character and add an attachmovie code to the button or something along those lines, so when you click the picture the little guy appears below. then have an ok button to make him go to the next frame, hitTest to determine if the character has been hit, life bar goes down, all that.

                        only thing i don't know is how to link the attack movie clip to the hitTest code so that the only character that takes damage is the one being attacked. basically i need to make it so if the hitTest returns true and one of the characters is attacking the one not attacking loses life, otherwise the character attacking would lose health when he attacks and they would both lose health when they just bumped into each other without attacking, and every fight would end in a draw. so how do i do that?