Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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
从XML获取公式,AS3_Xml_Flash_Actionscript 3 - Fatal编程技术网

从XML获取公式,AS3

从XML获取公式,AS3,xml,flash,actionscript-3,Xml,Flash,Actionscript 3,在我的swf中有一个变量,我想接收XML。它是一个方程式形式的整数值。如何接收“formatcount”的XML值 我的变量 //Variable I want to grab XML<br> //formatcount=int('want xml value to go here'); formatcount=int(count*count/100); 我的XML <?xml version="1.0" encoding="utf-8"?> <SESSI

在我的swf中有一个变量,我想接收XML。它是一个方程式形式的整数值。如何接收“formatcount”的XML值

我的变量

//Variable I want to grab XML<br>
//formatcount=int('want xml value to go here');

formatcount=int(count*count/100);
我的XML

<?xml version="1.0" encoding="utf-8"?>
   <SESSION>
      <TIMER TITLE="speed">1000</TIMER>
      <COUNT TITLE="starting position">10000</COUNT>
      <FORMATCOUNT TITLE="ramp">count*count/1000</FORMATCOUNT>
</SESSION>

1000
10000
计数*计数/1000

您需要编写或使用能够解析和计算表达式的:

检查表达式的计算器示例:

基于上述库(未测试):

import.sephiroth.expr.CompiledExpression;
导入it.sephiroth.expr.Parser;
导入it.sephiroth.expr.Scanner;
导入flash.display.Sprite;
公共类示例扩展了Sprite
{
公共函数示例(){
超级();
var myXML:XML=
1000
10000
计数*计数/1000
;
变量表达式:String=myXML.FORMATCOUNT.toString();
变量扫描器:扫描器=新扫描器(表达式);
var解析器:解析器=新解析器(扫描器);
编译的var:CompiledExpression=parser.parse();
var count:Number=Number(myXML.count.toString());
变量上下文:对象={
计数:计数
};
var formatcount:Number=compiled.execute(上下文);
}
}

您似乎在尝试在XML文件中进行计算,虽然您可以尝试从XML中读入一个等式,但我不明白为什么需要在XML文件本身的级别上进行这两种操作。只要从XML文件中读入值,并在AS中进行任何计算,就会容易得多

如果已将
的值读入代码中的变量(我假定是通过
myXML.COUNT
),则只需执行以下操作:

formatcount = count*count / 10000;
其中count为:

var count:Number = myXML.COUNT;

和你们的问题一样,我不确定我是在回答你们的问题,还是误解了你们的问题。祝你好运。

谢谢,这让我冷静了下来。表达式计算器很难使用。我看不到太多文档。@VideoDnd不,我看不出有什么困难,但这是我的观点;)
formatcount = count*count / 10000;
var count:Number = myXML.COUNT;