Posted By

orazal on 09/14/09


Tagged

mask 45degree bars


Versions (?)

45 degree bars


 / Published in: ActionScript
 

Creates a mask made of 45 degree bars to later animate in sequence

  1. var image:MovieClip = createImage(150, 150, 300, 100);
  2. createBarMask(image);
  3. function createImage(x:Number, y:Number, w:Number, h:Number):MovieClip
  4. {
  5. var image:MovieClip = this.createEmptyMovieClip("image", this.getNextHighestDepth());
  6. image.lineStyle(1, 0x222222, 100);
  7. image.moveTo(0, 0);
  8. image.lineTo(w, 0);
  9. image.lineTo(w, h);
  10. image.lineTo(0, h);
  11. image.lineTo(0, 0);
  12. image._x = x;
  13. image._y = y;
  14. return image;
  15. }
  16.  
  17. function createBarMask(target:MovieClip):Void
  18. {
  19. var barMask:MovieClip = this.createEmptyMovieClip("barMask", this.getNextHighestDepth());
  20. var bars:Number = ((target._width +target._height) -10) / 10;
  21. for(var i:Number = 0; i<bars ; i++)
  22. {
  23. var bar:MovieClip = barMask.createEmptyMovieClip("bar"+i, barMask.getNextHighestDepth());
  24. drawBar(bar, target._height);
  25. bar._x = 10 * i;
  26. }
  27. barMask._x = target._x - target._height;
  28. barMask._y = target._y;
  29.  
  30. }
  31.  
  32. function drawBar(mc:MovieClip,h:Number):Void
  33. {
  34. var w:Number = 10;
  35. var xDecal:Number = h;
  36. mc.beginFill(Math.random()*0xFF0000, 80);
  37. mc.moveTo(0, 0);
  38. mc.lineTo(xDecal, 0 + h);
  39. mc.lineTo(xDecal + w, 0 + h);
  40. mc.lineTo(w, 0);
  41. mc.lineto(0, 0);
  42. mc.endFill();
  43. }

Report this snippet  

You need to login to post a comment.