# Variable Loading From Database

**URL:** <https://forum.kirupa.com/t/variable-loading-from-database/200116>\
**Category:** flash\
**Created:** [September 8, 2006, 7:08pm UTC](https://forum.kirupa.com/t/variable-loading-from-database/200116 "2006-09-08T19:08:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![apdpsu](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@apdpsu](https://forum.kirupa.com/u/apdpsu)\
**Post date:** [September 8, 2006, 7:08pm UTC](https://forum.kirupa.com/t/variable-loading-from-database/200116/1 "2006-09-08T19:08:39Z")

</div>

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!!! ☹**

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].

```auto

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:

```auto

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
