Skip to main content
Known Participant
December 25, 2018
Question

button not work

  • December 25, 2018
  • 2 replies
  • 384 views

i make this button to return to scene 1 but it get error how can i fix??

stop();

Object(this).myExit.addEventListener(MouseEvent.CLICK, nonon);

function nonon (e:MouseEvent):void{

  gotoAndStop(1,"s1");

  }

the error massage is : 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  at فذائي_fla::MainTimeline/hitsa7an()

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    December 25, 2018

    Hi.

    This error happens probably because you switch scenes but you don't remove the enterFrame listener first. As you added the listener to the main timeline, when you go back to the "s1" scene, the main timeline is still there so the listener. But the objects being accessed inside of the handler function are no longer available.

    A suggestion is to write your handler function like this:

    function nonon(e:MouseEvent):void

    {

        removeEventListener(Event.ENTER_FRAME, hitsa7an);

        gotoAndStop(1, "s1");

    }

    I hope this helps.

    Regards,

    JC

    Known Participant
    December 25, 2018

    this the all code:

    stop();

    Object(this).myExit.addEventListener(MouseEvent.CLICK, nonon);

    function nonon (e:MouseEvent):void{

      gotoAndStop(1,"s1");

      }

     

     

     

    //--------------------------------------

     

    juse.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    juse.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

     

     

     

    cheesy.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    cheesy.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

     

    batter.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    batter.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

     

    avocado.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    avocado.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    orang.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    orang.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    apple.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    apple.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    melon.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    melon.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    strobary.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    strobary.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    carrot.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    carrot.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    latos.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    latos.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    spinch.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    spinch.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    tomato.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    tomato.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    purpol.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    purpol.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    brad2.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    brad2.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    ricee.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    ricee.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    uu.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    uu.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    myMilk.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    myMilk.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    myfish.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    myfish.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    meat.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    meat.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

    myEgges.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;

    myEgges.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;

     

    //---------------------------------------------------------- 

    function  startdraging(e:MouseEvent):void{

      e.currentTarget.startDrag();

      }

     

      function stopdraging (e:MouseEvent):void{

      e.currentTarget.stopDrag();

      }

      //-------------------------------------Hit sa7an

    addEventListener(Event.ENTER_FRAME,hitsa7an);

    function hitsa7an (e:Event):void{

      if(avocado.hitTestObject(sa7an)){

      nonoM.gotoAndStop(2);

      }else {  nonoM.gotoAndStop(1);   }

      }