;

PDA

Click to See Complete Forum and Search --> : Error #2007 help for a Noob


Hughless
04-16-2009, 04:29 PM
Hi. I've literally started ASing today and trying my hand at a a site intro page. I've come up against this problem which a lot of people seem to have but none of the solutions I've found online seem to be helping me.

So I'm trying to get a simple button to animate when rolled over. Although I'm beginner I'm as sure as I can be that I've got all the timeline stuff fine-tuned and that my problem is purely code based. Here's my error message:-

TypeError: Error #2007: Parameter listener must be non-null.
at flash.events::EventDispatcher/addEventListener()
at splash4_fla::MainTimeline/frame96()

Here's my short bit of code:

b2.buttonMode=true;
b2.addEventListener(MouseEvent.ROLL_OVER,b2.Over);
b2.addEventListener(MouseEvent.ROLL_OUT,b2.Out);

b2.Over=over;
b2.Out=out;

function over() {
this.gotoAndPlay(9);
}

function out() {
this.gotoAndPlay(1);
}

I don't really know what might be the problem so any insight would be appreciated. Thanks.

5TonsOfFlax
04-16-2009, 05:00 PM
At the point where you are adding the listener, b2.Over and b2.Out are not set yet. You should be able to simply move the lines defining them above the addEventListeners. Of course, there's no reason to bother going through that indirection, you could just set over and out as the listeners in the first place.

I'm wondering if you think that "this" in over and out will refer to b2. It won't, it will refer to the clip in which the function is defined. If you did want it to refer to b2, you could either explicitly use b2, or use event.currentTarget (cast to MovieClip).

Which brings us to the third problem: your event handlers need to take event parameters.

Putting it all together:

b2.buttonMode=true;
b2.addEventListener(MouseEvent.ROLL_OVER, over);
b2.addEventListener(MouseEvent.ROLL_OUT, out);

function over(event:MouseEvent):void {
MovieClip(event.currentTarget).gotoAndPlay(9);
}

function out(event:MouseEvent):void {
MovieClip(event.currentTarget).gotoAndPlay(1);
}

Hughless
04-16-2009, 07:42 PM
Brilliant! Worked first time! Now I can finally go to bed.


I'm wondering if you think that "this" in over and out will refer to b2. It won't, it will refer to the clip in which the function is defined. If you did want it to refer to b2, you could either explicitly use b2, or use event.currentTarget (cast to MovieClip).
Thanks. Yes I was thinking that. I picked it from a tutorial I watched earlier but I guess I wasn't clear about the context.