Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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();
}
}
}
}
Copy link to clipboard
Copied
When you say the game does not work, in what way is it not working?
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
hm..
Sounds like it could work.. How to do it??
Copy link to clipboard
Copied
Basically you just assign the stage.focus property to the object you loaded.
stage.focus = ( after the file has loaded, assign it here )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now