PDA

View Full Version : Error loading local image



psych
August 23rd, 2008, 06:18 AM
I am try to load a local image, but are constantly getting :


Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.although i am 100% sure the path is correct, infact there is no path, image is in current directory. I am using the following code:


var pictLdr:Loader = new Loader();
var pictURL:String = "background.jpg";
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
this.addChild(pictLdr);Does anyone know what could be the problem?

thanks

senocular
August 23rd, 2008, 07:21 AM
try using another image file with a different name; do you get the same error?

psych
August 23rd, 2008, 07:49 AM
iI simplified the problem thinking there is something simple overlooked but i guess it's not the case. If i paste this code in Flash CS3 ide and run then the image is loaded just fine, but if i use this same code in FDT then i get the error above so i am not sure what's going on? Is there some restriction when using FDT, maybe it has something to do with the fact that i am infact using flex sdk or smth?

thanks sen

senocular
August 23rd, 2008, 08:03 AM
I'm not familiar with FDT so I don't know how it sets up your environment, but I'm sure it comes down to the URL being wrong. You just need to figure out where the image really needs to go to be recognized there.

psych
August 23rd, 2008, 09:13 AM
I'll post my directory structure, maybe you'll see something i am obviously missing:


src\
com\
simplistiq\
FullScreenBgImage.as
background.jpg
Main.asFullScreenBgImage.as and Main.as are classes. Basically what i am trying to do is from Main.as instantiate FullScreenBgImage class and pass to it image path parameter which is in this example path to background.jpg image and FullScreenBgImage class then loads and display that image. Here is the source of those two classes:

Main.as

package {
import flash.display.Sprite;

import com.simplistiq.FullScreenBgImage;

public class Main extends Sprite {
public function Main() {
var bgImage : FullScreenBgImage = new FullScreenBgImage("background.jpg");
addChild(bgImage);
}
}
}
FullScreenBgImage.as

package com.simplistiq{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;

public class FullScreenBgImage extends Sprite {

private var _imgLoader : Loader;

public function FullScreenBgImage(imgPath:String) {

_imgLoader = new Loader();
var imgUrl : URLRequest = new URLRequest(imgPath);
_imgLoader.load(imgUrl);
_imgLoader.contentLoaderInfo.addEventListener(Even t.COMPLETE, onLoadComplete);

}

public function onLoadComplete(event:Event):void{
trace("[loading complete]");

var imgMC:MovieClip = new MovieClip();
imgMC.addChild(_imgLoader);
addChild(imgMC);
}

}
}

senocular
August 23rd, 2008, 09:14 AM
See your ASorg post (you posted that one first so I saw it first)

psych
August 23rd, 2008, 09:21 AM
Thank you very much sen

best regards