[Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Adrian Park
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

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Daniel Cascais
you could try this: private function myMethod( i:Object ):Void On 6/15/06, Adrian Park [EMAIL PROTECTED] wrote: 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

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread eric dolecki
you could use 2 params... use String for one, Number for the other - and then use accordingly? On 6/15/06, Adrian Park [EMAIL PROTECTED] wrote: 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

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread eka
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

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Ian Thomas
Hi Adrian, I'd do it like this: private function myMethod(i:Object):Void { if (i instanceof String) { // do this } else if (i instanceof Number) { // do this } else { // report an error } } And, as you see, stick in an error condition - because by changing the input type to

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Adrian Park
Hi all. Thanks for the responses. I think my favoured route would be by Typing the parameter as generic Object as it means it's still one parameter which seems neater. Ian, I'm intrigued if your suggestion works - I had considered it but assumed it wouldn't work because the result of the typeOf

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Ian Thomas
Hi Adrian, Your i:Object declaration is a _compile-time_ declaration. All it's there for is to make the compiler happy. instanceof, which is what I'm using (typeof is an older construct which is more limited and less safe) is an operator which does a comparison at runtime on the underlying

Re: [Flashcoders] Accepting 1 parameter with 2 possible types in a method?

2006-06-15 Thread Nicolas Cannasse
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 }