Flash AS3 Maze Type Game Issue

I've created a maze game in Flash as3 and it all works great as an individual swf. As soon as I drop it into the main container swf it stops working! Well, it still kind of works, but it loses the 'bounds' of the maze. Does anyone know how I could fix this problem please? Any help greatly apprecaited, S.

package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.*; 
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.geom.Rectangle;
import gs.TweenLite;
import gs.easing.*;

public class slide17 extends MovieClip {        
    private var maze:mazeBG;    
    private var mazeC:mazeCircle;   

    var rightArrow:Boolean = false;
    var leftArrow:Boolean = false;
    var upArrow:Boolean = false;
    var downArrow:Boolean = false;
    var speed:int = 10;

    public function slide17():void {

    private function screen01():void {      

        stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
        stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
        stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

        maze = new mazeBG();

        mazeC = new mazeCircle();

        function stage_onKeyDown(event:KeyboardEvent):void {
            if(event.keyCode == Keyboard.RIGHT) rightArrow = true;
            if(event.keyCode == Keyboard.LEFT) leftArrow = true;
            if(event.keyCode == Keyboard.UP) upArrow = true;
            if(event.keyCode == Keyboard.DOWN) downArrow = true;
        function stage_onKeyUp(event:KeyboardEvent):void {
            if(event.keyCode == Keyboard.RIGHT) rightArrow = false;
            if(event.keyCode == Keyboard.LEFT) leftArrow = false;
            if(event.keyCode == Keyboard.UP) upArrow = false;
            if(event.keyCode == Keyboard.DOWN) downArrow = false;
        function stage_onEnterFrame(event:Event):void {
            var rect:Rectangle = mazeC.getBounds(stage);                
            var i:int = 0;
            var xBump:int = 0;
            var yBump:int = 0;
            if(rightArrow) {
                xBump = speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(rect.right + i, mazeC.y, true)) {
                        xBump = i - 1;
            if(leftArrow) {
                xBump = -speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(rect.left - i, mazeC.y, true)) {
                        xBump = -i + 1;
            if(upArrow) {
                yBump = -speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(mazeC.x, rect.top - i, true)) {
                        yBump = -i + 1;
            if(downArrow) {
                yBump = speed;
                for(i = 0; i < speed; i++) {
                    if(maze.hitTestPoint(mazeC.x, rect.bottom + i, true)) {
                        yBump = i - 1;
            mazeC.x += xBump;
            mazeC.y += yBump;




Your line:

var rect:Rectangle = mazeC.getBounds(stage);

uses the stage object to get the area of your MazeCircle. When you add your game to a wrapper swf (your main container swf), the stage object is now the stage of the wrapper. If the wrapper has different dimensions than your game swf, your call to getBounds() is going to return funky coordinates.

What you need is something consistent to measure with that won't change when the stage object gets changed. There are a few ways you could fix this:

  1. Use a Sprite or MovieClip to wrap your game, and use that with getBounds() instead of the stage. You could use the instance of slide_17 that your working in by using the this keyword. Ex:

    var rect:Rectangle = mazeC.getBounds(this);

  2. Use a function other than getBounds() to determine the area of your MazeCircle, for example, using the properties x, y, width, and height instead. Let me know if you would like an example of this, but I'm betting you can figure it out - it would be lengthy to include it here.

Hopefully that helps!

Need Your Help

Modeling a cookie with object composition in Ruby

ruby oop inheritance

I'm a new Rubyist and am wondering how I can access the ingredients class from individual cookies? As we all know, cookies are made of different ingredients. How can I specify default ingredients for

Why is a string Array causing a LNK2001 error?

c++ arrays string std lnk2001

I am mainly a C# programmer but I need this project done in C++ so I may be missing something for C++ arrays.