# Passing String Variable to URLRequest

**URL:** <https://forum.kirupa.com/t/passing-string-variable-to-urlrequest/306343>\
**Category:** flash\
**Created:** [March 13, 2010, 1:23pm UTC](https://forum.kirupa.com/t/passing-string-variable-to-urlrequest/306343 "2010-03-13T13:23:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anubhavmax](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@anubhavmax](https://forum.kirupa.com/u/anubhavmax)\
**Post date:** [March 13, 2010, 1:23pm UTC](https://forum.kirupa.com/t/passing-string-variable-to-urlrequest/306343/1 "2010-03-13T13:23:52Z")

</div>

I am struggling with this bit of code

var bgimage:String = new String();

var myTextLoader:URLLoader = new URLLoader();  
myTextLoader.dataFormat=URLLoaderDataFormat.VARIAB LES;

myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

function onLoaded(e:Event):void {  
bgimage = e.target.data.bg;  
trace(bgimage);  
}

myTextLoader.load(new URLRequest(“background.txt”));

var imageLoader:Loader;

function loadImage(url:String):void {

// Set properties on my Loader object  
imageLoader = new Loader();  
imageLoader.load(new URLRequest(url));  
imageLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, imageLoading);  
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imageLoaded);

}  
**loadImage(bgimage);**

function imageLoaded(e:Event):void {

// Load Image  
imageArea.addChild(imageLoader);

}

function imageLoading(e:ProgressEvent):void {

// Use it to get current download progress  
// Hint: You could tie the values to a preloader ![](http://forum.kirupa.com/uploads/kirupa/798/c985a958819d8917.gif)

}

The Code fetches data from a text file and stores it in variable bgimage. On executing this piece of Code, I am getting the following error

“image1.png”  
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

The trace(bgimage) gives the correct value of bgimage but when bgimage is passed as an arguement to loadMovie (finally to URLRequst) , the above error is shown.

However when I replace **loadImage(bgimage);** by **loadImage(“image1.png”);** it works perfectly. Just unable to make out why it isn’t taking a variable as an arguement but a direct value works perfectly.

Waiting for a solution to the problem desperately.

Thanks
