• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

button not work

Explorer ,
Dec 24, 2018 Dec 24, 2018

Copy link to clipboard

Copied

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()

Views

277

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 24, 2018 Dec 24, 2018

Copy link to clipboard

Copied

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);   }

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2018 Dec 25, 2018

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines