Problem embedding images in class

This is my first post here. Hi to all members. :smile:

I am having a problem loading images from folder src, I am getting multiple 1120 error access of undefined property.
I have a src folder with .fla and .as files inside and a images folder with background.png and character.png images.

I was using a URLRequest and loader and displaying the images from the folder instead of embedding them. I have commented out the code there.

my code is here:

package {

import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;

	
public class Dungeon extends Sprite {
	

	//create game character objects
	/*public var characterURL:URLRequest = new URLRequest("../images/character.png");
	public var characterImage:Loader = new Loader();
	public var character:Sprite = new Sprite();*/
		
//embed the background image
	[embed(source="../images/background.png")]
	public var BackgroundImage:Class;
	public var backgroundImage:DisplayObject = new BackgroundImage();
	public var background:Sprite = new Sprite();
	
	//embed the character image
	[embed(source="../images/character.png")]
	public var CharacterImage:Class;
	public var characterImage:DisplayObject = new CharacterImage();
	public var character:Sprite = new Sprite();
	
	
	//Create and Initialise the vx and vy variables
	public var vx: int = 0;
	public var vy: int = 0;
	
//Add the background
		background.addChild(backgroundImage);
		stage.addChild(background);
		background.x = -1005;
		background.y = -762;
		
		//Add the character
		character.addChild(characterImage);
		stage.addChild(character);
		background.x = 225;
		background.y = 250;


	public function Dungeon() {
		//Load the image into sprite and place it on the stage

		/*characterImage.load(characterURL);
		character.addChild(characterImage);
		stage.addChild(character);
		character.x = 225;
		character.y = 150;*/
		
	
		
		

		// Event Listeners
		stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
		stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
		stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}

	
	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 {
		//feed the vy vx velocity to hero object position 
		character.x += vx;
		character.y += vy;

		//Stop hero from moving over the stage boundaries 50 pixels inside stage
		
		//Top Boundaries
		if (character.x < 50) 
			{
			character.x = 50;
			}
		if (character.y < 50) 
			{
			character.y = 50;
			}
		if (character.x + character.width > stage.stageWidth) 
			{
			character.x = stage.stageWidth - character.width;
			}
		if (character.y + character.height > stage.stageHeight) 
			{
			character.y - stage.stageHeight - character.height;
			}

		//Bottom Boundaries(slightly different code adds heros width
						
		if (character.x + character.width  > stage.stageWidth - 50)

			{
			character.x = stage.stageWidth - character.width - 50;
			}
		if (character.y  + character.height > stage.stageHeight - 50) {
			character.y = stage.stageHeight - character.height- 50;
			trace("here");
			}

		}

}

}
any help would be much appreciated.

A post was merged into an existing topic: Problem embedding images