# Tracking a variable change from C++

**URL:** <https://forum.kirupa.com/t/tracking-a-variable-change-from-c/221460>\
**Category:** flash\
**Created:** [April 4, 2007, 2:47pm UTC](https://forum.kirupa.com/t/tracking-a-variable-change-from-c/221460 "2007-04-04T14:47:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lariat1997](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@lariat1997](https://forum.kirupa.com/u/lariat1997)\
**Post date:** [April 4, 2007, 2:47pm UTC](https://forum.kirupa.com/t/tracking-a-variable-change-from-c/221460/1 "2007-04-04T14:47:50Z")

</div>

Hey all,

I have a listbox that needs to be populated when a variable is sent to my .swf. What happens is…if the variable is already passed a value before my .swf loads, then it works fine, but the variable will be passed after the .swf loads, so that leaves the listbox empty.

I would like for the listbox to populate when it notices the variable has been changed. I used object.watch, but it’s not successful. Here’s my code:  
[AS]  
stop();  
//Importing component classes  
import mx.controls.\*;  
mx.accessibility.ListAccImpl.enableAccessibility();

//Variables for Listbox  
var createVar\_btn:Button;  
var listBox\_lst:mx.controls.List;

//Setting ListBox properties  
listBox\_lst.hScrollPolicy = “off”;  
listBox\_lst.maxHPosition = 200;  
listBox\_lst.iconField = “icon”;  
//listBox\_lst.setStyle(“themeColor”, “haloBlue”);  
\_path.watch(“text”, loadChecks());  
//Setting up XML file  
//var \_pathUN = “Username\_and\_Password”;  
var checksXML:XML = new XML();  
var \_path:String = “”;

function loadChecks(property, oldVal, newVal){

checksXML.ignoreWhite = true;  
checksXML.load(checks.xml);

[//checksXML.load](https://checksXML.load)(“checks.xml”);  
checksXML.onLoad = function(pSuccess)  
{  
if(pSuccess)  
{  
\_root.splash\_mc.username\_txt.text = \_UN;

```
		//Populating ListBox with file in directory via XML
		for(var i:Number = 0; i &lt; checksXML.firstChild.childNodes.length; i++)
		{
			//Setting XML location to variable 'chk', then getting rid of the file extension to display in ListBox
			var chk = checksXML.firstChild.childNodes*.attributes.name;
			chk = chk.substring(0, chk.length-4) + "";
			listBox_lst.addItem(chk);
		};//End of 'for' loop					
	//End of 'rollButton_mc' function		
};//End of 'if(success)' loop

```

};//End of ‘onLoad’ function  
};

useCheck\_btn.onRelease = function()  
{ //Enter code to do something when an item is selected in the ListBox  
var tVar = listBox\_lst.selectedItem.label;   
};  
[/AS]

Any help is greatly appreciated.
