[英]how to assign actionscript variable value to spark component in flex
I have a variable in actionscript. 我在动作脚本中有一个变量。 How can I set the label text with the variable value? 如何设置带有可变值的标签文本? I have the following code: 我有以下代码:
public function setObjVal(obj1:InvPrintRRTObj):void
{
obj = obj1;
var date:String = obj.receive_Date;
var yy:String = date.substring(0,3);
var mm:String = date.substring(5,6);
var dd:String = date.substring(8,9);
}
I want to assign the yy value to a spark label. 我想将yy值分配给火花标签。 Please help. 请帮忙。 The mxml code goes here MXML代码在这里
s:Label width="35" height="25" textDecoration="none" verticalAlign="middle" text="{yy}" s:Label width =“ 35” height =“ 25” textDecoration =“ none” verticalAlign =“ middle” text =“ {yy}”
sorry, i was not able to format this mxml code 抱歉,我无法格式化此MXML代码
So, the problem is that the label does not have access to the yy variable, since it is defined in the setObjVal method. 因此,问题在于标签没有访问yy变量的权限,因为它是在setObjVal方法中定义的。 There are two ways to fix this: 有两种方法可以解决此问题:
make the yy variable global, ie define it outside of the method so the label component can access it 使yy变量成为全局变量,即在方法外部定义它,以便标签组件可以访问它
add an id to the label (eg 'myLabel') and add a line to the setObjMethod which updates the label's text, like so: 在标签上添加一个id(例如“ myLabel”),在setObjMethod上添加一行以更新标签的文本,如下所示:
myLabel.text = yy; myLabel.text = yy; //in this case, the label should be accessible to the method //在这种情况下,该方法应该可以访问标签
Another way to achieve this is to access the label by id. 实现此目的的另一种方法是通过id访问标签。
<s:Label
id="myLabel"
width="35"
height="25"
textDecoration="none"
verticalAlign="middle" />
Then in your function 然后在你的职能
public function setObjVal(obj1:InvPrintRRTObj):void
{
...
myLabel.text = yy;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.