0
votes

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. Please help. The mxml code goes here

s:Label width="35" height="25" textDecoration="none" verticalAlign="middle" text="{yy}"

sorry, i was not able to format this mxml code

2
You should provide more details about the context. For instance, is the label defined using MXML? Is the label instance accessible to the setObjVal? - Romi Halasz

2 Answers

0
votes

Another way to achieve this is to access the label by 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;
}
0
votes

So, the problem is that the label does not have access to the yy variable, since it is defined in the setObjVal method. There are two ways to fix this:

  1. make the yy variable global, i.e. define it outside of the method so the label component can access it

  2. add an id to the label (e.g. 'myLabel') and add a line to the setObjMethod which updates the label's text, like so:

    myLabel.text = yy; //in this case, the label should be accessible to the method