# Loop creates global variables

**URL:** <https://forum.kirupa.com/t/loop-creates-global-variables/228080>\
**Category:** flash\
**Created:** [June 5, 2007, 8:00am UTC](https://forum.kirupa.com/t/loop-creates-global-variables/228080 "2007-06-05T08:00:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bzouchir](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bzouchir/32/2088_2.png) [@bzouchir](https://forum.kirupa.com/u/bzouchir)\
**Post date:** [June 5, 2007, 8:00am UTC](https://forum.kirupa.com/t/loop-creates-global-variables/228080/1 "2007-06-05T08:00:19Z")

</div>

hi all,

I can seem to figure this out, most examples I’ve seen were in AS2

here’s my code sample if u can pls help

```auto
var myVar:String;
function createVariables():void{
	for (var i:int= 0; i <5; i++){
		myVar = this["myVar"+i];
	}
}

function doSomething (action:String){
	trace (action);
}

doSomething(myVar1);
//Compile Error
//1120: Access of undefined property myVar1.

```

how can i pass this variable to be used elsewhere outside its scope :s

what I initially have is this:

```auto

var head1:String = myXML.window.(@id==1).headline;
var head2:String = myXML.window.(@id==2).headline;
var head3:String = myXML.window.(@id==3).headline;
var head4:String = myXML.window.(@id==4).headline;
var head5:String = myXML.window.(@id==5).headline;

trace(head1);
trace(head2);
///etc... I just want to collapse all those lines and learn proper scripting

```

thx for ur help
