Flex使用XML点表示法字符串

时间:2022-10-17 22:33:47

In the following example the first trace gives me the xml data at the node, but the second trace does not. This is AS3. How would I use a variable to do the same as inline dot notation?

在下面的示例中,第一个跟踪为我提供了节点上的xml数据,但第二个跟踪没有。这是AS3。我如何使用变量与内联点表示法相同?

var x:String = "animXML.home.version";
trace(animXML.home.version);  // this works
trace([x]);                   // this does not

Thanks

谢谢

1 个解决方案

#1


1  

Not sure what you are trying to achieve but this will output same thing:

不确定你想要实现什么,但这将输出相同的东西:

var x:String = animXML.home.version as String;
trace(animXML.home.version);  // this works
trace(x);                     // this works

update (full script):

更新(完整脚本):

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Declarations>
        <fx:Model id="animXML">
            <root>
                <home>
                    <version>Version 1</version>
                </home>
            </root>
        </fx:Model>    
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            protected function clickHandler(event:MouseEvent):void
            {
                var x:String = animXML.home.version as String;
                trace(animXML.home.version);  // this works
                trace(x);                     // this works
            }

        ]]>
    </fx:Script>

    <s:Button label="test" click="clickHandler(event)" />

</s:Application>

Click on "test" button gives the following output:

点击“测试”按钮给出以下输出:

Version 1
Version 1

#1


1  

Not sure what you are trying to achieve but this will output same thing:

不确定你想要实现什么,但这将输出相同的东西:

var x:String = animXML.home.version as String;
trace(animXML.home.version);  // this works
trace(x);                     // this works

update (full script):

更新(完整脚本):

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Declarations>
        <fx:Model id="animXML">
            <root>
                <home>
                    <version>Version 1</version>
                </home>
            </root>
        </fx:Model>    
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            protected function clickHandler(event:MouseEvent):void
            {
                var x:String = animXML.home.version as String;
                trace(animXML.home.version);  // this works
                trace(x);                     // this works
            }

        ]]>
    </fx:Script>

    <s:Button label="test" click="clickHandler(event)" />

</s:Application>

Click on "test" button gives the following output:

点击“测试”按钮给出以下输出:

Version 1
Version 1