# Calling variables outside of functions

**URL:** <https://forum.kirupa.com/t/calling-variables-outside-of-functions/256185>\
**Category:** flash\
**Created:** [March 31, 2008, 5:51pm UTC](https://forum.kirupa.com/t/calling-variables-outside-of-functions/256185 "2008-03-31T17:51:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clockwork\_killa](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@clockwork\_killa](https://forum.kirupa.com/u/clockwork_killa)\
**Post date:** [March 31, 2008, 5:51pm UTC](https://forum.kirupa.com/t/calling-variables-outside-of-functions/256185/1 "2008-03-31T17:51:16Z")

</div>

Can anyone explain how I can call a variable outside of a function?  
What I mean is, if I define a variable inside a function and then try and trace that variable anywhere outside the function all I get is undefined.  
For example if I were to try this:

```auto

onLoad=function(){
myVariable="variable";
}
trace(myVariable);

```

The output box would say undefined.

Is there a way round this? I have tried \_root and \_global but that doesnt work either.  
My problem is I am trying to load a variable from an XML file using the variable as the name of a video that needs to be attached to a netstream class. I can load the variable inside a function without any problems, but netstream will not work inside a function and I cannot pass the variable outside of the fucntion.  
Any ideas?  
Thanks
