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

Duplicate function on Menu

Participant ,
Dec 30, 2016 Dec 30, 2016

Hi,

I've made a menu which currently has 2 buttons to go to different frames.

In my actions I have `stop();` on each frame so it doesn't repeatedly loop.

I have added code for 2 buttons which is;

stop();

//click btnTests and go to revision tools

instTest.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

{

  gotoAndStop(4);

}

//click btnResources and go to resources

instResources.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_5);

function fl_ClickToGoToAndStopAtFrame_5(event:MouseEvent):void

{

  gotoAndStop(3);

}

The error I get is 'duplicate function', but I don't know of a way to not have the same function twice.

What do I need to do to have 2 clickable buttons to go to different frames?

Thanks,
Jack

230
Translate
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

correct answers 1 Correct answer

Community Expert , Dec 30, 2016 Dec 30, 2016

give the function different names (eg, 1.) or use one function and use a conditional statement (eg, 2.):

1.

instTest.addEventListener(MouseEvent.CLICK, f4);

function f4(event:MouseEvent):void

{

  gotoAndStop(4);

}

//click btnResources and go to resources

instResources.addEventListener(MouseEvent.CLICK, f3);

function f3(event:MouseEvent):void

{

  gotoAndStop(3);

}

2.

instTest.addEventListener(MouseEvent.CLICK, f);

//click btnResources and go to resources

instResources.addEventListener(MouseEvent.CLICK, f);

functi

...
Translate
Community Expert ,
Dec 30, 2016 Dec 30, 2016

give the function different names (eg, 1.) or use one function and use a conditional statement (eg, 2.):

1.

instTest.addEventListener(MouseEvent.CLICK, f4);

function f4(event:MouseEvent):void

{

  gotoAndStop(4);

}

//click btnResources and go to resources

instResources.addEventListener(MouseEvent.CLICK, f3);

function f3(event:MouseEvent):void

{

  gotoAndStop(3);

}

2.

instTest.addEventListener(MouseEvent.CLICK, f);

//click btnResources and go to resources

instResources.addEventListener(MouseEvent.CLICK, f);

function fl(event:MouseEvent):void

{

if(e.currentTarget.name=='instTest'){

gotoAndStop(4);

} else {
gotoAndStop(5);

}

}

Translate
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
Participant ,
Jan 02, 2017 Jan 02, 2017

Thanks kglad - I named them instead of using conditional. I like simple!

Thanks again!

Translate
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 ,
Jan 02, 2017 Jan 02, 2017
LATEST

you're welcome.

Translate
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