Re: [Flashcoders] Casting to Array

2007-08-06 Thread Hans Wichman
btw one more compilaltion error circumventing hack that seems to work: [yourObj][0] ;-S greetz JC On 7/24/07, Danny Kodicek <[EMAIL PROTECTED]> wrote: > > > > > That's a fair point. It's more the principle of the thing - it was > > > frustrating not to be *able* to make it strict. But yes, lea

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Danny Kodicek
> That's a fair point. It's more the principle of the thing - it was > frustrating not to be *able* to make it strict. But yes, leaving off > the :Object would be a better solution. Well, you can't do argument overloading in AS2 (nor AS3, I believe), so you can't have pure polymorphism in Flas

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Steven Sacks
> That's a fair point. It's more the principle of the thing - it was > frustrating not to be *able* to make it strict. But yes, leaving off > the :Object would be a better solution. Well, you can't do argument overloading in AS2 (nor AS3, I believe), so you can't have pure polymorphism in Flash

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Danny Kodicek
You're "hacking" it either way. This one function is not going to cause coder confusion. You're leaving the type off so you can pass any type. Considering you type everything else, it's pretty obvious to anyone who looks at it what's going on. Adding extra lines of code that put a paramete

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Steven Sacks
In the more general case, I disagree that AS2 gains nothing from type-checking. But you weren't being general. :-) I thought I was, but I realize now that I made a flawed assumption. You don't know my coding practices and how I write everything as strict as I can and use MTASC for compiling,

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Steven Sacks
You're "hacking" it either way. This one function is not going to cause coder confusion. You're leaving the type off so you can pass any type. Considering you type everything else, it's pretty obvious to anyone who looks at it what's going on. Adding extra lines of code that put a parameter

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Ian Thomas
Steven, I do see what you're getting at - having reviewed Danny's code, in this instance, you're right (and I was being too general and should have paid more attention!). In the more general case, I disagree that AS2 gains nothing from type-checking. But you weren't being general. :-) Ian On

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Ian Thomas
On 7/23/07, Steven Sacks <[EMAIL PROTECTED]> wrote: If you look at it objectively, you're adding extra lines of code for no reason. AS2 has absolutely no gains from strict typing. The compiled code doesn't gain anything - but if (like me) you're writing code libraries to be used by other prog

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Steven Sacks
> 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). Danny, It seems to me if you'r

Re: [Flashcoders] Casting to Array

2007-07-23 Thread Arul Prasad M L
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() }

RE: [Flashcoders] Casting to Array

2007-07-23 Thread Danny Kodicek
> 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 de

RE: RE: [Flashcoders] Casting to Array

2007-07-20 Thread David Ngo
fine. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Mark Hawley Sent: Friday, July 20, 2007 1:44 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: RE: [Flashcoders] Casting to Array David's suggestion doesn't actually cast to arra

Re: [Flashcoders] Casting to Array

2007-07-20 Thread Hans Wichman
Hi Danny, its an annoying issue and a subtle difference between the flash ide and mtasc as well. When compiling in mtasc, Array(myObject) becomes a regular cast and not the freakish thing its in the Flash IDE:). greetz JC On 7/20/07, Steven Sacks <[EMAIL PROTECTED]> wrote: Danny, I'm still

Re: [Flashcoders] Casting to Array

2007-07-20 Thread R�kos Attila
Date:Friday, July 20, 2007, 3:03:55 PM Subject: [Flashcoders] Casting to Array --===-- I'm trying to do something like this: if (a instanceof Array) { doMyArrayFunction(a) } the doMyArrayFunction expects an Array obje

Re: [Flashcoders] Casting to Array

2007-07-20 Thread Steven Sacks
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? Danny Kodicek wrote: I'm trying to do something like this: if (a instanceof Array) { doMyArrayFunction(a) } ___ Flashcoder

Re: RE: [Flashcoders] Casting to Array

2007-07-20 Thread John Mark Hawley
anny Kodicek" <[EMAIL PROTECTED]> > Date: 2007/07/20 Fri AM 10:07:47 CDT > To: > Subject: RE: [Flashcoders] Casting to Array > > > As it's AS2, you might think about making it so > > doMyArrayFunction will not expect an array, but will take anything

Re: [Flashcoders] Casting to Array

2007-07-20 Thread Paul Andrews
- Original Message - From: "Danny Kodicek" <[EMAIL PROTECTED]> To: Sent: Friday, July 20, 2007 2:03 PM Subject: [Flashcoders] Casting to Array I'm trying to do something like this: if (a instanceof Array) { doMyArrayFunction(a) } the doMyArrayFunction expect

Re: [Flashcoders] Casting to Array

2007-07-20 Thread Ian Thomas
Danny, The shortest way I found of doing it is: var b:Array={arr:a}.arr; i.e. make it a property of an object, then unbox it again. Silly, but works syntactically. I'd love to see a shorter way. In AS3, Array(x) as an array creator still exists - you get around it using the new 'as' operator:

RE: [Flashcoders] Casting to Array

2007-07-20 Thread Danny Kodicek
> As it's AS2, you might think about making it so > doMyArrayFunction will not expect an array, but will take anything: > > class ArrayTest { > > public function ArrayTest(a) { > trace(a[0]); > } > > } > > > > new ArrayTest([1,2,3,4]); > > works fine.

Re: [Flashcoders] Casting to Array

2007-07-20 Thread Jim Kremens
As it's AS2, you might think about making it so doMyArrayFunction will not expect an array, but will take anything: class ArrayTest { public function ArrayTest(a) { trace(a[0]); } } new ArrayTest([1,2,3,4]); works fine. Jim Kremens _

RE: [Flashcoders] Casting to Array

2007-07-20 Thread David Ngo
: [Flashcoders] Casting to Array I'm trying to do something like this: if (a instanceof Array) { doMyArrayFunction(a) } the doMyArrayFunction expects an Array object, so this throws an error. What I would normally do in this case is cast the object to the class I'm expecting, but unfortunate

[Flashcoders] Casting to Array

2007-07-20 Thread Danny Kodicek
I'm trying to do something like this: if (a instanceof Array) { doMyArrayFunction(a) } the doMyArrayFunction expects an Array object, so this throws an error. What I would normally do in this case is cast the object to the class I'm expecting, but unfortunately Array(a) doesn't leave a unchanged,