如何知道,如果一个对象是动态的,在AS3动态

2023-09-08 13:25:09 作者:君未叹沉香

在动作脚本3,你可以写一个定义动态对象(影片剪辑和对象是两个例子),这个对象可以在运行时修改类。我想知道,如果是(当然是在运行时,)有一些方法可以知道某个对象是动态的还是不行。

PS:如果不做这样的事情:

 函数isDynamic(对象){
    尝试 {
        object.newProperty ='someValue中'
    }赶上(五){
        返回false
    }
    返回true
}
 

解决方案

CookieOfFortune有正确的想法,但不幸的是C本身的$ C $有问题,isDynamic是一个属性,并且返回的值是一个值的XMLList一个字符串,反映了一个true或false值,而不是直接返回布尔子节点。它应该看起来更像是这样的:

 函数isDynamic(对象):布尔
{
    VAR类型:XML =不如describeType(对象);
    返回类型@ isDynamic.toString()==真。
}  
Flash 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
}

解决方案

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 type.@isDynamic.toString() == "true";
}