Making variables defined in a function available globally

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

//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);
                var myLoader:Loader = new Loader();
                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?