Hi all , i am following a tutorial.
The code below should load two images into my scene.
I have an .as file and an .fla file in a folder called src and two images in a folder called images. I am compiling my .as file in Adobe Animate.
When I try to embed my images using:
it does not want to work.
Nothing is loaded and there are no errors compiled.
Here is my code. It is simple. It should load background.jpg and character.png from the images folder.In order to control the character onstage with keyboard controls.
public class BasicScrolling extends Sprite
//Embed the background image
public var BackgroundImage:Class;
public var backgroundImage:DisplayObject = new BackgroundImage();
public var background:Sprite = new Sprite();
//Embed the character image
public var CharacterImage:Class;
public var characterImage:DisplayObject = new CharacterImage();
public var character:Sprite = new Sprite();
//Create and initialize the vx and vy variables
public var vx:int = 0;
public var vy:int = 0;
public function BasicScrolling()
//Add the background
background.x = -1325;
background.y = -961;
//Add the character
character.x = 225;
character.y = 150;
//Add the event listeners
public function keyDownHandler(event:KeyboardEvent):void
if (event.keyCode == Keyboard.LEFT)
vx = -5;
else if (event.keyCode == Keyboard.RIGHT)
vx = 5;
else if (event.keyCode == Keyboard.UP)
vy = -5;
else if (event.keyCode == Keyboard.DOWN)
vy = 5;
public function keyUpHandler(event:KeyboardEvent):void
if (event.keyCode == Keyboard.LEFT
|| event.keyCode == Keyboard.RIGHT)
vx = 0;
else if (event.keyCode == Keyboard.DOWN
|| event.keyCode == Keyboard.UP)
vy = 0;
public function enterFrameHandler(event:Event):void
//Move the background
background.x -= vx;
background.y -= vy;
//Check the stage boundaries
if (background.x > 0)
background.x = 0;
else if (background.y > 0)
background.y = 0;
else if (background.x < stage.stageWidth - background.width)
background.x = stage.stageWidth - background.width;
else if (background.y < stage.stageHeight - background.height)
background.y = stage.stageHeight - background.height;
I pasted all of my code here. I hope that this is ok.
Any help is mot appreciated.
if the images folder is in the same folder as your published animate files, that should be:
Nice one for your help. so I have a folder called BasicScrolling, inside here is a folder called src and an images folder. Inside of src is my .fla and .as files and inside of folder called images are my background.jpg and character.png.
As kglad said, except the dot in the beginning. Try "/images/background.jpg"
the correct format is:
Its now working.
I had a typo in my class name.
Thanks for all the help guys.