Page 1 of 1

how to add movieclips to an armature ikNode already animated

Posted: Thu Nov 25, 2010 12:46 pm
by darknkreepy3#
Wouldn't it be great to make animation cycles in flash cs4 and cs5 and reuse them or make them accessible to modification at a later date? A simple technique is to make movieclips for all of the armature parts that you want to replace or tack on an external jpg (inside of a movieclip) even masked movieclips as children of the moving part of the armature.

you need to make all parts you want to replace exported for actionscript and call them in your class by the name you export (a class in a sort of kind of way, but literal in flash). You will get warnings about nothing referencing it, etc, until you put it in your .as class for your main flash body (timeline base, the main class / whatever name you like as long as your .as matches it).

Then by addChild the movieclip 'class' instance you create to the ikNode you want it to follow, or really be ontop of, it will go along with it.

note:I have noticed that if you have an armature animation on the main timeline, it works when testing in flash IDE [test movie] and loops just fine, but in an embed (object) it will not start the animation, and an additional timeline layer with the script of simply

Code: Select all

play();
is needed. And for a loop, at the end of a main timeline animation, it will stop at the end unless you put in a blank keyframe on the last frame of main timeline armature animation and again put

Code: Select all

play();
maybe it is some setting I am missing, but it is most likely either a flash player 10 bug, or an armature bug.
Image

Here it is in action


here is a ZIP of the project CS5 format
http://www.supercala.net/tuts/flash_ik/ ... follow.zip

Here is the as3 class

Code: Select all

package
	{
	/*
	simple ik attachment example v1.0 by Kristoffe Brodeur. ©2010 All Rights Reserved.
	11-24-2010
	*/
	//import flash.display.MovieClip; 
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.system.*;
	//-----
	public class follow_ikNode extends MovieClip
		{
		public var mc_follow:mc_dup;
		public var mc_mask1:mc_mask;
		
		public var flowerLdr:Loader;
		public var mcFlower:MovieClip;
		//-----
		public function follow_ikNode():void
			{
			/*
			without this line, the php loads as a text file, instead of the 'server' during testing
			local host with flash needs the php installed in apache etc to run
			*/
			Security.allowDomain("*");
		
			mc_follow=new mc_dup();
			mc_mask1=new mc_mask();
			mc_mask1.x=(mc_follow.width-mc_mask1.width)/2;
			mc_mask1.y=(mc_follow.height-mc_mask1.height)/2;
			ikNode_renamed.addChild(mc_follow);
			ikNode_renamed.addChild(mc_mask1);
			mc_follow.mask=mc_mask1;
			//
			load_example_image();
			}
		//-----
		public function attach_example_image(e:Event):void
			{
			var resize:int=84.95;
			flowerLdr.width=resize;
			flowerLdr.height=resize;			
			mcFlower.addChild(flowerLdr);
			ikNode_3.addChild(mcFlower);
			}
		//-----
		public function load_example_image():void
			{
			mcFlower=new MovieClip();
			flowerLdr=new Loader();
			var filename="sunflower.jpg";//600w x 600h jpg image
			var reqURL:URLRequest=new URLRequest(filename);
			flowerLdr.addEventListener(Event.ADDED,attach_example_image);
			flowerLdr.load(reqURL);
			}
		}		
	}