Hi everyone. I’m atm trying to get a little proof of concept up and running for armature control. I’ve gotten an armature of a top-down human figure setup, to point its arms at something. This worked perfectly initially.
Now I’m trying to get it to point it’s arms at a point, arms length away, in the direction of the cursor. so that the arms come together at the end.
I made a movieclip for this purpose and put my armature inside it. However I’m having problems accessing the position of the movieclip:
My code can be found at the bottom of the post. The important line is:
var pos:MovieClip = tree.parent;
This throws the following compile error:
Scene 1, Layer 'actions', Frame 1, Line 47 1119: Access of possibly undefined property parent through a reference with static type fl.ik:IKArmature.
As far as I can tell, this basically means you can’t get the parent of an armature. Could that really be so? Seems pointlessly inflexible. If the parent were null then that would indicate a problem with assigning it properly, but it won’t even let me check that property at all, which I think means that it doesn’t exist.
For reference, I’ve never used addChild anywhere in the code, as my movieclip containing the armature is present on stage to begin with. I don’t generally do that but it;s supposed to just be a quick test.
Farther to the above, I’m attempting testing the opposite way.
I instantiated the movieclip as a class onstage, and tried using getChildAt to find the armature within it.
This failed horribly, and after running through a loop of it’s children, I found out that the 5 child objects under it were all the seperate movieclips that the armature connects. It seems I can’t access the armature itself through the parent/child system.
I’m thoroughly confused about how this all works. any advice?
import fl.ik.*
import flash.geom.Point;
import flash.display.MovieClip;
//var tree:IKArmature = IKManager.getArmatureByName("figure");
var tree:IKArmature;
var ik1:IKMover;
var ik2:IKMover;
var armlength:int = 100;
function set_params()
{
if (tree != null)
{
trace('tree');
IKManager.setStage(stage);
var bone1:IKBone = tree.getBoneByName("arm1bone");
var bone2:IKBone = tree.getBoneByName("arm2bone");
var endEffector1:IKJoint = bone1.tailJoint;
var endEffector2:IKJoint = bone2.tailJoint;
var pos1:Point = endEffector1.position;
var pos2:Point = endEffector2.position;
ik1 = new IKMover(endEffector1, pos1);
ik1.limitByDistance = true;
ik1.distanceLimit = 0.1;
ik1.limitByIteration = true;
ik1.iterationLimit = 10;
ik2 = new IKMover(endEffector2, pos2);
ik2.limitByDistance = true;
ik2.distanceLimit = 0.1;
ik2.limitByIteration = true;
ik2.iterationLimit = 10;
}
}
stage.addEventListener(Event.ENTER_FRAME, frameFunc);
function frameFunc(event:Event)
{
tree = IKManager.getArmatureAt(0);
trace(tree);
set_params();
if (tree != null)
{
var pos:MovieClip = tree.parent;
var pt = new Point(mouseX, mouseY);
var me = new Point(pos.x, pos.y);
//var me = new Point(tree.parent.x, tree.parent.y);
var direction = new Point(pt.x - me.x, pt.y - me.y);
direction = direction.normalize(1);
direction.x = direction.x * armlength;
direction.y = direction.y * armlength;
pt = me.add(direction);
ik1.moveTo(pt);
ik2.moveTo(pt);
}
}