4 Replies Latest reply on Nov 4, 2009 2:17 AM by MBR aps

    simple removeChild not working - 1120 error

    MBR aps

      Hi there, this is my first post so be gentle...

       

      I'm working on a simple presentation website in flash that imports swf-banners onto the main page. This works, but I need a backgroundcolor and a border so the banners aren't seethrough. So I create another graphic element that puts itself underneath. All this works, but when I try to write a button to remove the "child" it only removes the imported swf (loader) but it can't remove the box underneath - even if I remove the loader-child completely.

       

      I get a "1120: Access of undefined property Kant." error

       

      CODE for buttons & loading the swf:

      stop();
      var Xpos:Number=10;
      var Ypos:Number=230;
      var swf:MovieClip;
      var loader:Loader = new Loader();

       

      // Btns Universal function
      function btnClick(event:MouseEvent):void {
      MovieClip(root).Clean_mc.gotoAndPlay(2)

      var SWFRequest:URLRequest=new URLRequest(event.target.name+".swf");

       

      //mask

          var rect:Shape = new Shape();
          rect.graphics.beginFill(0xFFFFFF);
          rect.graphics.drawRect(10, 230, 930, 180);
          rect.graphics.endFill();

       

      //background and border

          var Kant:Shape = new Shape();
          Kant.graphics.lineStyle(2,0xFFFFFF);
          Kant.graphics.beginFill(0x000000);
          Kant.graphics.drawRect(10, 230, 930, 180);
          Kant.graphics.endFill();

       

      //swf loader
          loader.load(SWFRequest);
          loader.x=Xpos;
          loader.y=Ypos;
          //loader.background = true;
              //loader.backgroundColor = 0xFFFFFF;
          loader.mask=rect;

       

          addChild(Kant);
          addChild(loader);
      }

       

      H3K.addEventListener(MouseEvent.CLICK, btnClick);
      AAOO.addEventListener(MouseEvent.CLICK, btnClick);
      Metro.addEventListener(MouseEvent.CLICK, btnClick);
      Jonas.addEventListener(MouseEvent.CLICK, btnClick);
      CS.addEventListener(MouseEvent.CLICK, btnClick);
      BEP.addEventListener(MouseEvent.CLICK, btnClick);
      WSGM.addEventListener(MouseEvent.CLICK, btnClick);

       

      Code for "resetting" page:

      removeChild(Kant);
      removeChild(loader);

       

      It's probably very simple, but I can't get it to work. Please help me fix it, so I can go home early...

        • 1. Re: simple removeChild not working - 1120 error
          Ned Murphy Adobe Community Professional & MVP

          The code for adding the stuff to the page isn't the issue as far as I can tell.  It appears to be more a problem with the code to remove things, which is evidenced by the error messge... chances are that code is active when it shouldn't be, so you probbably need to check if the children exist before trying to remove them.  How/where is the removeChild code implemented?

          • 2. Re: simple removeChild not working - 1120 error
            MBR aps Level 1

            I have two frames in my main file, where most of the code is in frame 1. When I call the swf a button appears. The button then links to frame 2. The removeChild is placed as an action in that frame - so the 'Child' should be present every time the 'remove'-action is called. Besides, it works when removing the swf-file (loader) which are add'et and removed the same places...

            • 3. Re: simple removeChild not working - 1120 error
              Ned Murphy Adobe Community Professional & MVP

              The problem is the scope of the Kant object is limited to within that function.  If you declare it outside of the function like you do for the loader, you should be okay...

               

              var Xpos:Number=10;
              var Ypos:Number=230;
              var swf:MovieClip;
              var loader:Loader = new Loader();

              var Kant:Shape;

               

              // Btns Universal function
              function btnClick(event:MouseEvent):void {
              MovieClip(root).Clean_mc.gotoAndPlay(2)

              var SWFRequest:URLRequest=new URLRequest(event.target.name+".swf");

               

              //mask

                  var rect:Shape = new Shape();
                  rect.graphics.beginFill(0xFFFFFF);
                  rect.graphics.drawRect(10, 230, 930, 180);
                  rect.graphics.endFill();

               

              //background and border

              Kant = new Shape();

              • 4. Re: simple removeChild not working - 1120 error
                MBR aps Level 1

                It works and you're awesome! Thanks a lot.