0

This should be super simple but I can't for the life of me seem to get it to just set the text of a label at run time. It throws "1120: Access of undefined property lbl_param"

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               width="398" height="85" minWidth="398" minHeight="85">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>

    <fx:Script>
        <![CDATA[
            lbl_param.text = "test113";
        ]]>
    </fx:Script>
</s:Application>
The Digital Ninja
  • 1,090
  • 6
  • 22
  • 36

1 Answers1

4

Your code to set the lbl_param.text should be in a method: The only code in a script block you can run outside of a method is a class import or a variable definition. This sample puts the code in a initialize event hander:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               width="398" height="85" minWidth="398" minHeight="85" initialize="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>

    <fx:Script>
        <![CDATA[
           public function init():void{
            lbl_param.text = "test113";
           }
        ]]>
    </fx:Script></s:Application>

Disclaimer: I wrote this code in the browser and it may not be "compiler" perfect.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Thanks so much, all my code seems to work perfect so long as I wrap them in functions. Your a life saver. I got really good with node.js and javascript and figured I could just pick up this language and run with it, nope, chuck testa. – The Digital Ninja Jun 07 '12 at 04:24