AS3:AS3中获取变量编写XML code时直接 [英] AS3: access variable when writing XML code directly in AS3

查看:162
本文介绍了AS3:AS3中获取变量编写XML code时直接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

写在AS3 XML code时,我怎么能访问一个变量的值?是这样的:

how can I access the value of a variable when writing XML code in AS3? something like this:

var myVar:Number = 3;

var xml:XML =
    <myXML>
        <valueOfMyVar>???</valueOfMyVar>
    </myXML>

我有什么来替代???用?

what do I have to replace ??? with?

推荐答案

的ActionScript 3.0现在把XML作为这意味着本地数据类型及其不再被解析为一个字符串。但这带给人们在插入变量值的老方法(如+ myvalue的+)不再适用。

ActionScript 3.0 now treats XML as a native data type meaning its no longer parsed as a String. That does bring with it that the old methods of inserting variable values (e.g. ""+myValue+"") no longer apply.

只要看看在code以下片段:

Just take a look at the following snippet of code:

var myVar:Number = 3;

var xml:XML =
<myXML>
    <valueOfMyVar>{myVar}</valueOfMyVar>
</myXML>

这是正确的,从MXML花括号标记。一个区别,虽然,这是的没有的积极的参考变量。如果你改变了变量的值,这将不更新你的XML(没有,甚至没有在Flex的 - 这是纯粹的AS3 code,但当然也可以在MXML定义XML结构,并利用其数据绑定功能)

That’s right, the curly braces notation from MXML. One difference though, this is not an active reference to the variable. If you change the value of the variable this will not update your XML (no, not even in Flex — this is pure AS3 code but you can of course define the XML structure in MXML and take advantage of its data binding features).

另外值得一提的是,你不把引号的花括号,当你使用它的XML属性,如果你这样做,它就会把它当作一个字符串,而不是eval'ing它。 XML对象负责从它生成有效的XML。

Also worth noting is that you don’t put quotes around the curly braces when you use it for an XML attribute, if you do that it’ll treat it as a String rather than eval’ing it. The XML object takes care of generating valid XML from it.

这篇关于AS3:AS3中获取变量编写XML code时直接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆