PDA

View Full Version : TypeError: Error #1009. (Trying to control loaded swf)



weedunc65
February 19th, 2010, 07:42 AM
Hello

Only recently started aquainting myself with AS3 and have created a basic fla. with 2 buttons. One to load a swf with xml in it which animates onto the stage in my main fla. The second button is just supposed to play the rest of the loaded swf so it animates off, then unloads the loader. Here's my code.


unloadbutton.mouseEnabled=false; //Cancel button is unavailable until the load button is pressed

/////////////////////////////////////////////// Load Button /////////////////////////////////////////////////////////////

loadbutton.addEventListener(MouseEvent.MOUSE_OVER, mouseoverload);
loadbutton.addEventListener(MouseEvent.MOUSE_OUT, mouseoutload);
loadbutton.addEventListener(MouseEvent.MOUSE_DOWN, mouseclickload);

function mouseoverload(event:MouseEvent):void {
loadbutton.gotoAndStop(2);
}

function mouseoutload(event:MouseEvent):void {
loadbutton.gotoAndStop(1);
}

var loader:Loader = new Loader();

function mouseclickload(event:MouseEvent):void{
loadbutton.gotoAndPlay(3);

addChild(loader);
var swfloader:URLRequest=new URLRequest('XML animated in swf.swf');
loader.load(swfloader);

unloadbutton.mouseEnabled=true;
}

//////////////////////////////////////// Cancel Button /////////////////////////////////////////////////

unloadbutton.addEventListener(MouseEvent.MOUSE_OVE R, mouseover);
unloadbutton.addEventListener(MouseEvent.MOUSE_OUT , mouseout);
unloadbutton.addEventListener(MouseEvent.MOUSE_DOW N, mouseclick);

function mouseover(event:MouseEvent):void {
unloadbutton.gotoAndStop(2);
}

function mouseout(event:MouseEvent):void {
unloadbutton.gotoAndStop(1);
}

var loadedswf:MovieClip = loader.content as MovieClip;

function mouseclick(event:MouseEvent):void {
unloadbutton.gotoAndPlay(3);

loadedswf.gotoAndPlay(16);
loadedswf.addEventListener(Event.COMPLETE, swfanimatedout);

function swfanimatedout(e:Event):void {
loader.unload(); //I'm hoping this function will mean the 'loadedswf' will have time to animate offscreen before it is unloaded. I tested the code without this function in and still the same result
}

loadbutton.mouseEnabled=true;
}

This code brings up the error 'TypeError: Error #1009: Cannot access a property or method of a null object reference. at XMLWIthinSWFloadengine_fla::MainTimeline/mouseclick()'

I've no idea what it means or what I'm to do about it.

Any help appreciated.

IQAndreas
February 19th, 2010, 07:45 AM
Tag! This thread is mine!

Time for my "handy dandy one size fits all Error #1009 copy paste list"!

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)

weedunc65
February 19th, 2010, 08:17 AM
I love a quick fix as much as the next guy, but the one link of those that was relevant to what I'm doing here, didn't work. Pasted in the swf I'm loading or the swf im loading to, I got the same error.

=(

IQAndreas
February 19th, 2010, 08:43 AM
Darn. That usually fixes 98% of all problems. But do you at least understand what the #1009 error means now?

As I mentioned in the last link, if you debug using "CTRL+SHIFT+ENTER" you find EXACTLY which line the error is at.

Then use trace to find which item is null, or if you can't find it, post back the EXACT error message, and the line of code which it points to, and I'll help you track it down.

weedunc65
February 22nd, 2010, 06:18 AM
Thank you for your continued assistance. In answer to your question however, I'm a little confused. I don't understand how the position of the loaded swf on the stage affects my ability to control the animation within it with some 'gotoAnd...'s

One question of my own to add; I assume that you can't see anything obviously wrong with the code I have written thus far, if you need me to debug and so on in order to help me?

weedunc65
February 22nd, 2010, 07:22 AM
I should probably add that the swf loaded just fine until I added the following indicated lines of code;

var loadedswf:MovieClip = loader.content as MovieClip; //added this line

function mouseclick(event:MouseEvent):void {
unloadbutton.gotoAndPlay(3); // These two lines were already present when it worked

loadedswf.gotoAndPlay(16); //added all of the following
loadedswf.addEventListener(Event.COMPLETE, swfanimatedout);

function swfanimatedout(e:Event):void {
loader.unload();
} // up to here...

loadbutton.mouseEnabled=true;
}

It was only when I tried to control the loaded swf that the error occurred. Sorry if this was not made clear before and I've been leading you down the wrong path

weedunc65
February 22nd, 2010, 09:39 AM
Many thanks for your help, problem has now been solved.

The loaded swf didnt like being addresses as an MC, instead I addresed it as an object, and all went acording to plan.