Skip to main content
Inspiring
December 30, 2016
Answered

Duplicate function on Menu

  • December 30, 2016
  • 1 reply
  • 277 views

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

This topic has been closed for replies.
Correct answer kglad

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

}

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 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);

}

}

Inspiring
January 2, 2017

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

Thanks again!

kglad
Community Expert
Community Expert
January 2, 2017

you're welcome.