stage.frameRate=30;
var nav:Sprite = Sprite(addChild(new Sprite()));
nav.x=nav.y=150;
var cover:Sprite;
var coverDest:Number=0;
var spacing:int=4;
var btnNum:int=6;
buildNav();
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
cover.x += (coverDest - cover.x) /4;
}
function buildNav():void {
for (var i:int = 0; i<btnNum; i++) {
var b:Sprite=makeBox(50,50);
b.x = i * (b.width + spacing);
b.buttonMode=true;
b.addEventListener(MouseEvent.CLICK, onClick);
}
cover=makeBox(54, 60);
cover.blendMode=BlendMode.INVERT;
}
function onClick(evt:MouseEvent):void {
coverDest=evt.currentTarget.x;
}
function makeBox(w:Number, h:Number) {
var b:Sprite = new Sprite();
with (b.graphics) {
beginFill(0x000000),drawRect(-w/2,-h/2,w,h);
}
nav.addChild(b);
return b;
}
This is something I do in my intermediate flash classes… the only difference is that we do the graphics in the flash IDE during class time instead of drawing them with ActionScript.