简体   繁体   English

如何将动作脚本变量值分配给flex中的spark组件

[英]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: 有两种方法可以解决此问题:

  1. make the yy variable global, ie define it outside of the method so the label component can access it 使yy变量成为全局变量,即在方法外部定义它,以便标签组件可以访问它

  2. 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.

相关问题 Flex / ActionScript:如何通过值(而不是引用)复制ListCollectionView变量? - Flex/ActionScript: How to copy ListCollectionView variable by value (rather than reference)? Flex / AS3:如何在ActionScript中设置spark Rect的属性? - Flex / AS3: how to set properties of spark Rect in ActionScript? 如何将经过编辑的动作脚本类应用于Flex 4中的MXML组件? - How do I apply an edited actionscript class to an MXML component in Flex 4? 如何将寻址变量传递给flex / actionscript等? - How do I pass an addressed variable into flex/actionscript etc? 如何捕获在actionscript和flex中动态创建的textinput值? - how to capture the textinput value created dynamically in actionscript and flex? flex4如何将值传递给火花图像 - flex4 how to pass value to spark image 从actionscript3访问flex中的图像组件 - accessing an image component in flex from actionscript3 ActionScript:如何通过VALUE而不是REFERENCE分配数组? - ActionScript: How to assign arrays by VALUE rather than REFERENCE? 如何在flex4 / MXML / Spark中从外部文件包含动作脚本功能? - How to include an actionscript function from an external file in flex4/MXML/Spark? Actionscript / Flex:如何在Spark列表排序后维护所选项目(而不是索引) - Actionscript/Flex: How to maintain the selected item (instead of index) after a Spark list sorts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM