Skip to main content
Adrien_
Known Participant
July 25, 2011
Question

Duplicate Function Deffinition error

  • July 25, 2011
  • 2 replies
  • 342 views

I have an Interface as suh:

function loadObject(string:String):Boolean

In my class that implements this I have:

loadObjects(monsterFile:String):Boolean{}

loadObjects(itemsFile:String):Boolean{}

Obviously this is wrong in actionsript when it should NOT be due to the language being statically typed.

Now in pervious threads people said to user ...rest and ...args as they will allow me to pass in what ever I want. How ever in this case I have very specific arguments to pass in, since I cannot do this in AS how would I use rest and or args to do this and make sure that one method loads only the MonsterFile (what ever file they pass in, or the Items file...? Essentially should they be two methods or one?

This topic has been closed for replies.

2 replies

HandVoodoo
Participating Frequently
July 27, 2011

You could also try passing a name with the string and than follow the function up with a switch statement.

function loadObject(someFile:String, someFileName:String):Boolean{

     switch(someFileName){

          case "Monster": //do whatever for monster

          break;

          case "Items": //do Items logic

          break;

          default : //something

          break;

     }

     return someBoolean;

}

So in your progam you would call this function with 2 arguments:

loadObject(yourFile, "nameOftheFile");

nameOftheFile would be a literal name of your naming typed out.

kglad
Community Expert
Community Expert
July 25, 2011

you can have in any class, at most, one method/function with a given name.  so, in your class, you need to fix that:

function loadObject(whatever:String):Boolean{

.

.

}

should appear once only