Re: [Flashcoders] Array like access to custom class?
Can I provide array like access to a custom collection object? The easiest way would be to extend Array. Then you start with all the functionality of the Array object, and you can add or remove functionality as needed. ryanm ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Array like access to custom class?
someClass.elem(0) = myObj; Nope - of course not. elem is a function - you can't use it that way. You can do anything you like, though. Create your own function for instance: someClass.setElem(0, myObj); Or a general addElem, that doesn't take a position argument but just pushes to the end: someClass.addElem(myObj); Anything you like :) -- Morten Barklund - Information Architect - Shockwaved Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark Phone: +45 7027 2227 - Fax: +45 3369 1174 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Array like access to custom class?
How do you implement assigning values to that array item? someClass.elem(0) = myObj; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dan Thomas Sent: 20 December 2005 14:28 To: Flashcoders mailing list Subject: RE: [Flashcoders] Array like access to custom class? Thanks very much Morten DannyT -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Morten Barklund Shockwaved Sent: 20 December 2005 13:15 To: Flashcoders mailing list Subject: Re: [Flashcoders] Array like access to custom class? Dan Thomas wrote: > Can I provide array like access to a custom collection object? > > E.g. > > Class MyClass > { > private var myArray:Array; > > public function getArray():Array > { > return this.myArray; > } > } > > [snip] > > How can I change it so I can achieve the same thing but with access to > the items like this: > > var someClass:MyClass = new MyClass; > thisItem = someClass[0]; Use __resolve: class MyClass { private var myArray:Array; public function __resolve(name:String):Object { if (!isNaN(name)) { return myArray[Number(name)]; } else { return false; } } } But it will not "strict type" properly at all, so you lose major benefits of using as2 this way. I'd do it: class MyClass { private var myArray:Array; public function elem(n:Number):Object { return myArray[n]; } } And: var someClass:MyClass = new MyClass; thisItem = someClass.elem(0); Then you will get proper validation of argument, parameter and return types. -- Morten Barklund - Information Architect - Shockwaved Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark Phone: +45 7027 2227 - Fax: +45 3369 1174 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders This message and any attachments should only be read by those persons to whom it is addressed and be used by them for its intended purpose. It must not otherwise be reproduced, modified, distributed, published or actioned. If you have received this e-mail in error, please notify us immediately by telephone on 01202 237000 and delete it from your computer immediately. This e-mail address must not be passed to any third party or be used for any other purpose. Every reasonable precaution has been taken to ensure that this e-mail, including attachments, does not contain any viruses. However, no liability can be accepted for any damage sustained as a result of such viruses, and recipients are advised to carry out their own checks. Moov2 Ltd cannot accept liability for statements made which are clearly the senders own and not made on behalf of the Moov2 Ltd. An e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business purposes. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Array like access to custom class?
Thanks very much Morten DannyT -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Morten Barklund Shockwaved Sent: 20 December 2005 13:15 To: Flashcoders mailing list Subject: Re: [Flashcoders] Array like access to custom class? Dan Thomas wrote: > Can I provide array like access to a custom collection object? > > E.g. > > Class MyClass > { > private var myArray:Array; > > public function getArray():Array > { > return this.myArray; > } > } > > [snip] > > How can I change it so I can achieve the same thing but with access to > the items like this: > > var someClass:MyClass = new MyClass; > thisItem = someClass[0]; Use __resolve: class MyClass { private var myArray:Array; public function __resolve(name:String):Object { if (!isNaN(name)) { return myArray[Number(name)]; } else { return false; } } } But it will not "strict type" properly at all, so you lose major benefits of using as2 this way. I'd do it: class MyClass { private var myArray:Array; public function elem(n:Number):Object { return myArray[n]; } } And: var someClass:MyClass = new MyClass; thisItem = someClass.elem(0); Then you will get proper validation of argument, parameter and return types. -- Morten Barklund - Information Architect - Shockwaved Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark Phone: +45 7027 2227 - Fax: +45 3369 1174 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders This message and any attachments should only be read by those persons to whom it is addressed and be used by them for its intended purpose. It must not otherwise be reproduced, modified, distributed, published or actioned. If you have received this e-mail in error, please notify us immediately by telephone on 01202 237000 and delete it from your computer immediately. This e-mail address must not be passed to any third party or be used for any other purpose. Every reasonable precaution has been taken to ensure that this e-mail, including attachments, does not contain any viruses. However, no liability can be accepted for any damage sustained as a result of such viruses, and recipients are advised to carry out their own checks. Moov2 Ltd cannot accept liability for statements made which are clearly the senders own and not made on behalf of the Moov2 Ltd. An e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business purposes. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Array like access to custom class?
Dan Thomas wrote: Can I provide array like access to a custom collection object? E.g. Class MyClass { private var myArray:Array; public function getArray():Array { return this.myArray; } } [snip] How can I change it so I can achieve the same thing but with access to the items like this: var someClass:MyClass = new MyClass; thisItem = someClass[0]; Use __resolve: class MyClass { private var myArray:Array; public function __resolve(name:String):Object { if (!isNaN(name)) { return myArray[Number(name)]; } else { return false; } } } But it will not "strict type" properly at all, so you lose major benefits of using as2 this way. I'd do it: class MyClass { private var myArray:Array; public function elem(n:Number):Object { return myArray[n]; } } And: var someClass:MyClass = new MyClass; thisItem = someClass.elem(0); Then you will get proper validation of argument, parameter and return types. -- Morten Barklund - Information Architect - Shockwaved Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark Phone: +45 7027 2227 - Fax: +45 3369 1174 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders