Wednesday, December 29, 2010

Flash: Inverse kinematics in external AS class

realised the following in IKManager reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/ik/IKManager.html?filter_flash=cs5&filter_flashplayer=10.1&filter_air=2#eventSummary

Note: When referencing IKArmature objects within a document class, be sure to first check the frameConstructed event to ensure that all objects have been populated.

else IKManager.numArmatures = 0 and IKManager.trackAllArmatures(false) will not work.

the bad thing is frameConstructed runs every frame. so one way is to use a boolean variable to track and run the code once.

can also use ENTER_FRAME

eg.:

public function IK_MC() // constructor
{
trace("start ik");

IKManager.trackAllArmatures(false); // will not work
this.addEventListener(Event.ENTER_FRAME, constructed);
}
function constructed(e:Event):void
{
//trace(IKManager.numArmatures);
if(IKManager.numArmatures > 0 && !init)
{
IKManager.trackAllArmatures(false);

var arm:IKArmature = IKManager.getArmatureByName("Armature_2");
trace(arm);
var arm2:IKArmature = IKManager.getArmatureAt(0);
trace(arm2);
init = true;
}
}

No comments: