dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: simple removeChild not working - 1120 error [AS3]

Hybrid View

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    7

    simple removeChild not working - 1120 error [AS3]

    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:

    Code:
    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:


    Code:
    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...

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    for the time being comment out your removeChild() calls .

    like

    Code:
    //removeChild(Kant);
    //removeChild(loader);
    and replace them with trace statements

    Code:
    trace(Kant);
    trace(loader);
    test your movie. When the application outputs the traces , are either of the values null , or do you get an alert saying something about a null object reference ?

    I think your problem is you are declaring "Kant" , inside of your btnClick() function. The reason its able to remove your loader, is because you are declaring and instantiating it at the top , outside of your method , so the variable becomes available to anything in that scope. Try to declare Kant underneath loader. See if it works.
    Last edited by AttackRabbit; 11-02-2009 at 11:46 PM.

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166
    what class is your adding graphics and which class is the removeChild on?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center