Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

error when opening swf from another swf

Guest
Jun 06, 2013 Jun 06, 2013

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!

TOPICS
ActionScript
871
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 06, 2013 Jun 06, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 06, 2013 Jun 06, 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();

                }

            }

        }

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 06, 2013 Jun 06, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 06, 2013 Jun 06, 2013

the character in the game, a small red dot named Dude, is not moving through the maze when i hit keyboard keys assigned for movement. And if I start the game directly by clicking on it's file "maze.swf" everything works allright...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 06, 2013 Jun 06, 2013

My guess is the focus is no longer on the loaded movie, so your keyboard listeners are not catching anything.  After the game file has loaded try setting the stage.focus on it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 06, 2013 Jun 06, 2013

hm..

Sounds like it could work.. How to do it??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2013 Jun 10, 2013
LATEST

Basically you just assign the stage.focus property to the object you loaded.

stage.focus = ( after the file has loaded, assign it here )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines