PDA

View Full Version : Bindable variables not updating...


jrashag
07-29-2008, 11:08 PM
So I had an issue, resolved it and figured out the real issue.

I have data incoming from a socket, it gets parsed into the appropriate variables, which are bindable, and they output the correct information when I alert them after the function is over, however they do not update on my UI.

example:

[Bindable]
var a:String;
[Bindable]
var b:String;

function data(x:XML):void
{
parse data blah blah blah

a = parsedData1;
b = parsedData2;


textarea1.validateNow() //null object error
Alert.show(a) //correct output
Alert.show(b) //correct output
}

<mx:TextArea text="{a}" />
<mx:TextArea text="{b}" />

Aren't my text area's supposed to update their text when the value of a and b change?

edit: Also like to note that I tried using assignments instead of bindable variables and it told me that the access of the textarea's property .text was a null object or reference (Error #1009 I think). I had originally been updating the information right as I parsed it to the text fields but when I ran it, I kept getting the error which is why I went to bindable variables.

edit2: I tried adding a validateNow() to my two text area's which resulted in the 1009 error null object or reference.

exactpixel
07-29-2008, 11:29 PM
well, I just tested your code and a and b update jsut fine for me. As for the validateNow, it looks like a typo since you do not have any ids in your mxml.

jrashag
07-29-2008, 11:44 PM
well, I just tested your code and a and b update jsut fine for me. As for the validateNow, it looks like a typo since you do not have any ids in your mxml.

well i do, just didn't write them in, sorry about that. The text area's actually have id's :)

I agree normally this would work, except that for some reason the variables are not retaining their assignments after they leave the function.

So giving a more proper example....

<mx:Application blah blah creationComplete="init();" >
<mx:Script>
<![CDATA[
[Bindable]
private var a:String;
[Bindable]
private var b:String;


private function init():void
{
//connects to socket and socket sends data back calling the next function
}

private function receivedata(x:XML):void
{
//parses data here assigns to appropriate variables

a = parsedData1;
b = parsedData2;

disp1.text = a; //throws object is null error
Alert.show(a); //shows correct information
Alert.show(b); //shows correct information

}
]]>
</mx:Script>

<mx:TextArea id="disp1" text="{a}" />
<mx:TextArea id="disp2" text="{b}"/>
<mx:Button click="Alert.show(a); Alert.show(b)" /> //these return empty string no matter how long I wait before I press it

</mx:Application>

jrashag
07-29-2008, 11:51 PM
ok I just changed the variables to be public static instead of private and it works....

/sigh