Skip navigation
blk.sheep
Currently Being Moderated

stage=null

Nov 14, 2011 9:07 AM

Hi,

 

Loading an swf into a container swf, I'm getting the the #1009 error. I'm new to this syntax so I don't think I have it correct: The reisze listener is firing, and from the container swf I'm returning the trace

 

parent is null

stage is null

 

but my trace in the the listener using ADDED_TO_STAGE doesn't return anything at all. I'm not using classes.

 

Code for the external swf:

 

stage.addEventListener(Event.ADDED_TO_STAGE, ini);

 

function ini(e:Event):void { 

    removeEventListener(Event.ADDED_TO_STAGE, ini); 

    trace("stage after added to stage -" + stage);

}

 

 

stage.addEventListener(Event.RESIZE, resizeHandlerNews2);

function resizeHandlerNews2(e:Event){

        //stage.addEventListener(Event.ADDED_TO_STAGE,resizeHandlerNews2);

       

        trace("parent is " + parent);

        trace ("stage is " + stage);

        if(parent != null)

        trace("parent.parent is " + parent.parent);

       

    //var sw:int = int(stage.stageWidth);

    //var sh:int = int(stage.stageHeight);   

}

I understand I need to get the stage to the display list to kill the null, and am perhaps a little confused as to why this wouldn't work.

 

thank you -

 
Replies
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 9:17 AM   in reply to blk.sheep

    Event ADDED_TO_STAGE is used in time when stage is not set. You don't add it to stage but to current object. This should work:

     

    addEventListener(Event.ADDED_TO_STAGE, ini);
     
    function ini(e:Event):void { 
        removeEventListener(Event.ADDED_TO_STAGE, ini); 
        stage.addEventListener(Event.RESIZE, resizeHandlerNews2);
     
        trace("stage after added to stage -" + stage);
    }
     
    function resizeHandlerNews2(e:Event){
            //stage.addEventListener(Event.ADDED_TO_STAGE,resizeHandlerNews2);
     
            trace("parent is " + parent);
            trace ("stage is " + stage);
            if(parent != null)
            trace("parent.parent is " + parent.parent);
     
        //var sw:int = int(stage.stageWidth);
        //var sh:int = int(stage.stageHeight);   
    }
    
     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 10:12 AM   in reply to blk.sheep

    Allright, different angle: Tell me what exactly are you trying to achieve and paste code from LOADER swf and from LOADEE swf. So I can see thich one does what.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 2:59 PM   in reply to blk.sheep

    Locate this piece of code in (each) loadee:

     

    function ini(e:Event):void {  
        removeEventListener(Event.ADDED_TO_STAGE, ini);  
        trace("stage after added to stage -" + stage);
    }
     
    stage.addEventListener(Event.RESIZE, resizeHandlerNews2); 
    

     

    and replace it with this:

     

    function ini(e:Event):void {  
        removeEventListener(Event.ADDED_TO_STAGE, ini);  
        trace("stage after added to stage -" + stage);
        stage.addEventListener(Event.RESIZE, resizeHandlerNews2); 
    }
    

     

    You have to access stage after the loadee was added to stage. I believe it will work now.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 3:44 PM   in reply to blk.sheep

    In publish settings, is there Omit trace actions checked? You added the loaders to stage so anything you load should definitely fire addedToStage handler.

    Try a little check - put this code inside a loadee:

     

    addEventListener(Event.ENTER_FRAME, temp);

     

    function temp(event:Event):void {

         trace("stage: " + stage);

    }

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 3:59 PM   in reply to blk.sheep

    put the trace statement outside the function - what does it say?

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 4:14 PM   in reply to blk.sheep

    So what was the problem in the first place?

    It seems we don't have a problem at all :?

     

    Change the code from

     

    addEventListener(Event.ADDED_TO_STAGE, ini); 
     
    function ini(e:Event):void {  
        removeEventListener(Event.ADDED_TO_STAGE, ini);  
        trace("stage after added to stage -" + stage);
        stage.addEventListener(Event.RESIZE, resizeHandlerNews2); 
    }
    

     

    to

     

    stage.addEventListener(Event.RESIZE, resizeHandlerNews2); 
    

     

    and it should be allright

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 4:16 PM   in reply to blk.sheep

    If any other error pops up, make sure you set "Permit debugging" to checked in Publish settings and paste the whole error message here. If you permit debugging, the error will tell you which line is wrong so you can locate it.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 14, 2011 4:39 PM   in reply to blk.sheep

    stage: [object Stage]

    stage: [object Stage]

    stage: [object Stage]

    stage: [object Stage]

    Outside of the temp function:

     

    stage: [object Stage]

     

    I don't see "null" here.. it would be best if I had direct access to the files.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 15, 2011 10:06 AM   in reply to blk.sheep

    I found the problem. The null references to stage in resizeHandler were actualy called from the previous swfs you loaded. Once you bound your swf with the stage through the listener, it can't be removed from memory after you're done using it. You always have to remove all listeners on object that you don't want to use anymore.

     

    I added destroy() funciton in your loadee - you should copy it to all loadees. And also changed the loader a bit, you'll find it, just search for "destroy".

     

    You can download fixed sources here: http://files.flashlabs.eu/stage_null_fixed.zip

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 16, 2011 12:05 PM   in reply to blk.sheep

    I can't compile news.fla because I'm missing RSSParser.as. Can you chare it as well?

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 16, 2011 2:24 PM   in reply to blk.sheep

    Well there's apparently more: now it wants some MailingList... don't you have those classes in one place so you can give it to me at once? And you don't have to pack FLAs again.. just classes.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 16, 2011 4:12 PM   in reply to blk.sheep

    FIXED.

     

    I expanded the destroy function - since your code executes after few frames play, I added stop() in the destroy so we prevent the code from executing while the movie is considered destroyed.

    I also cleared the loader, removed its listeners and removed it from stage. You have to always remove all listeners in destroy method on all objects.

    And finally, in index.fla I added a variable _currentLoader with getter and setter since you have multiple loaders and load them at multiple locations. The setter basically clears previous loader and calls destroy upon its content.

    Don't forget to modify all loadee destroys according to this one: stop() and remove listeners. Take a look how I handler bannerindex - I put an IF statement there because destroy() can be called even before the last frame with script executed, thus bannerindex might still not be initialized and we would get null reference error.

     
    |
    Mark as:
  • Peter Celuch
    505 posts
    Nov 17, 2005
    Currently Being Moderated
    Nov 16, 2011 5:28 PM   in reply to blk.sheep

    Yes, I see few things that need to be destroyed. The rssTextMC should have a destroy as well which will be called from the news' destroy.

     

    stage.addEventListener(Event.RESIZE, RSSstageResize);
    rssParser.addEventListener("dataWritten", onDataReceived)
    cssLoader.addEventListener(Event.COMPLETE, cssLoadComplete);
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points