Copy link to clipboard
Copied
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 -
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
...Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Thanks for that! Didn't work tho - traced the same output.
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){
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);
}
Maybe a bit more info. On resizing, the output of the loading .swf traces:
parent is [object Stage]
stage is [object Stage]
parent.parent is null
And the output of the container swf on resizing loads:
parent is [object Loader]
stage is [object Stage]
parent.parent is [object MainTimeline]
Then, when you reload the swf in the container swf a second time, I then receive:
parent is null
stage is null
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ha - okay then.
I basically have LOADER swf loading in external swf's in an array, on top of one another. I'm trying to position and center the elements in each LOADEE swf to the stage, and this what brings the error but I'm not loading the stage correctly I'm assuming in the LOADEE. swf.
It's a lot of code maybe, and I was trying to break down just the issue of the stage=null error. I removed extraneous comments. The LOADER.swf:
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
//set stage position, no scaling on stage
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
/// create mcvar tl:MovieClip = this;
// arrary, loaders, listeners
var loaderNum:uint = 0;
var swfArray:Array = ["news.swf", "biopress.swf", "sounds.swf", "images.swf", "video.swf", "shows.swf", "store.swf", "contact.swf", "blog.swf"];
tl["loader_0"] = new Loader();
tl["loader_1"] = new Loader();
tl["loader_0"].contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);
tl["loader_1"].contentLoaderInfo.addEventListener(Event.COMPLETE,loadCompleteF);
// listener for first loader_0
tl["loader_0"].load(new URLRequest(swfArray[0]));
//////// force reload & prevent swf caching
var req:URLRequest = new URLRequest(swfArray[0]);
if( versionChanged() )
{
req.method = URLRequestMethod.POST;
req.data = true;
}
tl["loader_0"].load(req);
function versionChanged():Boolean {
var cache:SharedObject = SharedObject.getLocal( "app-cache", "/" );
var version:String = loaderInfo.parameters.version;
var changed:Boolean = cache.data.version != version;
cache.data.version = version;
cache.flush();
return changed;
}
/////////////////////////////////////////////////////////////////////////////
addChild(tl["loader_0"]);
addChild(tl["loader_1"]);
function loadCompleteF(e:Event){
loaderNum=(loaderNum+1)%2;
}
//load top and bottom bars
var barOne = new BarOne();
stage.addChild (barOne);
var barTwo = new BarTwo();
stage.addChild (barTwo);
// load navmenu
var navmenu = new NavMenu();
stage.addChild(navmenu);
// navmenu buttons listeners
navmenu.news.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.biopress.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.sounds.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.images.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.video.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.shows.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.store.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.contact.addEventListener(MouseEvent.CLICK, btnClick);
navmenu.blog.addEventListener(MouseEvent.CLICK, btnClick);
function btnClick(event:MouseEvent):void {
tl["loader_"+loaderNum].load(new URLRequest(event.currentTarget.name+".swf"));
addChild(tl["loader_"+loaderNum]);
}
// load logo
var logo = new MyMovieClip();
stage.addChild(logo);
stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(e:Event){
//stage.addEventListener(Event.ADDED_TO_STAGE,resizeHandler);
// variables for fullscreen stage values width & height
var sw:int = int(stage.stageWidth);
var sh:int = int(stage.stageHeight);
// position page elements
navmenu.x = 25;
navmenu.y = 3;
logo.x = sw - 130;
logo.y = sh - 39;
barOne.width = sw;
barOne.x =0;
barTwo.width = sw;
barTwo.y = stage.stageHeight - barTwo.height;
}
resizeHandler(null);
stop();
And the LOADEE swf:
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
//set stage position, no scaling on stage
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
///var sw:int = int(stage.stageWidth);
//var sh:int = int(stage.stageHeight);
//topwindow loader
var indexBanner:Loader = new Loader();
addChild(indexBanner);
var url:URLRequest = new URLRequest("index_banner.swf");
indexBanner.load(url);
indexBanner.addEventListener(MouseEvent.CLICK, btnClick);
function btnClick(event:MouseEvent):void {
var urlLink:URLRequest = new URLRequest("http://www.chocodogmerch.com/index.php?sku=wee728");
navigateToURL(urlLink, "_blank");
}
//add networks nav
var networksnav = new networksNav();
addChild(networksnav);
//Mailinglist Form
import MailinglistForm;
var mailinglistForm:MailinglistForm = new MailinglistForm();
// Label settings
/*
mailinglistForm.emailText = "Type your email here";
mailinglistForm.sendButtonText = "CONTACT ME";
mailinglistForm.sendingText = "Sending message...";
mailinglistForm.errorEmailText = "Your email is not valid.";
mailinglistForm.errorServerText = "Server problems.";
mailinglistForm.confirmationText = "Thanks for contacting me!";
*/
// Color settings
mailinglistForm.textColor = 0x000000;
mailinglistForm.borderColor = 0xffffff;
mailinglistForm.selectedBorderColor = 0xF2F2F2;
mailinglistForm.selectedBackgroundColor = 0xffffff;
mailinglistForm.selectedBlurAmount = 25;
mailinglistForm.sendButtonTextColor = 0x440B0B;
mailinglistForm.sendButtonTextRollOverColor = 0xffffff;
mailinglistForm.sendButtonColor = 0xffffff;
mailinglistForm.sendButtonRollOverColor = 0xD7BE62;
mailinglistForm.errorColor = 0xFF0000;
mailinglistForm.confirmationColor = 0x05b59a;
addChild(mailinglistForm);
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){
trace("parent is " + parent);
trace ("stage is " + stage);
if(parent != null)
trace("parent.parent is " + parent.parent);
//variables for fullscreen stage values width & height
//var sw:int = int(stage.stageWidth);
//var sh:int = int(stage.stageHeight);
}
stop();
In the LOADEE swf I have nothing in the resize funciton but just the trace, and again nothing fires from the ADDED_TO_STAGE listener.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I gave that a go, and resizeHandlerNews2 doesn't do anything on resize - the listner is now in the ini function. . Plus I can't understand why the ini listnener isn't firing the trace.
Thanks so much the help.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Omit trace option is unchecked. That listener outputs correctly as
stage: [object Stage]
stage: [object Stage]
stage: [object Stage]
stage: [object Stage]
etc
in both loadee and loader output.
Copy link to clipboard
Copied
put the trace statement outside the function - what does it say?
Copy link to clipboard
Copied
Outside of the temp function:
stage: [object Stage]
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
? I think I'm confused -
I still have the same issue - any external loaded into the loader swf is tracing output stage=null, thus I can't set listeners for the loaded swfs and use stage dimensions and centering.
This should be working - but the ADDED_TO_STAGE listener isn't firing or tracing output, or being seen.
addEventListener(Event.ADDED_TO_STAGE, ini );
function ini(e:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE, ini);
trace("stage after added to stage -" + stage);
stage.addEventListener(Event.RESIZE, resizeHandlerNews2);
}
function resizeHandlerNews2(e:Event){
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
http://amandlanet.net/stage_null.zip
A zip of the container fla, and 2 external swfs.Reposting what I wrote earlier about the #1009 error:
On resizing, the output of the loading .swf traces:
parent is [object Stage]
stage is [object Stage]
parent.parent is null
And the output of the container swf on resizing loads:
parent is [object Loader]
stage is [object Stage]
parent.parent is [object MainTimeline]
Then, when you reload the swf in the container swf a second time, I then receive:
parent is null
stage is null
So I'm getting the null error when a swf is loaded 3 times - using my original cod with no ADDED TO STAGE listener.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
- brilliant! Apologies for the lapse - I'm a new kitten daddy, little buggers are crazy - That works just great and I understand the code.
My only other issue is, with one of the 'loadee' swfs - news.swf - it has an MC on its timeline that loads another MC with a stage listener inside of it, and this MC is now bringing the #1009. I know it's a paths issue, but my attempts have proved fruitless.
I uploaded another zip.....?
Again, really - thanks a million -
Copy link to clipboard
Copied
I can't compile news.fla because I'm missing RSSParser.as. Can you chare it as well?
Copy link to clipboard
Copied
The zip has been updated with the classes folder -
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
www.amandlanet.net/classes.zip -
apologies & cheers
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Howdy -
I'm reproducing the #1009 from the news.swf when I load news.swf in index.swf 3 times. It's coming from the listener in rssTextMC. I have to put the destroy method all the objects there ...?
Copy link to clipboard
Copied
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);