A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Error #2007 help for a Noob

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    2

    Question Error #2007 help for a Noob

    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:

    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.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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:
    Code:
    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);
    }

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    2
    Brilliant! Worked first time! Now I can finally go to bed.


    Quote Originally Posted by 5TonsOfFlax View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center