# Making variables defined in a function available globally

**URL:** <https://forum.kirupa.com/t/making-variables-defined-in-a-function-available-globally/289835>\
**Category:** Uncategorized\
**Created:** [June 5, 2009, 12:57pm UTC](https://forum.kirupa.com/t/making-variables-defined-in-a-function-available-globally/289835 "2009-06-05T12:57:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tedri\_Mark](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@Tedri\_Mark](https://forum.kirupa.com/u/Tedri_Mark)\
**Post date:** [June 5, 2009, 12:57pm UTC](https://forum.kirupa.com/t/making-variables-defined-in-a-function-available-globally/289835/1 "2009-06-05T12:57:27Z")

</div>

As above, really. The following bit of code outputs that ‘myRequest’ and ‘i’ are not defined.

```auto
//Load external asset
        
        
            function loadfail():void
            {
                var myRequest:URLRequest = new URLRequest("images/default.jpg");
            }
            
            function loadsuccess():void
            {
                var myRequest:URLRequest = new URLRequest(thumb*);
            }
            
            private function Load_thumbnail():void
        {
            
            
            
            for (var i:uint = 0; i<numphot; i++)
            {
                
                var testLoader:Loader = new Loader()
                var testRequest:URLRequest = new URLRequest(thumb*);
                testLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadfail);
                testLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadsuccess);
                testLoader.load(testRequest);
                
                
                
                var myLoader:Loader = new Loader();
                myLoader.load(myRequest);
                myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, Thumb_loaded);
                pInfor[myLoader] = i;
            }
                
            }

```

after a bit of reading I find that it is because ‘myRequest’ and ‘i’ are defined within functions, and so those variables are not available outside those functions.  
How can I get around this? Make a class?
