views:

71

answers:

2

Hi. I have a flex project with a mx:Text. i have a class that is loaded at the beginning of my project and i want this class to enter text in that text element. the id of the text element is "messagePanel" but when i try to type messagePanel.text i get 'Access of undefined property'. how do i resolve the issue?

example

general.FMS3Connect class connects to an adobe flash media server, when it completes connecting i want it to display the even info code of the connection inside a mx:Box, it's id is messageBox.

on my main mxml file i have the following:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[0xFFFFFF,0xAAAAAA]"
xmlns:local="*">
<mx:Script>
<![CDATA[
    import general.FMS3Connect;     
    private var conn:FMS3Connect= new FMS3Connect();
]]>
</mx:Script>

<mx:Text id="messageBox" color="black" text="trying to connect to server..." creationComplete="conn.connect()"  >
</mx:Application>

the function connect() for now just has "messageBox.text='test'";

when i execute the application i get the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference.

how do i resolve the issue?

thanks!

+1  A: 

wait for creationcomplete event

Eran
this works when i had action script code on the mxml file. but i want to include an action script class, and with it want to manipulate flex elements. when i try to do so i get `access of undefined property`
ufk
Let say you have a init() function in your as class where you do messagePanel.text = someString , you need to call it in creation complete , so your mxml will have<TextArea id="text1" creationComplete="init()" />
Eran
i edited the main question with a code sample and error message. still does not work.
ufk
+1  A: 

Problem is, your FMS3Connect class has to reference to the Text element.

Easiest (but nasty) solution is to pass in a reference to the Text Element to your connect method, you can then reference the element from that.

something like...

<mx:Text id="messageBox" color="black" text="trying to connect to server..." creationComplete="conn.connect( messageBox )"  >

public function connect( messageDisplay : Text ) : void {
    // do usual connect stuff.
    messageDisplay.text = "test";
}

This isn't the nicest solution in the world, connect shouldn't know about the message box really. But it solved your problem!

Gregor Kiddie
awesome. thank you
ufk