Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if an object is dynamic in AS3

In Action Script 3, you can write a class that defines a dynamic object (MovieClip and Object are two examples), this objects can be modified in run-time. What I want to know if is there some way (in run-time, of course) to know if certain object is dynamic or not.

PS: Without making something like this:

function isDynamic(object) {
    try {
        object.newProperty = 'someValue'
    } catch (e) {
        return false
    }
    return true
}
like image 347
Lucas Gabriel Sánchez Avatar asked Dec 07 '22 07:12

Lucas Gabriel Sánchez


2 Answers

CookieOfFortune has the right idea, but unfortunately the code itself has problems, isDynamic is an attribute, and the returned value will be a XMLList with a value of a String that reflects a true or false value, not a child node that directly returns a Boolean. It should look more like this:

function isDynamic(object) : Boolean
{
    var type:XML = describeType(object);
    return [email protected]() == "true";
}
like image 164
Bryan Grezeszak Avatar answered Dec 15 '22 07:12

Bryan Grezeszak


Be careful!

Anytime you want to use the describeType() function, please please please use the variation:

import mx.utils.DescribeTypeCache;
var typeDesc:XML = DescribeTypeCache.describeType(object).typeDescription;

Performance of making repeated calls to the runtime reflective machinery will absolutely suck. That's why Adobe invented the DescribeTypeCache class.

like image 27
verveguy Avatar answered Dec 15 '22 07:12

verveguy