views:

65

answers:

3

Hi,

I've been given an fla to make some changes too. Basically its a fairly long timeline animation with sound. So far I've successfully added a few button functions for sound etc.. but one has got me stumped.

One of the buttons needs to load a child swf. I'm using the code below but I'm recieving an error - 'Error #1009: Cannot access a property or method of a null object reference'. I believe this may be refferring to an object that isn't set yet but I have no idea which one it is:

Code:

var mcExt:MovieClip = new MovieClip();
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
ldr.load(new URLRequest("Downloads.swf"));

function swfLoaded(e:Event):void {
mcExt = MovieClip(ldr.contentLoaderInfo.content);
ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);
mcExt.x = 50;
mcExt.y = 50;
addChild(mcExt);
}

Any help on what is going wrong would be greatly appreciated!

Thanks

+1  A: 

Hi there Rich,

Rather than:

ldr.contentLoaderInfo.content

Try:

ldr.content

Hope that solves your problems!

Tyler Egeto
afaict, both are valid and the same
Amarghosh
Thanks for the correction, very cool!
Tyler Egeto
A: 

Have you tried compiling in debug mode? Running the debugger will likely throw the same error, but it will magically include a line number too.

sberry2A
A: 

Place

ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);

at the end of your code, making it:

var mcExt:MovieClip = new MovieClip();
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
ldr.load(new URLRequest("Downloads.swf"));

function swfLoaded(e:Event):void {
    mcExt = MovieClip(ldr.contentLoaderInfo.content);
    mcExt.x = 50;
    mcExt.y = 50;
    addChild(mcExt);
    ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);
}

I believe that the position of your removeEventListener is what is messing up your code.

Christopher Richa