Simple BlendMode Nav

Actionscript:
  1. stage.frameRate=30;
  2. var nav:Sprite = Sprite(addChild(new Sprite()));
  3. nav.x=nav.y=150;
  4.  
  5. var cover:Sprite;
  6. var coverDest:Number=0;
  7. var spacing:int=4;
  8. var btnNum:int=6;
  9.  
  10. buildNav();
  11.  
  12. addEventListener(Event.ENTER_FRAME, onLoop);
  13.  
  14. function onLoop(evt:Event):void {
  15.     cover.x += (coverDest - cover.x) /4;
  16. }
  17.  
  18. function buildNav():void {
  19.     for (var i:int = 0; i<btnNum; i++) {
  20.         var b:Sprite=makeBox(50,50);
  21.         b.x = i * (b.width + spacing);
  22.         b.buttonMode=true;
  23.         b.addEventListener(MouseEvent.CLICK, onClick);
  24.     }
  25.     cover=makeBox(54, 60);
  26.     cover.blendMode=BlendMode.INVERT;
  27. }
  28.  
  29. function onClick(evt:MouseEvent):void {
  30.     coverDest=evt.currentTarget.x;
  31. }
  32.  
  33. function makeBox(w:Number, h:Number) {
  34.     var b:Sprite = new Sprite();
  35.     with (b.graphics) {
  36.         beginFill(0x000000),drawRect(-w/2,-h/2,w,h);
  37.     }
  38.     nav.addChild(b);
  39.     return b;
  40. }

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.

This entry was posted in motion and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*