BloodGrinder
asked on
Iterating over properties of a class Actionscript
Hi I wonder if someone could help.
Still being fairly new to programming as a whole,
I have an incoming string to a function which i wish to validate against a static constant from a class.
The class is ListStyleType and it has numerous constants of the like ListStyleType.Decimal, ListStyleType.Box etc
Now I could create an array and place all the constants in that, and then loop over the values, but I dont really want to have to type out 50 odd values as the string constants already exist
Therefore I was wondering if there was any way I could loop of the properties of the class itself
ie something like
private function checkStyle(incomingString) {
for each(var property:String in ListStyleType){
if (incomingString== property){
etc.....
}
}
}
Thanks in advance
Still being fairly new to programming as a whole,
I have an incoming string to a function which i wish to validate against a static constant from a class.
The class is ListStyleType and it has numerous constants of the like ListStyleType.Decimal, ListStyleType.Box etc
Now I could create an array and place all the constants in that, and then loop over the values, but I dont really want to have to type out 50 odd values as the string constants already exist
Therefore I was wondering if there was any way I could loop of the properties of the class itself
ie something like
private function checkStyle(incomingString)
for each(var property:String in ListStyleType){
if (incomingString== property){
etc.....
}
}
}
Thanks in advance
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps a little explanation at what's actually happening now:
If you call
If you however call
Now the function is incoked and the string itself and any other parameter is passed and the function is executed. You could also return a value if you needed to. I just did a void function, but any other type of function would work.
If you call
checkStyle("hurz")
the lookup in line 2 of checkStyle will return null and nothing will happen.If you however call
checkStyle("constant3")
Then the lookup will return a reference to the func3 function.Now the function is incoked and the string itself and any other parameter is passed and the function is executed. You could also return a value if you needed to. I just did a void function, but any other type of function would work.
ASKER
Both Solution worked
You want to create an input that takes a string and if this string matches a constant you want it to execute something (each constant different action)?