Link to home
Start Free TrialLog in
Avatar of BloodGrinder
BloodGrinderFlag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

What exactly are you trying to do?

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)?
SOLUTION
Avatar of Gary Benade
Gary Benade
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of petiex
petiex
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps a little explanation at what's actually happening now:

If you call
checkStyle("hurz")

Open in new window

the lookup in line 2 of checkStyle will return null and nothing will happen.
If you however call
checkStyle("constant3")

Open in new window

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.
Avatar of BloodGrinder

ASKER

Both Solution worked