3 Replies Latest reply on Sep 29, 2006 4:36 AM by disco-logic

    Removing and creating instances of MC's

    disco-logic Level 1
      Ive been making a little flash game to learn about it Ive got this movie clip of a bullet that I want to be able to replicate everytime something shoots.

      At the minute the only way I can work out to replicate the bullet each time is using some code like:

      (when shot is fired)
      duplicateMovieClip("_root.bullet", "_root.bullet" + this.getNextHighestDepth(), this.getNextHighestDepth());

      Now thats fine (except the bullet doesn work but that another story). Thing is to get the _root.bullet object in the first place Ive had to drag out the bullet_mc clip and give it the instance name bullet.

      There are two problems.

      1: I dont want that bullet to have to be on stage in the first place. I know I can put it outside the app area but it would be nice to know a "proper" way to get rid of it...
      Is it possible to get rid of that bullet the minute the app starts so that its never on stage.
      using bullet.removeMovieClip(); or removeMovieClip(bullet); in the main timeline's code didnt work.
      or is it possible just to not place it on stage but rather call an instance of it to duplicate each time I fire?
      Can I infact just make it such that the
      duplicateMovieClip("_root.bullet", "_root.bullet" + this.getNextHighestDepth(), this.getNextHighestDepth());
      code pulls a new instance straight out of the stored symbols?

      I cant remember what the second problem was.

      Hmm seems worth pointing out that the:
      duplicateMovieClip("_root.bullet", "_root.bullet" + this.getNextHighestDepth(), this.getNextHighestDepth());
      line of code is within another object (the cannon object suprisingly enough)
        • 1. Removing and creating instances of MC's
          disco-logic Level 1
          Hmm ok after some investigation Ive found out that whats happening is that each time I make a new instance of bullet its just putting it in exactly the same place as the old one and not doing anything.

          The examples I looked at seemed to have the bullet MC following the tank around and making a new one each time it fired. Really Id rather I could create the bullet when I fire and not have one following the tank thing around otherwise moving the tank involves moving the bullet mc around too. Plus on top of that I wanted to make a couple of different explosions for the bullet (depending what it hit) and I dont want to have to have those follow the whole arrangement around just incase they are needed.

          Basically Im asking how I can just grab an MC out the air and get it to
          1- appear with the properties I want (_x, _y, speed, _rotation etc)
          2- still follow some set code for that object

          Im thinking this might require use of seperate .as files?
          • 2. Re: Removing and creating instances of MC's
            AnandMX
            try using attachMovie instead of duplicateMovieClip as it is always error prone and tend to loose control on app.
            • 3. Removing and creating instances of MC's
              disco-logic Level 1
              hmm ok maybe the problem is that Im trying to use info from the soldier instance to set up the bullet.

              So there is code like
              this._rotation = soldier1._rotation;
              within the bullet instance
              Which by the looks of some traces Ive done just gives soldier1._rotation as undefined.

              How can I pass a value out of soldier1 to use here?