从 Dataservice Flex 获取并节省价值
我正在尝试学习 Flex,我使用 PHP 服务器作为数据服务设置了一个简单的 Air 应用程序...
在我的 php 类中,有一个函数 counttotal
返回一个简单的 int
价值。
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:demologicaclass="services.demologicaclass.*"
width="682" height="397" showStatusBar="false" initialize="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected var count:int = 0;
protected function init():void
{
counttotalResult.token = logicaservice.counttotal();
count = counttotalResult.lastResult as int;
}
protected function get_count():void
{
Alert.show(count as String);
}
.....
.....
<s:Label id="countitems" left="10" bottom="39" width="221" height="21"
fontSize="20"
fontWeight="bold" text="{counttotalResult.lastResult as String}"/>
<s:Button right="10" bottom="39" label="Controlla" click="get_count();"/>
在标签中,我得到了正确的值,但我无法保存并将值显示到简单变量中/从简单变量中显示......
I'm trying to learn Flex, I setup a simple Air application with PHP server as dataserice...
In my php class there is a function counttotal
that return a simple int
value.
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:demologicaclass="services.demologicaclass.*"
width="682" height="397" showStatusBar="false" initialize="init()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected var count:int = 0;
protected function init():void
{
counttotalResult.token = logicaservice.counttotal();
count = counttotalResult.lastResult as int;
}
protected function get_count():void
{
Alert.show(count as String);
}
.....
.....
<s:Label id="countitems" left="10" bottom="39" width="221" height="21"
fontSize="20"
fontWeight="bold" text="{counttotalResult.lastResult as String}"/>
<s:Button right="10" bottom="39" label="Controlla" click="get_count();"/>
In the label I got the correct value, but I can't save and show the value into/from a simple variable...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为使用关键字 as 将使 Flex 尝试将一种类型强制转换为另一种类型,从而存在强制转换失败的风险。在这里,您尝试将字符串转换为整数,这基本上意味着您执行以下操作:
您想要做的是将字符串转换为整数(尽管不确定这个词)。为此,请使用以下语法:
上面的意思是
转换可能会失败(但它不会失败,只要 lastResult 是有效数字的字符串表示形式),并且语法可以更短,但简而言之,这就是将类型转换为另一种类型与将类型转换为其他。
That's because using the keyword as will make Flex to try to cast a type to another, with a risk that the cast fails. Here, you try to cast a String as an integer, which basically means you do the following :
What you want to do is transtype (not sure about the word, though) a String to an integer. To do this, use the following syntax :
The above means
The conversion can fail (but it wont, as long as lastResult is the string representation of a valid number), and the syntax could be shorter, but in a nutshell, that's the difference between casting a type to another, and converting a type to another.