Copy link to clipboard
Copied
Hello,
I have just recently started using the Flash platform and working with ActionScript. I have started a small project and attempting to load a PNG file onto the stage. I have an image directory within the project folder and have the following code which is generating the error.
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);
}
}
}
Unfortunately I was unable to locate a code block to contain this and there is no syntax highlighting for ActionScript within the forum?
Thanks.
Copy link to clipboard
Copied
So I have since realized the backspace '\' is used for escape characters in string literals so I have since doubled them up '\\'.
Typing the full directory resolves the issue but if my project was used on another computer the directory path will be different so I need to know the default path it runs the application from. I thought this would be the bin-debug folder. So moving up the directory to the main project folder then into my images folder should work but it isn't.