PDA

View Full Version : error #1009:Cannot access a property or method of a null object reference.



Tedri Mark
July 11th, 2009, 10:40 AM
I know there is at least one other thread on this error, and I've overcome it before with the ADDED_TO_STAGE listener, but this time I can't seem to get it to work

I have this function:


private function preload(e:Event):void
{
var preloader = e.target;
var bar = preloader.process;
bar.scaleX += (count / numphot - bar.scaleX) * 0.1;

if (bar.scaleX >= 0.95) {

bar.scaleX = 1;

//Fade out preloader
Tweener.addTween( preloader, { alpha:0,
time:1,
transition:"easeOutExpo",
onComplete:function():void {

//remove preloader ~ load complete
removeChild(preloader)

changeTo(startFrom);

// fade in screen, scroller, caption, tooltip
Tweener.addTween([container, iScroller, cap, prevbut, nextbut], {alpha:1, time:2});
state = true;
}
});

// remove Enterframe event for preloader
preloader.removeEventListener(Event.ENTER_FRAME, preload);
}
}

Which is called by this, first time around:


preloaderMain.addEventListener(Event.ENTER_FRAME, preload);

and then later on, when I've removed all the items from the scene and want to restart everything again, using this:


preload(null);



According to the debug console, this is what is causing the error:


var preloader = e.target;


Any ideas?

.ral:cr
July 11th, 2009, 11:11 AM
var preloader = e.target;
will became:
var preloader = null.target;

so what do you think is the error here?

Tedri Mark
July 11th, 2009, 01:51 PM
var preloader = e.target;
will became:
var preloader = null.target;

so what do you think is the error here?


Aha, that makes sense. So how do I get around the
1136: Incorrect number of arguments. Expected 1. error if I just call
preloader(); ?

453.0
July 11th, 2009, 02:24 PM
Well, as a first step, understanding what you have there would be good. It would be more then good, it would be simply great. Once you understand what the code you copy-pasted from somewhere does, then you might actually understand why it will never work the way it is now.

That would be the first solution, the second one would be to actually understand how preloaders work and to write your own preloader. The code you have there is just sad.

Take some time, surf the internet and try to actually understand what you are doing.

.ral:cr
July 11th, 2009, 03:55 PM
good advice from 453.0, i think you don't know some elementary things about programming in general. if a function expects a parameter you have to provide it.

anyway, there's nothing you can do there, if you want to reset the preloader you create another function that set everything as you want

Tedri Mark
July 13th, 2009, 10:05 AM
good advice from 453.0, i think you don't know some elementary things about programming in general. if a function expects a parameter you have to provide it.

Yep, I get that, hence the (null) argument, but then obviously this throws up another error. But yeah, I'm definitely just a beginner, and probably in deeper than I should be at this stage, but needs must and all that..

I'll have a little investigate of the pre-loader, and see if I can spot why it won't work in the way I'd like it to, and do a bit of a re-write.

Ta for the advice.


How I'm learning is akin to learning a new language by moving to a different country, leaping in and understanding what I can, having to research stuff I don't know about as and when I come to it.