PDA

View Full Version : Loading External SWFs Error



titanag
October 8th, 2009, 10:27 AM
Hi,

Here's my problem: I have an index called allproducts and I want users to be able to click on an element and load a new SWF (with several external .as files) that has specifics about that element.

When I run JUST the element (SS_glutenfree.swf), it works great. When I run allproducts.swf and click on the gluten free button, I get:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Handle()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at Gallery()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Gallery()

allproducts.swf is in the folder above SS_glutenfree.swf and all of its .as files (which are Gallery, Handle, and Img).

Thanks for any help you can offer!

April

IQAndreas
October 8th, 2009, 10:32 AM
That's the most common error, so I have a precompiled list of threads that cover it. The first one should suffice if you don't want to read them all. :)

TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hands down, with no doubt possible in anyone's mind the absolute #1 error. There are 2 possible causes:


Error #1009 when preloading another SWF:
http://www.kirupa.com/forum/showpost...10&postcount=2 (http://www.kirupa.com/forum/showpost.php?p=2495410&postcount=2)
http://www.kirupa.com/forum/showthread.php?t=330677
http://www.kirupa.com/forum/showthread.php?p=2500293
http://www.kirupa.com/forum/showthread.php?t=333092
Error #1009 in general:
http://www.kirupa.com/forum/showpost...21&postcount=2 (http://www.kirupa.com/forum/showpost.php?p=2500521&postcount=2)

titanag
October 8th, 2009, 11:32 AM
Thanks for your quick reply, but unfortunately my problem exists BEFORE I get to any of your suggestions, but I have implemented the ADDED_TO_STAGE tip already. (Your post was much clearer than the one I struggled to understand!)

Here's the code from allproducts.swf:
function glutenfreeclick(event:MouseEvent):void {
trace("clicked gluten free");
var glutenfreeLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("SS_allproducts/SS_glutenfree.swf");
glutenfreeLoader.load(url);
trace( "loading" );
glutenfreeLoader.contentLoaderInfo.addEventListene r( Event.COMPLETE, seeProducts );
}

function seeProducts( _e : Event, gfl : Loader ) : void
{
trace( "can you see me now?" );
addChild(gfl);
trace( "how about now?" );
}

The last trace I get is "loading."

Thanks a bunch for your help!

April

IQAndreas
October 8th, 2009, 11:44 AM
So, are you still getting the #1009 error?

Why do you have the extra parameter "gfl" in the event listener function?
function seeProducts( _e : Event, gfl : Loader ) : void

Is that possible? If not, try using:

function seeProducts( _e : Event) : void
{
trace( "can you see me now?" );
addChild(_e.content);
trace( "how about now?" );
}

Also, did you use the ADDED_TO_STAGE initializer in the loaded SWF? (the glutenfree.swf, not allproducts.swf, although it would still work in there...)

titanag
October 8th, 2009, 12:30 PM
I tried your tip (_e.content) - just a note, I had to type cast _e as a movie clip or I got Error 1119, so now I have

trace(...
addChild( MovieClip(_e).content);
trace(...

and still get the #1009 Error. :(

Here are my constructors for Gallery and Handle, but since I'm not even getting past the Event.COMPLETE, I don't think at this point they are the problem. Yet.

public function Gallery() : void
{
addEventListener( Event.ADDED_TO_STAGE, init );
}

private function init( _e : Event ) : void
{
trace("added!");
removeEventListener( Event.ADDED_TO_STAGE, init );
STAGE = this.stage;
stageWidth = STAGE.stageWidth;
theHandle.addEventListener( "sliding", slide );

imagesClip.y = 330; //original number was 180, number in combo movie is 330
addChild( imagesClip );

setImgList();
initListeners();

xmlLoader.load( new URLRequest( imglist + "?" + new Date().valueOf() ) );
xmlLoader.addEventListener( Event.COMPLETE, loadImages );
}

and Handle:

public function Handle() : void
{
addEventListener( Event.ADDED_TO_STAGE, init );
}

private function init( _e : Event ) : void
{
buttonMode = true;
addEventListener( MouseEvent.MOUSE_DOWN, moveHandle );
Main.STAGE.addEventListener( MouseEvent.MOUSE_UP, stopHandle );
}

When I debug, the Debug Console says the follow (hopefully this helps):

Handle [no source]
x2 flash.display... [no source]
Gallery [no source]

Thanks a bunch for your help thus far. I have met a brick wall on this for about a week.

April

IQAndreas
October 8th, 2009, 02:06 PM
Sorry. That error was a typo on my part...

I'm not sure about the rest of your code, but try if this gets rid of the error first:

function seeProducts( _e : Event) : void
{
trace( "can you see me now?" );
addChild(_e.currentTarget.content);
trace( "how about now?" );
}

titanag
October 8th, 2009, 02:40 PM
Oooh Ooooh Oooooh! No errors! But nothing happens either.

I still never get past the trace "loading," so the event of loading is not completing? At least that's how I understand it. We never make it to the seeProducts function.

But, NOT getting that error after a week of getting it feels like real progress!

Do you have any more suggestions? Thanks, thanks, thanks for everything thus far. I really can't thank you enough.

April

IQAndreas
October 8th, 2009, 03:51 PM
Found it. :)

You are asking it to listen for when it is finished downloading AFTER it has already started downloading.

By the time it gets down to the line where you ask it to start listening, it is likely long gone and loaded.

Try putting the listener first:

var url:URLRequest = new URLRequest("SS_allproducts/SS_glutenfree.swf");
glutenfreeLoader.contentLoaderInfo.addEventListene r( Event.COMPLETE, seeProducts );
glutenfreeLoader.load(url);

titanag
October 8th, 2009, 04:28 PM
That worked! *kneels before godlike figure* Thank you, truly. :)

Also, I realized I don't need to typecast _e. Just addChild( _e.currentTarget.content ) works just fine.

Thanks again!

April