# Avoid nested function in order to access a local variable

**URL:** <https://forum.kirupa.com/t/avoid-nested-function-in-order-to-access-a-local-variable/306581>\
**Category:** flash\
**Created:** [March 17, 2010, 10:01pm UTC](https://forum.kirupa.com/t/avoid-nested-function-in-order-to-access-a-local-variable/306581 "2010-03-17T22:01:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitree](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dimitree/32/2530_2.png) [@Dimitree](https://forum.kirupa.com/u/Dimitree)\
**Post date:** [March 17, 2010, 10:01pm UTC](https://forum.kirupa.com/t/avoid-nested-function-in-order-to-access-a-local-variable/306581/1 "2010-03-17T22:01:07Z")

</div>

I want to load an XML file and access one node value.  
I decided to store it in a variable( **var addedNumber** ).

The problem is I want to access this variable in a new function ( **loadURL** )“outside” of the scope.  
Is there a clearer way to do this instead of using nested function?

```php
var XMLLoader:URLLoader;
var XMLPath:URLRequest;
var XMLDoc:XMLDocument = new XMLDocument();
XMLDoc.ignoreWhite=true;
var XMLData:XML;
var addedNumber:Object;
XMLPath=new URLRequest("test.xml");
XMLLoader=new URLLoader(XMLPath); 
XMLLoader.addEventListener("complete", extractXMLFileData);  
function extractXMLFileData(event:Event):void 
{ var XMLData = XML(event.target.data);  
var addedNumber = XMLData.np.text();
trace("wwww.ssss.com?"+ addedNumber );// traces wwww.ssss.com?2 Correct
loadURL();
}

function loadURL():void{	
	trace("wwww.ssss.com?"+ addedNumber );//traces wwww.ssss.com?null ---Here is the problem
	
	}

```
