4 October 2010
Some prior experience working with ActionScript 3 is recommended. Familiarity with the Flash authoring environment is also helpful.
Beginning
This article is the second of seven in a series highlighting examples of programming strategies that make it easier than ever before to create rich content in Adobe Flash CS5 Professional. Adobe Flash Player 10 introduced the ability to control parts of an animation using inverse kinematics (IK). Now, using Flash CS5, you can apply the effect of a spring to an IK armature.
The Developer Center article titled Exploring the Spring tool in Flash Professional CS5 explains how to add and control the spring's motion. In order to control an IK armature with ActionScript 3, you must first create the animation elements in the Flash authoring environment.
The following sample movie is designed as a bare bones test, so that is easier to understand how to set and control the properties. In a real world example, you can use any number of elements in the armatures you create.
Notice that when you are working in the authoring environment, you could set the value for Spring by entering a numeric value in the Spring section at the bottom of the Property inspector; leave this value set to 0.


A Spring is assigned to a reference of an IK joint obtained from the IK bone. The process for controlling IK joints with ActionScript is essentially the same as in Flash CS4. First, you'll use the IKManager.getArmatureByName() method to get an IKArmature object, in order to pass in the IK Armature's name. Next, call the IKArmature.getBoneByName() method with the IKArmature object referrer and pass an IK bone's name to the method as an argument. The method will return the reference of the IKBone object. Finally, you can manipulate the IKJoint object by setting its IKBone.headJoint and IKBone.tailJoint properties.
At this point, a spring can be assigned to the IKJoint object. As you saw in Figure 4, the Spring section in the Property inspector for an IK bone contains two controls, Strength and Damping. Using ActionScript, two properties are available to set the values: IKJoint.springStrength and IKJoint.springDamping respectively.
// frame action
// IK Armature: myArmature
// IK Bone: ikBoneBar
import fl.ik.IKManager;
import fl.ik.IKArmature;
import fl.ik.IKBone;
import fl.ik.IKJoint;
var ikNodeBar:MovieClip;
var myArmature:IKArmature = IKManager.getArmatureByName("myArmature");
var myBone:IKBone = myArmature.getBoneByName("ikBoneBar");
var myJoint:IKJoint = myBone.tailJoint;
myJoint.springStrength = 50;
myJoint.springDamping = 50;
In the code above, a spring was assigned to an IKJoint of the IKBone object. Because the IK armature was set to Runtime, the instance of the head joint can be dragged in the published SWF file.

If you drag the instances too quickly, the movement may appear unnatural. After testing your animation, you may choose to make the armature more complex by setting some restrictions to the joint.
To learn more about working with Inverse Kinematics, watch the videos Using Spring properties with IK bones and Spring for bones on Adobe TV.
As you can see from these examples, there are many new possibilities to explore when developing ActionScript 3 projects in Flash Professional CS5. Hopefully the scripts provided in these examples will serve as the starting point as you begin experimenting with the new events and capabilities for delivering rich content with interactivity.
Be sure to check out my other articles in this series:
To learn more about developing with ActionScript 3, see the following online resources:
Also be sure to visit the Flash Developer Center to find more articles and sample files to help you take your Flash projects to the next level.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
| 04/23/2012 | Auto-Save and Auto-Recovery |
|---|---|
| 04/23/2012 | Open hyperlinks in new window/tab/pop-up ? |
| 04/21/2012 | PNG transparencies glitched |
| 04/01/2010 | Workaround for JSFL shape selection bug? |
| 02/13/2012 | Randomize an array |
|---|---|
| 02/11/2012 | How to create a Facebook fan page with Flash |
| 02/08/2012 | Digital Clock |
| 01/18/2012 | Recording webcam video & audio in a flv file on local drive |