0

I am receiving an error to suggest that my URL is not found. I am running the below simple script from Flash Builder. As I understand the application launches from bin-debug directory within the main project folder.

I have a image folder also within the main project folder yet it will not find the image. It works when I type the full directory.

The code I have is:

package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;

    [SWF(width="550", height="400", backgroundColor="#FFFFFF", frameRate="60")]

    public class Kitties extends Sprite
    {
        //Declare the variables for the background.
        public var backgroundURL: URLRequest;
        public var backgroundLoader: Loader;
        public var background: Sprite;

        public function Kitties()
        {
            backgroundURL = new URLRequest();
            backgroundLoader = new Loader();
            background = new Sprite();

            backgroundURL.url = "..\\images\\background.png";
            backgroundLoader.load(backgroundURL);
            background.addChild(backgroundLoader);
            stage.addChild(background);
        }
    }
}

I understand I need to add an event listener to capture this error but for now it's not necessary as i know the file exists. Has anyone experienced this before?

Thank you.

VC.One
  • 14,790
  • 4
  • 25
  • 57
  • check out this thread, http://stackoverflow.com/questions/12104291/how-to-upload-a-background-image-using-actionscript-3-0-code – ECM May 20 '16 at 18:04
  • This is not really related to the issue I am having. The issue linked is a permission issue which I do not have. As I have mentioned I can use the full directory and it locates my background, it's just using a relative directory it does not recognize it as a valid path. – Kirk Friend May 21 '16 at 11:37
  • Does `backgroundURL.url = "images\background.png";` work for you...? – VC.One May 23 '16 at 03:32
  • This does not work. `images\background.png";` A backslash in a literal string is an escape character so doubling them up is required. Also the application is ran from the bin-debug folder inside the main application folder. Therefore it is required to move up a directory level to the main application folder before accessing the image folder. I am certain the path in my code above is correct I just don't understand why it doesn't recognize it as a valid path. – Kirk Friend May 23 '16 at 14:55
  • Or even try `backgroundURL.url = "images/background.png";` I was half asleep. A quick experiment with slash variations while you wait is not illegal. Check out @Pelax answer below it might work for you. – VC.One May 24 '16 at 06:15

1 Answers1

2

You shouldn't use backslashes in actionscript3. Normal slashes work on every OS, even on Windows.

Try this:

backgroundURL.url = "../images/background.png";

If the file exists, it should load correctly.

Pelax
  • 66
  • 3