Hello :) you can try this example :
private function _myMethod( args ):Void { var arg0 = arguments[0] ; switch (true) { case arg0 instanceof String : break ; case arg0 instanceof Number : break ; default throw new Error("Illegal Argument, " + arg0 + " must be String or Number") ; ) } For me ... this method is a good alternative :) EKA+ :) 2006/6/15, Adrian Park <[EMAIL PROTECTED]>:
Hi List, What's the neatest way of accepting a single parameter with 2 possible types into a method and then working out what type of parameter has been passed? e.g. in pseudo code private function myMethod( i:Number/String ):Void { if ( i is a String ) { // do this } else if ( i is a Number ) { // do this } } I can think of several alternatives : - passing a generic object which contains the property and then using typeof on that property - calling 2 different methods but, in this case, it just makes sense to be one since it's doing the same thing with either parameter (retrieving a bit of data from an Array which may be identified using a numerical id or a String ID) - limiting my method to accepting a String only and then defining a second method that returns the correspoding String identifier given a numerical identifier All of the ways I can think of seem dirty. Is there a nice clean way or is it wrong to expect the method to accept one parameter of different types? Thanks in advance, Adrian P. _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
_______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com