Accessing a class like array
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
So I was just messing around in flash and was wondering if there was a way to access any class properties with array notation.
Say I have class Test:
public class Test {
public static var one:int = 1;
public static var two:int = 2;
public static var three:int = 3;
public function Test() {
}
}
I could access those values like Test.one, however I was wondering if there was a way to access them like Test[0], where Test[0] would output "1."
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
Why don't you push the variables into an array inside of your Test class and access them that way?
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
At 12/6/13 12:40 PM, Sam wrote: Why don't you push the variables into an array inside of your Test class and access them that way?
That is an option, definitely, but I was just curious if my above question was possible. I don't think I would ever need to use it, haha.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
At 12/6/13 12:44 PM, coln wrote:At 12/6/13 12:40 PM, Sam wrote: Why don't you push the variables into an array inside of your Test class and access them that way?That is an option, definitely, but I was just curious if my above question was possible. I don't think I would ever need to use it, haha.
I've just given it a go by creating a class that extends Array. Of course you get all the methods such as push and pop, but you can't access values via square brackets as easily, as far as I can tell. Maybe someone with a bit more knowledge can give you a better answer.
Some reading that you might be interested in: Extending the Array Class and Data Access with array and proxy extending.
- coln
-
coln
- Member since: Aug. 1, 2011
- Offline.
-
- Forum Stats
- Member
- Level 01
- Musician
At 12/6/13 01:07 PM, Sam wrote: Some reading that you might be interested in: Extending the Array Class and Data Access with array and proxy extending.
Very interesting indeed. Thanks for the reply!

