home page icon Flash Bestiary / Oddments / Millard Fillmore Bobblehead

Millard Fillmore Bobblehead

This bobblehead movie also uses my SpringSim class from the Physics section. If you want to provide simple bobbing motion, this is a good example, since very little code is needed to create it.

The head movieclip is attached to a single invisible anchor, 100 pixels above it's pivot point.

You may drag the head to move it.

The code to set up a bobblehead looks like this:

#include "SpringSim.as"
// grav, stiff, friction
ss = new SpringSim(this, 2, 0.35, 0.07);

// Create an anchor point for the bobble head
var mc = this.createEmptyMovieClip("anc_mc", 10);
mc._x = head_mc._x;
mc._y = head_mc._y-100;
ss.addSpring(head_mc, mc, .8);

head_mc._x += 75;
radToDeg = 180/Math.PI;
deg90 = Math.PI/2;

head_mc.onEnterFrame = function()
  // Rotate head to match relationship to anchor point
  var dx = _root.anc_mc._x - this._x;
  var dy = _root.anc_mc._y - this._y;
  var ang = Math.atan2(dy,dx)+deg90;
  this._rotation = ang*radToDeg;


sourcecode iconDownload the flash project
book iconJim's Favorite Actionscript Books
wiki iconAsk Jim about Actionscript
Next: Karl Marx Paddleball

Having trouble opening the project? You may need to Upgrade to Flash MX 2004

Copyright © 2003,2004 by Jim Bumgardner. All Rights Reserved.        Leave Jim some feedback