English 中文(简体)
AS3: 如果变量为目标类型,则核对
原标题:AS3: Checking if a variable is of the Object type

我想做的是行动文件3:

if(variable is Object) ...;
else ...;

可以是String(,Number(>,Array(),Object(.

目前,上述所有这类检查都属于实情。 但是,我只想回去对用<代码>新目的(<>>/代码>的物体。

任何帮助都会受到高度赞赏!

最佳回答

您应努力利用这一职能——、QualisedClassName。 这里有一部说明其如何掌握所列出的不同数据类型的代码,尤其见Array和数字的区别:

<><>Code>:

var o = new Array();                
trace ("var o = new Array()");
trace (getQualifiedClassName(o));
trace (typeof(o));      
var o = new Object();   
trace ("var o = new Object();");
trace (getQualifiedClassName(o));
trace (typeof(o));
var o = new String();
trace ("var o = new String()");
trace (getQualifiedClassName(o));
trace (typeof(o));
var o = new Number()
trace ("var o = new Number()");
trace (getQualifiedClassName(o));
trace (typeof(o));              
var o = 3.14;
trace ("var o = 3.14");
trace (getQualifiedClassName(o));
trace (typeof(o));

结果:

var o = new Array()
Array
object
var o = new Object();
Object
object
var o = new String()
String
string
var o = new Number()
int
number
var o = 3.14
Number
number

我假定,获得“QualisedClassName”是你重新研究的,这在“闪电”计划中:

import flash.utils.getQualifiedClassName;
问题回答

围绕其中一项内容进行询问:

if (variable.constructor.toString().match(/object/i) ==  Object )

if (variable.constructor.toString().indexOf("Object") != -1)

如果物体为目的,则建筑设计师的扼杀将类似目标。

function Object() { ... }

因此,你可以检查。

您也可使用<条码>,<条码>,<>条码>。 反对: a) 具有超等级:

public static function isObject( obj:* ):Boolean
{
    if ( obj == null )
        return false;
    return ( getQualifiedSuperclassName( obj ) == null );
}

各位来到这里,尝试这样做。

var ob:Object = new Object();

trace(ob); //[object Object]
trace(typeof(ob) == "object"); //true

if(typeof(ob) == "object"){
    //true
}else{
    //false
}




相关问题
Flex: Text Input that accepts number only

Need a code that only accepts numbers. Upon inputting, the code must check if it is number, if not, it must remove the entered key or not enter it at all

How to dynamically generate variables in Action Script 2.0

I have a for loop in action script which I m trying to use to dynamically create variable. Example for( i = 0 ; i &lt 3 ; i++) { var MyVar+i = i; } after this for loop runs, i would like to ...

drag file(s) from destop directly to flash webpage

Could someone please let me know if is possible to drag (multiple) files from desktop directly into a flash webpage. If yes could you please link me to some online resources.

Can XMLSocket send more than once in a frame?

I have a XMLSocket and I call send twice in the same function. The first send works but the second does not? Does XMLSocket have a restriction to only send one message per frame? Do I have to queue ...

How do you stop a setInterval function?

I have a function that I want to run at an interval within a frame. I use the following code to start the function: var intervalID = setInterval(intervalFunction, 3000); Then, in a button s ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...