Bookmark Bookmark Bookmark Bookmark Bookmark Bookmark Bookmark My Bookmark - Become a Fan on Facebook!

LorenzGames, All about Flash Games!

Follow me on Twitter! Follow Me on Twitter

Moving Bones in AS3 and Flash CS4

June 19th, 2009 - Category: ActionScript 3, Developers, Flash
This tutorial will teach you the basics to add bones to an object and move them using ActionScript 3.

It is quite simple, those are the steps to do:
  1. Design something ( to test i designed something like a snake Emoticon ).
  2. Click on the button Bone Tool (X).
  3. Draw a bunch of bones on the object making sure they are attached.
OK, now you should have something like this:
A Snake moved with bones in AS3
Make sure the last bone on the head is called: ikBoneName6

As you can see in the TimeLine now you have a new layer called Armature_(Number), rename it to Armature_1 if it has another number.

Now click on the Armature_1 layer and you should see in the properties something like this:
Armature Bones setting in AS3
Make sure to change the Type in Runtime.

Now create an empty layer where to place the ActionScript on the TimeLine (to keep the tutorial short i placed everithing on the timeline).
import fl.ik.*;
 
var tree:IKArmature = IKManager.getArmatureByName("Armature_1");
var bone:IKBone = tree.getBoneByName("ikBoneName6");
 
// tailJoint will manage the point of your bone, if you want to manage the head of your bone you need to use headJoint
var tJ:IKJoint = bone.tailJoint;
var posT: Point=tJ.position;
 
var ikMover:IKMover = new IKMover(tJ, posT);
 
addEventListener(Event.ENTER_FRAME, onFrame); 
function onFrame(event:Event){
	posT.x=mouseX;
	posT.y=mouseY;
	ikMover.moveTo(posT);
}


Now you are set, Test the movie and you should get something like this:



Of course spending lil bit more of time will make this a lot better! Emoticon



Article Comments


_ - April 22nd, 2010
Thank you for your time!

erick - May 20th, 2010
hi,
I try to do this, but it's show a error:
"TypeError: Error #1009: Cannot access a property or method of a null object reference. at snake.fla::MainTimeline/frame1()"

erick - May 20th, 2010
My mistake, I forgot to change the type in Runtime

chartago - August 17th, 2010
Is there a way for doing that with boned movie clips instead of shapes? I've tried but clip wont work. Any ideas? Thanks

Write a Comment: