Captivate – embedded SWF HitTest Not Working
crossfireue Dec 8, 2011 12:16 PMHi there,
I'm new to Captivate, and I'm having an intriguing and frustrating problem. I've created a Captivate presentation, and on one slide I am embedding a game SWF in which the user needs to navigate through a maze. There is a hittest function in the game to check if the player is against a maze wall, causing the player to stop. This works properly if I test the SWF in Flash, or if I publish the SWF and run it through Flash Player.
However, as soon as I embed the SWF into Captivate 5.5 and test the presentation, the HitTest function no longer works properly. The player movieclip is hitting something (I can tell by it's behavior), but it's not hitting the maze movieclip, or at least, not as it is seen on-screen. The SWF loads and runs properly, and other functions (such as scoring and timing) work properly... just not the HitTest for the maze.
Any suggestions?
Here is the portion of code that controls the player in regards to hitting the maze;
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;
player.rotation = 90;
}
if (event.keyCode == Keyboard.LEFT)
{
leftArrow = true;
player.rotation = -90;
}
if (event.keyCode == Keyboard.UP)
{
upArrow = true;
player.rotation = 0;
}
if (event.keyCode == Keyboard.DOWN)
{
downArrow = true;
player.rotation = 180;
}
}
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;
}
}
//Hit Maze Function//
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;
}
