View Full Version : Flash CS4 IK with AS3?
Ingenieurs2
10-21-2008, 12:36 PM
Hello.
I just got my copy of the CS4 installed :) and so far its great. One thing I'm really keen to get playing with is the IK system, but it seems you can't control IK from code? Am I correct, or missing something? I'd love to be able to tween the clips around and have the IK update, but when I run a tween on any MC it moves leaving the IK armature untouched.
Any ideas?
A.
wvxvw
10-21-2008, 12:59 PM
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/fl/ik/IKManager.html
You may try reading this, I haven't found any other more advanced examples so far, but, yes, certainly, you may have control over IK with AS.
Cool I will have to have a play sometime, some googling and following links eventually lead me here...
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS76E4A0A2-F3D9-43c8-BA07-A2B6D6DE5266.html
Ingenieurs2
10-21-2008, 04:17 PM
I've had a look through both of these, I found them earlier. It seems a very complex class. I'm trying to get an IK chain to point at something I can move with a Tween, not with a click/drag.
Not sure your really ment to use tweener with it, but I got something working, I have not bothered to do anything pretty or complex just a proof of concept, I am really excited by this IK stuff, timeline just became more interesting again, but it sure took a lot of digging around to work out how to use it, may save others some time.
http://www.justinfront.net/CS4/LegIKTest/legIKtest.swf
The test fla is also there so you can experiment
package net.justinfront
{
//
// LegIKTest
//
// please retain credits with code
// created by: JLM at Justinfront
// 22 October 2008
//
// Example of using IKArmature with Tweener
//
//
import fl.ik.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import caurina.transitions.Tweener;
public class LegIKTest extends Sprite
{
private var _leg_ik: IKArmature
private var _thigh_ik: IKBone;
private var _shin_ik: IKBone;
private var _thighHeadJoint: IKJoint;
private var _thighTailJoint: IKJoint;
private var _shinHeadJoint: IKJoint;
private var _shinTailJoint: IKJoint;
private var _shinTailPos: Point;
private var _shinTailPosOrig: Point;
private var _mover: IKMover;
public function LegIKTest():void
{
// wait for Armature xml? data to be populated.
// make sure in the armature properties the options Type is set to Runtime
addEventListener(Event.FRAME_CONSTRUCTED, legReady );
}
private function legReady( e: Event ):void
{
removeEventListener(Event.FRAME_CONSTRUCTED, legReady );
trace(" Number of armatures on stage " + IKManager.numArmatures );
_leg_ik = IKManager.getArmatureByName("leg");
trace( "leg_ik.name: " + _leg_ik.name );
_thigh_ik = _leg_ik.getBoneByName("thighBone");
_shin_ik = _leg_ik.getBoneByName("shinBone");
_thighHeadJoint = _thigh_ik.headJoint;
_thighTailJoint = _thigh_ik.tailJoint;
_shinHeadJoint = _shin_ik.headJoint;
_shinTailJoint = _shin_ik.tailJoint;
_shinTailPos = _shinTailJoint.position;
_shinTailPosOrig = _shinTailJoint.position;
_mover = new IKMover( _shinTailJoint, _shinTailPos );
_mover.iterationLimit = 0;
moveBack();
}
private function moveBack():void
{
Tweener.addTween( _shinTailPos, {
x: _shinTailPos.x + 100,
y: _shinTailPos.y - 50,
time: 2,
delay: 0.5,
transition: "easeInOutSine",
onUpdate: updateMover,
onComplete: goBack
});
}
private function goBack():void
{
trace( 'goback');
Tweener.addTween( _shinTailPos, {
x: _shinTailPosOrig.x,
y: _shinTailPosOrig.y,
time: 2,
delay: 0.5,
transition: "easeInOutSine",
onUpdate: updateMover
});
}
private function updateMover():void
{
// update position of leg
_mover.moveTo( _shinTailPos );
}
}
}
Ingenieurs2
11-10-2008, 10:18 PM
Hello.
Sorry for not replying sooner, I hadn't seen this. Many thanks. I'm off to play with IK. :)
|
vBulletin® v3.8.5, Copyright ©2000-2010, Jelsoft Enterprises Ltd.