Variable Loading From Database

Ok, this is a bit rudamentary… lol I know what the issue is, but just need a little info on how to fix it, and so far nobody has been able to help me out!!! :frowning:

I have a swf, it has 1 frame. In that frame i have one layer. In this layer it has 1 button (called [COLOR=#009900]simple_btn[/COLOR]) and a dynamic text box (it’s instance name is [COLOR=#009900]myData[/COLOR]).

When I click the button, I query a database with a PHP script and return that data using sendAndLoad(); I want the returned value to be put into the dynamic field [COLOR=#009900]myData[/COLOR].


lo = new Object();
lo.click = function( event:Object ){
 var scriptPath = "[http://mysite.com/getrecord.php?i=2](http://mysite.com/getrecord.php?i=2)";
 
 // Get record
 var ipAddr;
 // get data
 trace( "Querying database for record now." );
 var recSender:LoadVars = new LoadVars( ); 
 var recReceiver:LoadVars = new LoadVars( ); 
 
 recReceiver.onLoad = function( ok )
 { 
  ipAddr  = recReceiver[ "ipaddress" ];
  trace( ">> ipAddr: " + ipAddr );
 
  this.myData = ipAddr;
 }
 recSender.sendAndLoad( scriptPath, recReceiver, "GET" );
 trace( "Data 1: " + ipAddr  );
}
simple_btn.addEventListener("click", lo);
trace( "Data 2: " + ipAddr  );

Here is the output of my code above:


Data 2: undefined
Querying database for record now.
Data 1: undefined
>> ipAddr: 10.1.1.2

Now I take it, before I print out “Data 2:”, my data has not been loaded from the database. Using timelines, or another method, how can I make sure Data 2 does NOT print out [COLOR=#ff0000]undefined[/COLOR] and the dynamic text field [COLOR=#009900]myData [/COLOR]has the value of ipAddr populated into it?

I dont think this should be too difficult???

Thanks!

Anthony