Change Label text with ActionScript

I got very basic question. Why this is not working?!

<?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="1000" height="550" minWidth="960" backgroundColor="#F2F0F0">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="test1" x="43" y="259" text="Label"/>

    <fx:Script>
        <![CDATA[
            test1.text = "Yay! This works...!";
        ]]>
    </fx:Script>
</s:Application>

I got this error: Access of undefined property.

Thanks!

Answers


You're setting the text before the component is created. Try putting the assignment into a method and calling the method on creationComplete:

<?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="1000" height="550" minWidth="960" backgroundColor="#F2F0F0" 
           creationComplete="onCreationComplete()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="test1" x="43" y="259" text="Label"/>

<fx:Script>
    <![CDATA[
        public function onCreationComplete():void {
            test1.text = "Yay! This works...!";
        }
    ]]>
</fx:Script>
</s:Application>

Need Your Help

uninstall sql express which is not show in add/remove program list

c# .net visual-studio-2008 sql-server-express

my question is simple , i want to uninstall sql express 2005 which is removed half and now not showing in add remove program list, it is not allowing me to install new one as well i am not able to ...

What are the pros and cons of object databases?

database oop rdbms relational oodbms

There is a lot of information out there on object-relational mappers and how to best avoid impedance mismatch, all of which seem to be moot points if one were to use an object database. My questio...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.