PDA

View Full Version : TypeError 1009 - Why Though??


NeoMarine
05-22-2008, 01:34 PM
The following code returns a 1009 error:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at myfile_fla::MainTimeline/colorActiveItemEvent()

But I have no idea what it is referring to exactly. The thing is, the code works, except everytime I use it inside test mode I get this annoying typeerror...

Does anyone know the reason, or fix for this?

Here's my code:

import flash.geom.ColorTransform;

function colorActiveItemEvent(eventObject:Event):void {
var newColorTransform:ColorTransform = activeItem.transform.colorTransform;
newColorTransform.color = colorChanger.cpColor.selectedColor;
activeItem.objectColor.transform.colorTransform = newColorTransform;
currentHairColor = colorChanger.cpColor.selectedColor;
}

activeItem.addEventListener(Event.ENTER_FRAME, colorActiveItemEvent);

amarghosh
05-22-2008, 01:48 PM
one of the variables has not been initialized to any value. thats y this error is occuring. unfortunately flash don't tell us anything about which one is null. only way is to start tracing all the possible objects;
function colorActiveItemEvent(eventObject:Event):void
{
trace("activeItem : " + activeItem);

var newColorTransform:ColorTransform = activeItem.transform.colorTransform;

trace("colorChanger : " + colorChanger);
trace("colorChanger.cpColor : " + colorChanger.cpColor);

newColorTransform.color = colorChanger.cpColor.selectedColor;

trace("activeItem.objectColor : " + activeItem.objectColor);

activeItem.objectColor.transform.colorTransform = newColorTransform;
currentHairColor = colorChanger.cpColor.selectedColor;
}

one of them will give u a null and terminate with 1009. find it and fix him

NeoMarine
05-22-2008, 01:56 PM
Ok it returns me to:

activeItem.objectColor : null

objectColor is a MovieClip... i'm not sure how to initialize it, it's already there in the first frame when its created and the function starts, and it still traces back null..?

ITS OK

I just put :

if (activeItem.objectColor){
//my code
}

and it stops this problem. thanks!!