I have a simple AS3 class that just holds private variables. Each private variable has a getter function, but not all of them have setter functions. At runtime, Is there a way of telling which properties do not have setters but are read-only? Then I can decide to give the user an input field to edit the properties that have setters.
+4
A:
Passing any object to describeType would return you XML containing very detailed information about object. to know if its readonly you can access following node of xml,
xmlReturnedFromDescType.accessor.access
This would be one of three, namely - readonly, writeonly, and readwrite.
Hope this helps.
Bhavesh.Bagadiya
2010-08-27 01:34:33
+1
A:
As mentioned, you can use describeType() that will return an XML object will all the type information. However, if you are uncomfortable working with the XML data, you can use the reflection API of AS3Commons-Reflect: http://www.as3commons.org
Here is an example:
var type:Type = Type.forClass(MyClass);
for each (var accessor:Accessor in type.accessors) {
if (accessor.writeable) {
// do something with writeable property
}
}
Christophe Herreman
2010-08-27 07:57:43
+1
A:
Also, if you happen to be doing a lot of calls to describeType, you should consider using the DescribeTypeCache for increased awesomeness (and also speed)
tousdan
2010-08-27 18:28:00