Results 1 to 7 of 7

Thread: Error #2007: Parameter listener must be non-null.

  1. #1

    Error #2007: Parameter listener must be non-null.

    Hi I'm creating a winnie the pooh colouring in game and I'm getting
    TypeError: Error #2007: Parameter listener must be non-null.
    at flash.events::EventDispatcher/addEventListener()
    at ColouringinGame_fla::MainTimeline/frame1()


    The Code on the main time line is

    import flash.events.MouseEvent;




    var myColor = 0xFFFFFF;




    function getBlack(event:MouseEvent):void {
    myColor = 0x000000;
    }
    function getLightBlue(event:MouseEvent):void {
    myColor = 0x33CCFF;
    }
    function getDarkBlue(event:MouseEvent):void {
    myColor = 0x3300CC;
    }
    function getGrey(event:MouseEvent):void {
    myColor = 0x666666;
    }
    function getLightGreen(event:MouseEvent):void {
    myColor = 0x66CC66;
    }
    function getDarkGreen(event:MouseEvent):void {
    myColor = 0x003300;
    }
    function getBrown(event:MouseEvent):void {
    myColor = 0x663300;
    }
    function getOrange(event:MouseEvent):void {
    myColor = 0xFF9900;
    }
    function getPink(event:MouseEvent):void {
    myColor = 0xFF66FF;
    }
    function getSkin(event:MouseEvent):void {
    myColor = 0xFFCCCC;
    }
    function getPurple(event:MouseEvent):void {
    myColor = 0x6600CC;
    }
    function getRed(event:MouseEvent):void {
    myColor = 0xFF0000;
    }
    function getWhite(event:MouseEvent):void {
    myColor = 0xFFFFFF;
    }
    function getYellow(event:MouseEvent):void {
    myColor = 0xFFFF00;
    }




    this.b_black.addEventListener(MouseEvent.MOUSE_DOW N, getBlack);
    this.b_grey.addEventListener(MouseEvent.MOUSE_DOWN , getGrey);
    this.b_dgreen.addEventListener(MouseEvent.MOUSE_DO WN, getDarkGreen);
    this.b_lblue.addEventListener(MouseEvent.MOUSE_DOW N, getLightBlue);
    this.b_dblue.addEventListener(MouseEvent.MOUSE_DOW N, getDarkBlue);
    this.b_lgreen.addEventListener(MouseEvent.MOUSE_DO WN, getLightGreen);
    this.b_brown.addEventListener(MouseEvent.MOUSE_DOW N, getBrown);
    this.b_orange.addEventListener(MouseEvent.MOUSE_DO WN, getOrange);
    this.b_pink.addEventListener(MouseEvent.MOUSE_DOWN , getPink);
    this.b_purple.addEventListener(MouseEvent.MOUSE_DO WN, getPurple);
    this.b_red.addEventListener(MouseEvent.MOUSE_DOWN, getRed);
    this.b_white.addEventListener(MouseEvent.MOUSE_DOW N, getWhite);
    this.b_yellow.addEventListener(MouseEvent.MOUSE_DO WN, getYellow);
    this.b_skin.addEventListener(MouseEvent.MOUSE_DOWN , getSkin);




    this.b_black.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_grey.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_dgreen.addEventListener(MouseEvent.MOUSE_UP , this.brush.colorMe);
    this.b_lblue.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_dblue.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_lgreen.addEventListener(MouseEvent.MOUSE_UP , this.brush.colorMe);
    this.b_brown.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_orange.addEventListener(MouseEvent.MOUSE_UP , this.brush.colorMe);
    this.b_pink.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_purple.addEventListener(MouseEvent.MOUSE_UP , this.brush.colorMe);
    this.b_red.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_white.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    this.b_yellow.addEventListener(MouseEvent.MOUSE_UP , this.brush.colorMe);
    this.b_skin.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);




    this.Pooh.P_legs.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_legs.colorMe);
    this.Pooh.P_arms.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_arms.colorMe);
    this.Pooh.P_shirt.addEventListener(MouseEvent.MOUS E_UP, this.Pooh.P_shirt.colorMe);
    this.Pooh.P_body.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_body.colorMe);
    this.Pooh.P_head.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_head.colorMe);
    this.Pooh.P_tounge.addEventListener(MouseEvent.MOU SE_UP, this.Pooh.P_tounge.colorMe);
    this.Pooh.P_Tjar.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_Tjar.colorMe);
    this.Pooh.P_bjar.addEventListener(MouseEvent.MOUSE _UP, this.Pooh.P_bjar.colorMe);




    function moveBrush (event:Event) : void {
    this.brush.startDrag (true);
    Mouse.hide();
    }


    this.addEventListener(Event.ENTER_FRAME, moveBrush);


    And the code on the brush is

    function paint(obj:Object,myColor:Number):void {
    var newColor:ColorTransform = new ColorTransform();
    newColor.color = myColor;
    obj.transform.colorTransform = newColor;
    }




    function colorMe(event:MouseEvent):void {
    this.paint(this.tip, event.target.root.myColor);
    }




    mouseEnabled = false;

  2. #2
    why are you using this ​everywhere?

    also on the publishing screen set Permit Debugging, so you can discover on what line the error is
    As3 / JS/jQuery / HTML5 / CSS(3) / PHP (intermediate)

  3. #3
    I noticed lines like this in your code:
    Code:
    this.b_black.addEventListener(MouseEvent.MOUSE_UP, this.brush.colorMe);
    Have you initialized b_black variable before this line?
    Have you initialized brush variable before this line?
    A simple way to know it can be
    Code:
    trace(b_black);
    Another way may be to comment all the addEventListener functions and decomment them progressively. When the error appears, here's the line to analyze.
    Hope it helps.

  4. #4
    1,391
    posts
    Registered User
    i believe that the issue is that the Pooh instances do not contain the methods being assigned in the listeners, ie. this.Pooh.P_Tjar.colorMe

    the method colorMe() is being declared in the brush - but is it declared in each Pooh.partX ?

    however, you can also use the event object to target each part when invoked by the listener - so you could place a method in the main timeline code, such as:
    Code:
    Pooh.P_legs.addEventListener(MouseEvent.MOUSE _UP, colorPooh);
    ...
    
    function colorPooh( e:MouseEvent ):void {
      var newColor:ColorTransform = new ColorTransform();
      newColor.color = myColor;
      e.currentTarget.transform.colorTransform = newColor;
    }
    the use of "this" is not necessary, however it is also a stylistic preference by some and can help clarify the scope of your code (there are cases where it is necessary to do so)

  5. #5
    That was it, thanks!

  6. #6
    679
    posts
    Registered abUser
    I know its a little late but if you know how to include a swc in your project I wrote a little set of tools one of which would be handy in your case.

    It has a function called "addListener" which is a clever wrapper for the "addEventListener" function.
    What it does is allow you to bypass the event handler and call what ever function you like with your own custom parameters.

    i.e.

    addListener(b_black, MouseEvent.MOUSE_DOWN, setColour, 0x000000);
    addListener(b_grey, MouseEvent.MOUSE_DOWN, setColour, 0xgrey);
    .....
    ...
    ....
    addListener(b_skin, MouseEvent.MOUSE_DOWN , setColour, 0x....);


    function setColour(colour:uint):void
    {
    myColour = colour;
    }

    that way you can handle all those events with one handler, not one per event, and no big ifs/switch statements

    heres a link to the post about it:
    http://blog.bwhiting.co.uk/?p=266 (link is also in my sig below I think)



    I use it all the time and it saves me loaaads of typing
    blog (experiments and code)-> http://blog.bwhiting.co.uk/ <-
    as3 helper/shortcut lib (v1.2) -> http://code.google.com/p/bwhiting/downloads/list <-
    agal helper -> Clicky here <- UPDATED

  7. #7
    TheCanadian's Avatar
    10,303
    posts
    Noo doot aboot it, eh?
    You could also just make color a property of each movie clip and use Event#target to get the one that was clicked.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012