AS3 Flash Animation not fully working in captivate 5.5

105 views Asked by At

Hi I have done a few Flash Animations previously in AS3 all of which import and run fine in Captivate 5.5. However, One of them, a simple drag an drop game won't work. It imports and is visible in captivate everything works with one (irritating) problem. That is, the objects will not drop onto the appropriate drop zones. The animation works fine as an SWF in my browser but just will not function when put into captivate any ideas? The outline of the code is below. I am tearing my hair out, any advice would be greatly appreciated.

code:

right_mc.visible=false; 
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;  
var orig1Y:Number=item1_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item1_mc.buttonMode=true;    

function dragTheObject(event:MouseEvent):void { 
    var item:MovieClip=MovieClip(event.target); 
    item.startDrag(); 
  var topPos:uint=this.numChildren-1; 
    this.setChildIndex(item, topPos);    
}  

function item1Release(event:MouseEvent):void { 
    var item:MovieClip=MovieClip(event.target); 
    item.stopDrag();       
    if (dropZone1_mc.hitTestPoint(item.x,item.y)) { 
        item.x=dropZone1_mc.x; 
        item.y=dropZone1_mc.y; 
    } else { 
       item.x=orig1X; 
       item.y=orig1Y; 
    } 
};    

done_btn.addEventListener(MouseEvent.CLICK,checkAnswers);
function checkAnswers(event:MouseEvent):void { 
    if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
     dropZone16_mc.hitTestPoint(item16_mc.x,item16_mc.y)) {
        wrong_mc.visible = false;
        right_mc.visible = true;
    } else {
        wrong_mc.visible = true;
        right_mc.visible = false;
    }
}

reset_btn.addEventListener(MouseEvent.CLICK,reset);
function reset(event:MouseEvent):void { 
    item1_mc.x=orig1X; 
    item1_mc.y=orig1Y;     

    right_mc.visible=false; 
    wrong_mc.visible=false; 
}
1

There are 1 answers

1
blvz On BEST ANSWER

Because hitTestPoint only works with global coordinates. When you open the SWF in the browser, local and global coordinates are the same, that's why it works. But when you load it inside Captivate, they differ.

Try this:

import flash.geom.Point;

// ...

var localPoint:Point = new Point(item.x, item.y);
var globalPoint:Point = item.parent.localToGlobal(localPoint);
if (dropZone1_mc.hitTestPoint(globalPoint.x, globalPoint.y)) { 
    item.x = dropZone1_mc.x;
    item.y = dropZone1_mc.y;
}

// ...