4 Replies Latest reply on Apr 15, 2011 7:14 PM by Rothrock

    Attach movieclip to stage

    prodigalmaster Level 2

      Here is my code, I dont know why it doesnt f'ing work?


      function newBomb() {

      var newBomb = attachMovie("bomb", "bomb");

      newBomb._x = 200;

      newBomb._y = 200;




      Please tell me what stupid thing i've done.

      And yes, the linkage/properties of the movieclip in the library are correct (linkage: bomb).

        • 1. Re: Attach movieclip to stage
          Ned Murphy Adobe Community Professional & MVP

          Try to avoid using the same names for different things and see if that works.  Don't name the instance the same as the linkage, and don;t name the variable the same as the function.

          • 2. Re: Attach movieclip to stage
            prodigalmaster Level 2

            not working


            function newBombFunc() {

            var newBomb = attachMovie("bomb");

            newBomb._x = 200;

            newBomb._y = 200;





            is this a bug or is there something little wrong?


            ok so

            newBomb = attachMovie("bomb", "bombName", 1);

            newBomb._x = random(Stage.width);

            in a clean .fla works

            but in the .fla im working on, it doesnt work, even with the same movieclip in the library... idk what to do. I have already attached a previous movieclip with a different name IDK if this affects it.

            Im sure its another bug.

            • 3. Re: Attach movieclip to stage
              Ned Murphy Adobe Community Professional & MVP

              It might be a bug with your file, either your code or the file might be corrupted, but it is not likely a bug in Flash.

              1 person found this helpful
              • 4. Re: Attach movieclip to stage
                Rothrock Level 5

                You can't just drop parts of the method signature. Attach movie needs all of its required arguments. Also it is generally a good idea to actually use the method of the MovieClip class.


                var newBomb:MovieClip=someInstanceName.attachMovie("LinkageID","newName",depth);



                The trace will show you if the attaching was successful—at least from Flash's point of view. If that trace works then you need to look at other things. If it doesn't work then you need to look at the attachMovie.


                Generally I start likage IDs with a Capital letter. That sort of mirrors how class names are always capital, MovieClip, Array, etc.


                I usually start the new name with a lower case letter.


                The depth needs to be a positive number between 1 and 2,400,000 or so. (Well it doesn't need to be, but you will have all kinds of other problems if you go negative.) Since you haven't specified which scope, timeline, movieclip you are attaching this to, and because we haven't seen the rest of the code we can't tell if something else is trying to use the same depth.


                I'll take what Ned said a little bit further. It is almost never a bug it is almost always a problem with the programmer. Flash doesn't do what we want it does what we tell it!