Skip to main content
Inspiring
February 5, 2010
Question

Can I reference static class vars via a string?

  • February 5, 2010
  • 1 reply
  • 262 views

Hi all,

I am trying to set the value of some static vars but I need to reference the class with a string rather than a proper constructor. In AS3 I can do this with:

var ref:Class = getDefinitionByName(classDefinitionAsString) as Class;

ref[varNameAsString] = newValue;

I can't find an equivelant approach that will work in AS2 though. I have tried:

var ref:Object = new [classDefinitionAsString];

ref[varNameAsString] = newValue;

This seems to just create an Object and as the vars that I am trying to access are static I don't really want to be using 'new' I just want to reference the vars.

Is this even possible in AS2 and if so can anyone explain how I might do this?

Cheers for any help

This topic has been closed for replies.

1 reply

Inspiring
February 5, 2010

I seem to have found a solution that works (for now at least). Not quite sure of the details

but this does it for me.

http://dynamicflash.com/2005/03/class-finder/