# Referring to Variables Outside of Functions

**URL:** <https://forum.kirupa.com/t/referring-to-variables-outside-of-functions/249337>\
**Category:** flash\
**Created:** [January 17, 2008, 5:30pm UTC](https://forum.kirupa.com/t/referring-to-variables-outside-of-functions/249337 "2008-01-17T17:30:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrwizzer](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mrwizzer](https://forum.kirupa.com/u/mrwizzer)\
**Post date:** [January 17, 2008, 5:30pm UTC](https://forum.kirupa.com/t/referring-to-variables-outside-of-functions/249337/1 "2008-01-17T17:30:57Z")

</div>

There’s gotta be a simple answer for this…

How does one refer to a variable that was defined inside a function when you’re outside of that function?

# For example:

# setMyVariable = function() { var myVariable:Number = 22; trace("myVariable is = " + myVariable); }; setMyVariable(); trace("That variable again is " + myVariable);

Returns the following:  
myVariable is = 22  
That variable again is undefined

How can I reference the variable I’ve declared in the function once I’m outside of the function?

Would I have to set up myVariable as a global variable like this: \_global.myVariable =22 and skip the strict datatyping? Or is there a better way?

Thanks
