5 Replies Latest reply on Jun 20, 2007 5:58 PM by kglad

    Instantiating a movieclip not working?

    Rusherific
      I've been out of the Flash game for a while and I'm just learning AS 3.0 so work with me here. I have an existing movieclip in the library that I'm simply adding to the stage like so:

      var mc1:mcname = new mcname();
      learn1.x = 583;
      learn1.y = 144;
      addChild(mc1);

      However this doesn't work in my existing project. I made a new flash file to test and do this it works fine, but it wouldn't in my project. I did some troubleshooting and found that no matter what layer I put this AS on it wouldn't show up unless I deleted any and all my layers that use masks?? What does that have to do with anything?
        • 1. Re: Instantiating a movieclip not working?
          kglad Adobe Community Professional & MVP
          are you adding mc1 to a masked object? ie, is that code located on a timeline that's masked?
          • 2. Re: Instantiating a movieclip not working?
            Rusherific Level 1
            Thanks for the response, but no, and if it were that AS would disappear itselft when I deleted the masked layers. I tried switching to

            addChildto(mc1, 5);

            Which works for now, but why I don't know. I guess I'm confused about this new displayobjectcontainer business in general. Since AS can no longer be associated with an object, and only keyframes, what exacly is it adding a child to? The stage? How do I specify a container? The docs are woefully sketchy on this as always. I've tried using other displayobjects or movieclips as a container but I get errors and doubt I'm doing it right. All of which doesn't explain to me why even if I use plain old addChild() it will show up on top of 21 layers no matter where I put it as long as I have no masked layers but not show up if I have (entirely unrelated) masked layers in there at all...
            • 3. Re: Instantiating a movieclip not working?
              kglad Adobe Community Professional & MVP
              i assume you meant addChildAt(mc1,5) which is the same as

              this.addChildAt(mc1,5). and, in general, when you don't specify a displayobjectcontainer (doc) while coding in a flash frame, the stage that contains that frame is the default doc.

              you can always specify your doc by using:

              doc1.addChild() or doc1.addChildAt().

              and this works just like flash 2:

              doc1.addChild(doc2);
              doc1.doc2.addChild(doc3);
              doc1.doc2.doc3.addChild(doc4);

              // and unlike as2, you can stagger these displayobjects as follows:

              doc2.x=10;
              doc3.x=10;
              doc4.x=10;

              now, if you use addChild, the depth of the first display object added to a doc is 0. each subsequent displayobject added is placed at increasing depths.

              so, just why your making worked when mc1 was added to depth 5 and not when added to depth 0, must depend upon some circumstances specific to your masking. do you know what that is?
              • 4. Re: Instantiating a movieclip not working?
                Rusherific Level 1
                I have no idea. Really I have just have three masked layers all of which are completely dumb and static (except for some timeline keyframing) involving no AS anywhere, and are on entirely un-conflicting areas of the stage from my mc, so I couldn't tell you! Getting rid of just one or some combo of them doesn't work either--I have to delete all of them to not have to use addChildAt 5
                • 5. Re: Instantiating a movieclip not working?
                  kglad Adobe Community Professional & MVP
                  what if you use addChildAt(mc1,0) or addChildAt(mc1,this.numChildren)?