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 object that you're passing around. Rather than at compile time. So it doesn't know or care whether you typed i:Object or i:String - it's just working with the actual value of i, which has an underlying type.
This code works because a number is represented by a Number class, which is a subclass of Object - and because a string is represented by a String class, which is also a subclass of Object. (This isn't quite true, but is true enough for these circumstances!). Because Object is the common superclass, the compiler doesn't get upset when you type myFunction(5) or myFunction("fred"). It's somewhat clearer if I show you an example of a class (rather than Number or String - they are both a little bit different internally but Flash hides the differences from us using something called autoboxing): class A { function A(){} } class B extends A{ function B(){} } var a:A=new A(); var b:B=new B(); var c:A=new B(); trace(a instanceof A); //true trace(b instanceof A); //true trace(c instanceof A); //true trace(a instanceof B); //false trace(b instanceof B); //true trace(c instanceof B); //true As you can probably see, instanceof is working on the underlying object that's been created, never mind what you typed after the colon. The reason I use instanceof instead of typeof is that typeof would give you a less useful answer: trace(typeof A); // "function" (because it's a constructor function) trace(typeof B); // "function" (because it's a constructor function) In your case, typeof should do the job. But just bear in mind that it's an old operator, and should probably be retired. ;-) HTH, Ian On 6/15/06, Adrian Park <[EMAIL PROTECTED]> wrote:
Ian, I'm intrigued if your suggestion works - I had considered it but assumed it wouldn't work because the result of the typeOf operation would just be 'object' (since that is what the parameter is typed as).
_______________________________________________ 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