Skip to main content
June 6, 2013
Question

error when opening swf from another swf

  • June 6, 2013
  • 1 reply
  • 930 views

Hi all,

I'll try to explain this as good as possible.... I made a maze game that works perfectly when I run it by clicking on it's own .swf file, but when I try to access it from another .swf file which is a menu for the games I created, it does not work.

I have absolutely no idea where to look for the error, so my question is: can it be that the main.swf (which is the menu for games) could be the problem, or the problem must be in the maze.swf?

Thanx in advance!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
June 6, 2013

Does the game file load any data files or other content that might be displaced when you are loading thru a different file in a different folder?

June 6, 2013

no, all code is in the first frame of actions layer:

stop();

    var rightArrow:Boolean = false;   

    var leftArrow:Boolean = false;

    var upArrow:Boolean = false;

    var downArrow:Boolean = false;

    var speed:int = 5;

    stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);

    stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);

    stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);

    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 = player.getBounds(this);

        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, player.y, true)) {

                    xBump = i - 1;

                    break;

                }

            }

        }

        if(leftArrow) {

            xBump = -speed;

            for(i = 0; i < speed; i++) {

                if(maze.hitTestPoint(rect.left - i, player.y, true)) {

                    xBump = -i + 1;

                    break;

                }

            }

        }

        if(upArrow) {

            yBump = -speed;

            for(i = 0; i < speed; i++) {

                if(maze.hitTestPoint(player.x, rect.top - i, true)) {

                    yBump = -i + 1;

                    break;

                }

            }

        }

        if(downArrow) {

            yBump = speed;

            for(i = 0; i < speed; i++) {

                if(maze.hitTestPoint(player.x, rect.bottom + i, true)) {

                    yBump = i - 1;

                    break;

                }

            }

        }

        player.x += xBump;

        player.y += yBump;

        if(rightArrow) {

            xBump = speed;

            for(i = 0; i < speed; i++) {

                if(cilj.hitTestPoint(rect.right + i, player.y, true)) {

                    xBump = i - 1;

                    nextScene();

                }

            }

        }

    }

Ned Murphy
Legend
June 6, 2013

When you say the game does not work, in what way is it not working?