PDA

View Full Version : Can someone tell me what is meant by this error?


p0c
05-16-2008, 07:42 AM
I have this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Maps_fla::MainTimeline/frame1()

But what does it mean exactly all I know is something cant be found, I dont even have anything called Maps.fla, similar though but can anyone help me out I cant find any errors or wrong links


Thanks

Flash Gordon
05-16-2008, 08:08 AM
your variable contains a null reference. so your variable is equal to null

var myVar:* = null;

now you are trying to access a property of that variable

myVar.myProp

which equates to this

null.myProp

because "null" contains no properties of it's own, you can't access any properties of it. Therefore the error.

What's the null object? I dunno. Flash sucks as giving feedback on that pesky bug. Start tracing.

amarghosh
05-16-2008, 08:19 AM
some code in ur frame1 is accessing a variable before its assigned anything; post the code and we might be able to tell u where it is....

if u think its not from ur fla, it might be from some swf that u have loaded using Loader (just a wild guess)

//some basic stuff abt 1009

var temp:Array;
temp.push(2);

this code will give u a 1009 error. Here we have declared temp to be a variable that will be pointing to an Array (that will contain an Array) but we haven't specified which Array; so flash complains "what the heck am i supposed to push 2 into?"
to correct this create a new Array and assign it to temp; when u call new Array(), it will create an Array and its internal memory address will be assigned to temp; unless u do this, temp will be having no Array assigned to it - hence the 'null';

var temp:Array;
temp = new Array(); //or temp = []
temp.push(2);

now it will work;

p0c
05-16-2008, 08:40 AM
It is from loading an swf, inside a movie clip. But the maps.swf works fine on its own, and as far as I can see I have previously loaded swfs elsewhere in the flash application and have used exactly the same code and have made sure that the swf is in the correct location :confused:

Im still also a bit confused about what code to post because there is a lot of it, thats why this vague error is causing me problems. I do have these vars in the maps frame 1 fla file though:

var mapRectWidth=mapSpace.width;
var mapRectHeight=mapSpace.height;

var xoffset:Number;
var yoffset:Number;

amarghosh
05-16-2008, 08:49 AM
i second Flash Gordon: start tracing -- give trace statements for every object that u think might produce null error (may be u can avoid objects that u assign to using new keyword - make sure they are not assigned return values of some functions)

if u have a large amount of code in there, put separate sections of code in separate try blocks, catch errors and throw different error statements from different blocks. this way u can track the section of code that throws null. then go for tracing in that segment;

u have to install debug version of flash player -- it might tell something about the line of code that gave error;

p0c
05-16-2008, 08:58 AM
Well this bit of code bothers me:

addChild(mapsShow);
mapsShow.x=0.0;
mapsShow.y=100.2;
TransitionManager.start(mapsShow, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone, startPoint:4});

//addChild(introMovie);
//introMovie.x=0.0;
//introMovie.y=100.2;
//TransitionManager.start(introMovie, {type:Fade, direction:Transition.IN, //duration:1, easing:None.easeNone, startPoint:4});


This is the swf that loads on the first frame of the app (I only load one of the above). But the weird thing is this code works and gets no errors, but if I take the "//" off the introMovie section and put them on the mapsShow section, the intro movie obviously loads but then I get that maps_fla error I showed below:confused:

amarghosh
05-16-2008, 09:02 AM
what is introMovie? u have the code? is it loaded using Loader?

trace(introMovie);//what does this print?

p0c
05-16-2008, 09:08 AM
I got: [object introMC]

In introMC (that has a linkage to as because it not on the stage, ah, which is actually also "introMC" in the class box.

The movie clip is just a white box with the following code:

var introShow:Loader = new Loader();
var introReq:URLRequest = new URLRequest("Intro v2.swf");
var mc:MovieClip = null;
addChild(introShow);
introShow.x = 0;
introShow.y = 0;
introShow.load(introReq);

amarghosh
05-16-2008, 09:11 AM
is this the only code in introMC class? r u doing anything with var mc:MovieClip later?

p0c
05-16-2008, 09:13 AM
To be honest im not even sure what "var mc:MovieClip = null;" is doing but it makes no difference if i take it out

amarghosh
05-16-2008, 09:15 AM
is there any other code in introMC class that might be causing it?

p0c
05-16-2008, 09:18 AM
There is no other code in the introMC movie clip.

After a few clicks i got this error now :mad:: TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Maps_fla::MainTimeline/muh()

Which is in the embedded maps.swf...

stage.addEventListener(MouseEvent.MOUSE_UP,muh);
function muh(Event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mm h);
}

Is using stage even a good idea in embedded swfs, does it get the stage of the embedded swf or the main stage of the swf its loaded into?

amarghosh
05-16-2008, 09:32 AM
stage is null unless and until u add it to display list.
move all the stage related stuff in the maps.swf to an ADDED_TO_STAGE event listener;

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
function onAddedToStage(e:Event):void
{
//write stage accessing code here;
}

p0c
05-16-2008, 09:45 AM
I tried doing what you said...

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
function onAddedToStage(e:Event):void
{
mapSpace.mapViewer.addEventListener(MouseEvent.MOU SE_DOWN,mdh);
function mdh(Event:MouseEvent):void {
xoffset=mapSpace.mapViewer.mouseX;
yoffset=mapSpace.mapViewer.mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE,mmh);
}

function mmh(Event:MouseEvent):void {
mapSpace.mapViewer.x=mapSpace.mouseX-xoffset;
mapSpace.mapViewer.y=mapSpace.mouseY-yoffset;
if (mapSpace.mapViewer.x>0)
mapSpace.mapViewer.x=0;
else if (mapSpace.mapViewer.x<0-mapSpace.mapViewer.width+mapRectWidth)
mapSpace.mapViewer.x=0-mapSpace.mapViewer.width+mapRectWidth;
if (mapSpace.mapViewer.y>0)
mapSpace.mapViewer.y=0;
else if (mapSpace.mapViewer.y<0-mapSpace.mapViewer.height+mapRectHeight)
mapSpace.mapViewer.y=0-mapSpace.mapViewer.height+mapRectHeight;
}

stage.addEventListener(MouseEvent.MOUSE_UP,muh);
function muh(Event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mm h);
}

Whatever code I put inside that function doesn't get picked up.

After playing round a bit I got this new error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1083()

But it only seems to happen the second time map.swf loads up.

I mean I'm obviously no expert but seeing as I've tested the map.swf to death many times and I only get errors when importing surely it has something to do with trying to access the stage, I can't think of anything else?

amarghosh
05-16-2008, 12:05 PM
try giving a trace statement in the onAddedToStage and the methods within it to see if they r being called or not; and i don't think it would make a difference, but its not a good thing to put functions inside another function; take those listener functions inside onAddedToStage out and make them independent functions;

if trace in the onAddedToStage is being called, call onAddedToStage(null) from main swf once the map.swf is loaded

p0c
05-16-2008, 12:15 PM
Ah YES!!! ;)

I got it sorted (somehow)

Thanks again for your help amarghosh you've helped me a lot recently!! I am not 100% sure but I think it was because I changed all "stage" occurrences to "root" It seems to work now when imported into another swf, thanks. (I have so many variations of the map.swf I dont know what one it was)

amarghosh
05-16-2008, 01:28 PM
glad to know that u got it :)