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

1021: Duplicate function definition.

New Here ,
May 16, 2012 May 16, 2012

Copy link to clipboard

Copied

Well, I am trying to generate a random number and send the users to that keyframe in flash but I keep getting the errors

Symbol 'WholeFile', Layer 'actions', Frame 3, Line 3 1151: A conflict exists with definition speed in namespace internal.

Symbol 'WholeFile', Layer 'actions', Frame 3, Line 4 1021: Duplicate function definition.

on each of the keyframes for the random number.

Here is the code:

On the main generator

  var high:Number = 13;

  var low:Number= 1;

 

  var district = (Match.floor(Math.random()*(1+high-low))+low).toString();

if(district == 1)

{

  gotoAndStop("district1");

}

else if(district == 2)

{

  gotoAndStop("district2");

}

  else if(district == 3)

{

  gotoAndStop("district3");

}

  else if(district == 4)

{

  gotoAndStop("district4");

}

else if(district == 5)

{

  gotoAndStop("district5");

}

else if(district == 6)

{

gotoAndStop("district6");

}

  else if(district == 7)

{

  gotoAndStop("district7");

}

  else if(district == 8)

{

  gotoAndStop("district8");

}

  else if(district == 9)

{

  gotoAndStop("district9");

}

  else if(district == 10)

{

  gotoAndStop("district10");

}

  else if(district == 11)

{

  gotoAndStop("district11");

}

else if(district == 12)

{

  gotoAndStop("district12");

}

else if (district == 13)

{

  gotoAndStop("capitol");

}

on the generated number frame

import fl.transitions.*;

import fl.transitions.easing.*;

var speed:Number = 3;

function comeToMe(event:MouseEvent){

   var obj:Object = event.target;

   var tweenX:Tween = new Tween(plyr, "x", None.easeNone, plyr.x, obj.x, speed, true);

   var tweenY:Tween = new Tween(plyr, "y", None.easeNone, plyr.y, obj.y, speed, true);

   addEventListener(Event.ENTER_FRAME, loopFunction);

   var obj_clip:MovieClip = obj as MovieClip;

   function loopFunction(event:Event):void{

      if(plyr.hitTestObject(obj_clip)) {

        status_txt.text = "Welcome to "+obj_clip.name+" have fun!";

        tweenX.stop();

        tweenY.stop();

        removeEventListener(Event.ENTER_FRAME, loopFunction);

      }

   }

}

bank.addEventListener(MouseEvent.CLICK, comeToMe);

home.addEventListener(MouseEvent.CLICK, comeToMe);

business.addEventListener(MouseEvent.CLICK, comeToMe);

please help and tell me what's wrong with my code!!

TOPICS
ActionScript

Views

4.0K

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

correct answers 1 Correct answer

LEGEND , May 18, 2012 May 18, 2012

Do you happen to be repeating code in different frames?

Votes

Translate

Translate
Contributor ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

var district = (Match.floor(Math.random()*(1+high-low))+low).toString();

In this Math is misspelled as Match. Change it to Math.floor.

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
New Here ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

ok thanks.

But it still flickers from the loading screen to the welcome screen when i load my game.

It says 1151: A conflict exists with definition speed in namespace internal. and 1021: Duplicate function definition.

What should I do? Here is my code:

import fl.transitions.*;

import fl.transitions.easing.*;

var speed:Number = 3;

function comeToMe(event:MouseEvent){

   var obj:Object = event.target;

   var tweenX:Tween = new Tween(plyr, "x", None.easeNone, plyr.x, obj.x, speed, true);

   var tweenY:Tween = new Tween(plyr, "y", None.easeNone, plyr.y, obj.y, speed, true);

   addEventListener(Event.ENTER_FRAME, loopFunction);

   var obj_clip:MovieClip = obj as MovieClip;

   function loopFunction(event:Event):void{

      if(plyr.hitTestObject(obj_clip)) {

        status_txt.text = "You hit the "+obj_clip.name+" have fun!";

        tweenX.stop();

        tweenY.stop();

        removeEventListener(Event.ENTER_FRAME, loopFunction);

      }

   }

}

bank.addEventListener(MouseEvent.CLICK, comeToMe);

home.addEventListener(MouseEvent.CLICK, comeToMe);

business.addEventListener(MouseEvent.CLICK, comeToMe);

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
Contributor ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

I checked this code but didn't get any errors

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
Contributor ,
May 17, 2012 May 17, 2012

Copy link to clipboard

Copied

Your code is working fine for me. Once check speed variable is declared anywhere in your code. If it is then change speed variable name to some other name. If it is not then uncheck the option "Automatically declare stage instances" in Action Script 3.0 publish settings.

Coming to duplicate function defintion error, Check for comeToMe function also. If there is any duplicate find somewhere in your code then change it. If it is not then try with different function names for addEventListeners.

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
New Here ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

ok thanks.

but now i get this error

Symbol 'WholeFile', Layer 'world', Frame 3, Line 4 1151: A conflict exists with definition speed in namespace internal.

Symbol 'WholeFile', Layer 'world', Frame 4, Line 9 1021: Duplicate function definition.

here's the code:

import fl.transitions.*;

import fl.transitions.easing.*;

var speed:Number = 3;

function comeToMe(event:MouseEvent){

   var obj:Object = event.target;

   var tweenX:Tween = new Tween(plyr, "x", None.easeNone, plyr.x, obj.x, speed, true);

   var tweenY:Tween = new Tween(plyr, "y", None.easeNone, plyr.y, obj.y, speed, true);

   addEventListener(Event.ENTER_FRAME, loopFunction);

   var obj_clip:MovieClip = obj as MovieClip;

   function loopFunction(event:Event):void{

      if(plyr.hitTestObject(obj_clip)) {

        status_txt.text = "You hit the "+obj_clip.name+" MovieClip and can now interact with it(no you cannot)";

        tweenX.stop();

        tweenY.stop();

        removeEventListener(Event.ENTER_FRAME, loopFunction);

      }

   }

}

bank.addEventListener(MouseEvent.CLICK, comeToMe);

home.addEventListener(MouseEvent.CLICK, comeToMe);

business.addEventListener(MouseEvent.CLICK, comeToMe);

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
LEGEND ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

Do you happen to be repeating code in different frames?

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
New Here ,
May 18, 2012 May 18, 2012

Copy link to clipboard

Copied

yeah. I deleted it from the other frames but now it doesn't do what I want it to.

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
LEGEND ,
May 19, 2012 May 19, 2012

Copy link to clipboard

Copied

You can share functions and variables along a timeline if they do the same thing, meaning you do not need to rewrite them in different frames.  If they happen to do diferent things, then you need to use new names.  Similarly, you can share variables.  If you declare a function or variable in a frame, if you extend that layer along the timeline they can be used along the length of the timeline in which they extend.

So in frame 1, if you declare a variable...

var someVar:* = initialValue;   // * represents its Class type

you can reuse that variable anywhere along the timeline, but you cannot redeclare (cannot use " var someVar:* " again) again for it anywhere else along that timeline.  The same with functions... in frame 1 you could have:

function doSomething(argument:*):void {

     // do something

}

and in later frames you can call that same function using: doSomething(arg);  but you cannot create another function by the same name (cannot use "function doSomething(...)" again)

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
LEGEND ,
May 19, 2012 May 19, 2012

Copy link to clipboard

Copied

One other thing worth mentioning is that when it comes to functions, you can often have one function that is written generically such that it makes use of arguments or external variables to process different things in a similar manner. 

An example of this would be a function that processes different buttons being clicked.  If the processing is the same for each button but invoilves different instances of objects, you can use the event argument that gets passed to the function to determine which button was clicked and use that information to process relative to that button.

function buttonClicked(evt:MouseEvent):void {

     // "evt.target" is the object that dispatched the event

     // "evt.currentTarget" is the object with the listener assigned to it

     // sometimes evt.target is the same as evt.currentTarget, sometimes not.

}

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
New Here ,
May 19, 2012 May 19, 2012

Copy link to clipboard

Copied

Thanks, this helped remove that error but now, when I try to call the function, i get this eror:

Symbol 'WholeFile', Layer 'world', Frame 3, Line 4 1084: Syntax error: expecting rightparen before colon.

so I don't know if i am calling it right or not but here's my code:

import fl.transitions.*;

import fl.transitions.easing.*;

stage.frameRate = 30;

comeToMe(event:MouseEvent);

loopFunction(event:Event);

bank.addEventListener(MouseEvent.CLICK, comeToMe);

home.addEventListener(MouseEvent.CLICK, comeToMe);

business.addEventListener(MouseEvent.CLICK, comeToMe);

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
LEGEND ,
May 19, 2012 May 19, 2012

Copy link to clipboard

Copied

The 4th line of what you show doesn't make sense, and is where your problem is anyways.  When you call a function you do not include the class identifier ":MouseEvent"    But since that function appears to be called by buttons as an event handler function, you probably do not want to be calling it that way... try removing that line altogether or explain why you have it there.

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 Beginner ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

Hi Ned,

I'm having the same issue as boyonfire, where I have a few buttons that spread thru different frames but I can't obviously having the same code repeating in different frames.

I guess what he was trying to do was what you said before "and in later frames you can call that same function using: doSomething(arg);"

So he just wrote "comeToMe(event:MouseEvent);" The name of his function plus what was inside the parentesis. That's how he interperted your "doSomething(arg);"

But since this not work, we now know this is not the right way to do it...

Can you please explain how we should be calling the function instead? And yes, the function is being called by a button.

Cheers,

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
LEGEND ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

The problem with what was done... comeToMe(event:MouseEvent);  was as I already explained.  You do not include the class of the argument when you call a function with an argument. 

If calling that function using that "event" argument was a valid approach (which it can be, but is also questionable since an event listener argument is normally passed without code specifying it), then the function call would have been...

     comeToMe(event); 

the ":MouseEvent" does not get included in the function call.

If the function is being called by an event listener, then you don't call it at all, you just specify it in the listener without any mention of the event argument...

    someBtn.addEventListener(MouseEvent.CLICK, comeToMe);

as I mentioned already, the event argument is automatically passed the the event handler function, so you do not need to specify it in the listener.

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 Beginner ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

Thanks Ned, this solved the problem. It's quite simple now that you've pointed it out!

We just need to write the  function in the first frame and then, whenever we want to call it again in other frames, just use the "someBtn.addEventListener(MouseEvent.CLICK, comeToMe);"

Again, thanks for this. It was very helpfull!

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
LEGEND ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

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