Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3将字符串转换为对象_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3将字符串转换为对象

Actionscript 3 AS3将字符串转换为对象,actionscript-3,Actionscript 3,考虑到字符串中的对象存在,我正在尝试将以下字符串转换为对象: var-exampleStr:String=“myObject.property1.property2” var-exampleObj:Object=exampleStr-as-Object 我将如何实现这一点,您是否可以提供一种替代方法?我假定您正在尝试从组合的字符串动态创建对象?如果是这样的话,我想你想要的是: var exampleObj:Object = this[ "myObject.property1.property2"

考虑到字符串中的对象存在,我正在尝试将以下字符串转换为对象:

var-exampleStr:String=“myObject.property1.property2”
var-exampleObj:Object=exampleStr-as-Object


我将如何实现这一点,您是否可以提供一种替代方法?

我假定您正在尝试从组合的字符串动态创建对象?如果是这样的话,我想你想要的是:

var exampleObj:Object = this[ "myObject.property1.property2" ];

这假定myObject的作用域是“This”,并且属性2也是一个对象。

我假定您正在尝试从组合字符串动态创建对象?如果是这样的话,我想你想要的是:

var exampleObj:Object = this[ "myObject.property1.property2" ];
   //Convert the string to  a property array       
    var t:Array = exampleStr.split(".");

    var exampleObj:Object = null;

    if (t.length > 0)
    {

        var objName:String = t[i];

        //get the object in the class
        exampleObj = this[objName];

        for (var i:int = 1; i < t.length; i++)
        {
            var propertyName:String = t[i];

            if (exampleObj.hasOwnProperty(propertyName))
            {
                exampleObj = exampleObj[propertyName];
            }
            else
            {
                break;
            }
        }
    }

这假定myObject的作用域是“This”,并且属性2也是一个对象。

我假定您正在尝试从组合字符串动态创建对象?如果是这样的话,我想你想要的是:

var exampleObj:Object = this[ "myObject.property1.property2" ];
   //Convert the string to  a property array       
    var t:Array = exampleStr.split(".");

    var exampleObj:Object = null;

    if (t.length > 0)
    {

        var objName:String = t[i];

        //get the object in the class
        exampleObj = this[objName];

        for (var i:int = 1; i < t.length; i++)
        {
            var propertyName:String = t[i];

            if (exampleObj.hasOwnProperty(propertyName))
            {
                exampleObj = exampleObj[propertyName];
            }
            else
            {
                break;
            }
        }
    }

这假定myObject的作用域是“This”,并且属性2也是一个对象。

我假定您正在尝试从组合字符串动态创建对象?如果是这样的话,我想你想要的是:

var exampleObj:Object = this[ "myObject.property1.property2" ];
   //Convert the string to  a property array       
    var t:Array = exampleStr.split(".");

    var exampleObj:Object = null;

    if (t.length > 0)
    {

        var objName:String = t[i];

        //get the object in the class
        exampleObj = this[objName];

        for (var i:int = 1; i < t.length; i++)
        {
            var propertyName:String = t[i];

            if (exampleObj.hasOwnProperty(propertyName))
            {
                exampleObj = exampleObj[propertyName];
            }
            else
            {
                break;
            }
        }
    }
这假定myObject的作用域是“This”,并且property2也是一个对象。

//将字符串转换为属性数组
   //Convert the string to  a property array       
    var t:Array = exampleStr.split(".");

    var exampleObj:Object = null;

    if (t.length > 0)
    {

        var objName:String = t[i];

        //get the object in the class
        exampleObj = this[objName];

        for (var i:int = 1; i < t.length; i++)
        {
            var propertyName:String = t[i];

            if (exampleObj.hasOwnProperty(propertyName))
            {
                exampleObj = exampleObj[propertyName];
            }
            else
            {
                break;
            }
        }
    }
var t:Array=exampleStr.split(“.”); var exampleObj:Object=null; 如果(t.长度>0) { var objName:String=t[i]; //获取类中的对象 exampleObj=这个[objName]; 对于(变量i:int=1;i
//将字符串转换为属性数组
var t:Array=exampleStr.split(“.”);
var exampleObj:Object=null;
如果(t.长度>0)
{
var objName:String=t[i];
//获取类中的对象
exampleObj=这个[objName];
对于(变量i:int=1;i
//将字符串转换为属性数组
var t:Array=exampleStr.split(“.”);
var exampleObj:Object=null;
如果(t.长度>0)
{
var objName:String=t[i];
//获取类中的对象
exampleObj=这个[objName];
对于(变量i:int=1;i
//将字符串转换为属性数组
var t:Array=exampleStr.split(“.”);
var exampleObj:Object=null;
如果(t.长度>0)
{
var objName:String=t[i];
//获取类中的对象
exampleObj=这个[objName];
对于(变量i:int=1;i
您可以使用以下简单功能:

function getRValue(target:Object, chain:String):*
{
    for each(var i:String in chain.split("."))
    {
        if(target.hasOwnProperty(i)) target = target[i];
        else
        {
            // Couldn't find property.
            throw new Error("Property " + i + " does not exist.");
        }
    }


    return target;
}
通过测试:

var myObject:Object = {
    property1: {
        property2: "Hello world!"
    }
};

trace( getRValue(this, "myObject.property1.property2") ); // Hello world!
trace( getRValue(myObject, "property1.property2") ); // Hello world!

您可以使用以下简单函数:

function getRValue(target:Object, chain:String):*
{
    for each(var i:String in chain.split("."))
    {
        if(target.hasOwnProperty(i)) target = target[i];
        else
        {
            // Couldn't find property.
            throw new Error("Property " + i + " does not exist.");
        }
    }


    return target;
}
通过测试:

var myObject:Object = {
    property1: {
        property2: "Hello world!"
    }
};

trace( getRValue(this, "myObject.property1.property2") ); // Hello world!
trace( getRValue(myObject, "property1.property2") ); // Hello world!

您可以使用以下简单函数:

function getRValue(target:Object, chain:String):*
{
    for each(var i:String in chain.split("."))
    {
        if(target.hasOwnProperty(i)) target = target[i];
        else
        {
            // Couldn't find property.
            throw new Error("Property " + i + " does not exist.");
        }
    }


    return target;
}
通过测试:

var myObject:Object = {
    property1: {
        property2: "Hello world!"
    }
};

trace( getRValue(this, "myObject.property1.property2") ); // Hello world!
trace( getRValue(myObject, "property1.property2") ); // Hello world!

您可以使用以下简单函数:

function getRValue(target:Object, chain:String):*
{
    for each(var i:String in chain.split("."))
    {
        if(target.hasOwnProperty(i)) target = target[i];
        else
        {
            // Couldn't find property.
            throw new Error("Property " + i + " does not exist.");
        }
    }


    return target;
}
通过测试:

var myObject:Object = {
    property1: {
        property2: "Hello world!"
    }
};

trace( getRValue(this, "myObject.property1.property2") ); // Hello world!
trace( getRValue(myObject, "property1.property2") ); // Hello world!


您的意思是在
myObject.property1.property2
周围不包含
引号吗?引号应该在那里。我正在尝试评估动态创建的对象是否缺少任何链接属性。我现在明白了您的意思-您可以使用递归实现这一点。您的意思是在
myObject.property1.property2
周围不包含
引号吗?引号应该在那里。我正在尝试评估动态创建的对象是否缺少任何链接属性。我现在明白了您的意思-您可以使用递归实现这一点。您的意思是在
myObject.property1.property2
周围不包含
引号吗?引号应该在那里。我正在尝试评估动态创建的对象是否缺少任何链接属性。我现在明白了您的意思-您可以使用递归实现这一点。您的意思是在
myObject.property1.property2
周围不包含
引号吗?引号应该在那里。我正在尝试评估动态创建的对象是否缺少任何链接属性。我现在明白了您的意思-您可以使用递归实现。这是一个很好的示例,但对于动态创建的对象,它将为工作类中未找到的属性抛出一个错误1069。好的,只要property1和property2存在,代码就可以了。在他的评论之后,OP的问题更加明确。我没有意识到目标是确认财产的存在。:)很好的例子,但是对于动态创建的对象,它会为工作类中找不到的属性抛出一个错误1069。在他的评论之后,OP的问题更加明确。我没有意识到目标是确认exi