Alright.

This is my first foray into Object-Oriented design with Flash and also one of the biggest games I've worked on, personally. Essentially, I am in the process of creating an adventure game along the likes of King's Quest, Sam and Max, Hugo's Whodunnit, etc, where the character wanders around and attempts to solve puzzles to complete the game.

I have each room in the game loaded at runtime as a bitmap so that I may perform per-pixel calculations to detect collisions. Currently it is written so that any pure black lines are not able to be walked through, though any other color is fair game. This allows me to draw out the levels in Photoshop and merely import them into Flash, thus saving me numerous hours in the programming department.

My "problem" is this: Organization and placement of code. At the moment, I have four files -
1. the .fla
2. Game.as, where I declared the Game class
3. Level. as, where I declare the Level class
4. Item.as, where I declare the Item class

Most code resides in the Game class file, so that all I need to do in the .fla is create a new Game object and call the run() method. I am confused on what I should do for loading each level and all the items associated with it as the character moves from room to room. An array filled with the names of the levels would make sense, but where do I create each individual instance of the level object for each room? And on top of that, where do I assign the list of item objects AND their specific properties (x,y, description, etc) to each respective level?

Example:

I have an instance of a level named "hotel" which would have a few items like "key", "blanket", "window", and maybe "ear plugs". When I load the hotel level, I would want it to load the specific bitmap for the hotel, and then the items listed above, making sure to place them in the proper position, each with their unique properties. If the character were to walk out the door or off screen, a new level (room) would be loaded, along with whatever items may be in that level (room).

Does any of that make sense?

I'll post my three class files if that might help as well. Keep in mind that most of my code is in the Game class and the other two haven't had much added to them at this point. I guess I'm a "start big, work small" kind of guy?



Code:
import flash.display.BitmapData
import mx.utils.Delegate

class Game
{
	
	public var walkSpeed:Number;
	public var walking:Boolean;
	private var xdir:Number;	  // holds the horizontal direction (-1 or 1)
	private var ydir:Number;	 // holds the vertical direction (-1 or 1)
	// variables to hold level information
	private var levelBmp:BitmapData;
	private var level_mc:MovieClip;
	// keyListener object to let us interface with the keyboard
	private var keyListener:Object = new Object();  
	
	// constructor
	public function Game(walkSpeed:Number, walking:Boolean)
	{
		this.walkSpeed = walkSpeed;
		this.walking = walking;
		this.xdir = 0;
		this.ydir = 0;
		listenForKeys();
		loadLevel();
		loadHero();
			
	}
	
	private function initLevels():Void
	{
		// code to initialize new Level objects and the items that are attached to them
	}
	private function loadLevel():Void
	{
		levelBmp = BitmapData.loadBitmap("playground");

		level_mc = _root.createEmptyMovieClip("level_mc", 1);

		level_mc.attachBitmap(levelBmp, level_mc.getNextHighestDepth());
	}	
	
	private function loadHero():Void
	{
		_root.attachMovie("dave", "dave", _root.getNextHighestDepth(), {_x: 250, _y:400});
	}
	
	// listen for key presses
	private function listenForKeys():Void
	{

		// tells us what to do when a key is pressed
		keyListener.onKeyDown = Delegate.create(this, keyDownFunction);
		
		function keyDownFunction():Void
		{ 
			
			if(Key.getCode() == Key.LEFT)
			{
				
				if(xdir == -1)
				{
					xdir = 0;
					walking = false;
				}
				else
				{
					_root.dave._xscale = -100;
					ydir = 0;
					xdir = -1;
					walking = true;
				}
			}

			if(Key.getCode() == Key.RIGHT)
			{
				if(xdir == 1)
				{
					xdir = 0;
					walking = false;
				}
				else
				{
					_root.dave._xscale = 100;
					ydir = 0;
					xdir = 1;
					walking = true;
				}
			}

			if(Key.getCode() == Key.UP)
			{
				if(ydir == -1)
				{
					ydir = 0;
					walking = false;
				}

				else
				{
					xdir = 0;
					ydir = -1;
					walking = true;
				}	
			}

			if(Key.getCode() == Key.DOWN)
			{

				if(ydir == 1)
				{
					ydir = 0;
					walking = false;
				}
				else
				{
					xdir = 0;
					ydir = 1;
					walking = true;
				}
			}
		}	
		Key.addListener(keyListener);
	}
	
	// checks for collisions between dave and black pixels inside the level clip
	private function checkForWalls():Void
	{
		
		for(var i:Number = 1; i<=walkSpeed; i++)
		{
			if(levelBmp.getPixel(_root.dave._x, _root.dave._y+(i*ydir)) == 0x000000)
			{
				_root.dave._y+= (i-1)*ydir;
				ydir = 0;
				walking = false;
				break;
			}
		}

		for(var i:Number = 1; i<=walkSpeed; i++)
		{
			if(levelBmp.getPixel(_root.dave._x+(i*xdir), _root.dave._y) == 0x000000)
			{
				_root.dave._x+= (i-1)*xdir;
				xdir = 0;
				walking = false;
				break;
			}
		}
		
	}
	
	
	public function run():Void
	{
		checkForWalls();
	
		_root.dave._x += walkSpeed*xdir;
		_root.dave._y += walkSpeed*ydir;
		
		if(walking==true)
		{
			_root.dave.gotoAndStop(2);
		}
		else
		{
			_root.dave.gotoAndStop(1);
		}
	}
}

Code:
class Level
{
	// variables that hold the name of the rooms to the left and right of it
	public var levelLeft:String;
	public var levelRight:String;
	// this level's name
	public var levelName:String;
	
	public function Level()
	{
		// constructor
	}
	
	
	
	public function loadItems()
	{
		_root.attachMovie("blob", "blob", 501, {_x: 270, _y:350});
	}
	
	
}
Code:
class Item extends MovieClip
{	
	// setup a variable to hold who the hero is currently
	//static private var hero:MovieClip;
	
	public function Item()
	{
		//Constructor
	}
	
	// check the distance between the object and a movieclip
	private function checkForClipDistance():Void
	{
		var X:Number;
		var Y:Number;
		var distance:Number;
		
		X = _root.dave._x - this._x;
		Y = _root.dave._y - this._y;
		distance = Math.sqrt(Y*Y+X*X);
		
		if(distance<this._width/2)
		{
			trace("ITEM CLOSE");
		}
	}

}