5 Replies Latest reply: May 3, 2010 1:00 PM by riquigley RSS

    as3 remove a movie clip

    I Love Doing Websites Community Member

      Hello I have in frame 7 created a movie clip:

       

      var pContainer:MovieClip = new MovieClip;

       

      addChild(pContainer);

       

      var myLoader1:Loader = new Loader();

       

      pContainer.addChild(myLoader1);

       

      var myRequest1:URLRequest = new URLRequest("flash/products.swf");

       

      myLoader1.load(myRequest1);

       

      pContainer.x = stage.stageWidth/2 - 380;

       

      pContainer.y = stage.stageHeight/2 - 180;

      my problem is that I cannot remove this same movie clip let's say in any other frame, if I go to frame2 or frame 8 the movie clip is still there on top of everything. I tried this in frame 2:

       

      removeChild(pContainer);

       

      and no luck, any answers?

        • 1. Re: as3 remove a movie clip
          riquigley Community Member

          I have found that having code run at different frames can be very problematic.  Frame 2 won't be able to remove something put in on Frame 8 because AS won't know it's there.

           

          If you can make your code work by all happening on the first frame, and just use the frame advancement for the purpose of changing the graphics, then 90% of your ActionScript issues will go away.

          • 2. Re: as3 remove a movie clip
            I Love Doing Websites Community Member

            I don't follow, how can I make show up a movie clip with action script?  lets say if I put all the action script in frame2 how would I say when in frame 7 load the swf

            • 3. Re: as3 remove a movie clip
              riquigley Community Member

              It would require re-thinking how everything progresses.  Right now, it sounds like you have everything set-up as a proceedural-based code, with the frames determining where you are in the flow of the application.

               

              If you think of the frames as being just a way of easily changing what graphics are displayed, then you virtually will have no code (except for stop() commands) on your timeline.

               

              Seems like you might be in the same spot I was about 6 months ago.  as my apps got more complicated, I switched a class-based, object oriented approach.  It took a couple of weeks to get the hang of it, but Flash hasn't worked better since.

               

              Without knowing exactly what you're doing with each frame and how the movie is supposed to work, it's hard to give specific advice.  Sorry.

              • 4. Re: as3 remove a movie clip
                I Love Doing Websites Community Member

                Thank you Sir,

                 

                as for the code, I purchased a menu that when you click it goes to a frame. That's all no more code, I only have a stop on the second frame, the first frame has a preloader, and in each of the rest 12 frames I put a keyframe with a different content. in this case I cannot use a uiloader in frame 7 because it doesn't accept my swf because is a panning animation.

                 

                Can you recommend a book or source so I can start learning about classes please?

                 

                Thanks a lot

                • 5. Re: as3 remove a movie clip
                  riquigley Community Member

                  I would say try the Essential ActionScript 3.0 Book from O'Reilly.  It breaks down the exact how and why of classes in the first few chapters, and provides plenty of examples of how to do it.

                   

                  It also has a great section about Custom Events, which is essential for Class-based programming.  It feels really awesome (in a spectacularly geeky kind of way) to write code that fire off custom events, laden with info about the event, which are then caught by objects and acted upon.  It'll make your head explode at first, but then it quickly becomes second nature.

                   

                  All the other books I have ( and I have a ton of them) typically just give you snippets of code that don't necessarily translate to an overall application.