Danny, You can use an Array method like slice() or concat([]), which will create a duplicate of ur original array, and pass that to your function.
So your code would become: function generic(tObj:Object) { if (tObj instanceof Array) { doMyArrayFunction(tObj.slice()) } else { doSomethingElse() } } function doMyArrayFunction(tArr:Array) { ... } Unless there is some compelling reason that you have to pass around the same array's reference, this should help. Cheers, Arul Prasad. On 7/23/07, Danny Kodicek <[EMAIL PROTECTED]> wrote:
> Danny, > > I'm still not entirely clear on what you're attempting to do. > Can you show more code to give us a bigger picture? Thanks to everyone for suggestions and comments. Many of them, I suspect, would suffer from the same problem, though. For Steven, here's the problem in a bit more detail: function generic(tObj:Object) { if (tObj instanceof Array) { doMyArrayFunction(tObj) } else { doSomethingElse() } } function doMyArrayFunction(tArr:Array) { ... } This throws a compiler error because in the first function tObj is defined as an Object and the compiler isn't clever enough to realise that by the time we reach doMyArrayFunction it has to be of type Array. If the class I was trying to cast it to was anything except Array, I could use something like this: function generic(tObj:Object) { if (tObj instanceof MyClass) { doMyFunction(MyClass(tObj)) } else { doSomethingElse() } But because Array has a special constructor, Array(tObj) returns [tObj] instead of leaving it unchanged and just casting it to an Array. The solution I used works much the same way as Ian's: essentially it takes advantage of the fact that Flash's compiler isn't able to check the object type of sub-items of an object or array, so it ignores them (and assumes you've done your job correctly). John's solution is probably better from a strict OO standpoint, but mine works well enough, so... Danny _______________________________________________ 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
-- Arul Prasad http://arulprasad.blogspot.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