Posted By

adrianparr on 03/15/10


Tagged

border as3 stage rect


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

davidino1978
leongaban
tspitzr


AS3 Draw a Border around the stage


 / Published in: ActionScript 3
 

This function returns a Shape that can be used as a border around your Flash movie. It accepts a colour, width and an alpha.

  1. package
  2. {
  3. import flash.display.MovieClip;
  4. import flash.display.Shape;
  5.  
  6. public class DrawBorder extends MovieClip
  7. {
  8. private var _border:Shape;
  9. private var _borderColour:uint = 0xFF0000;
  10. private var _borderWidth:uint = 2;
  11. private var _borderAlpha:Number = 0.3;
  12.  
  13. public function DrawBorder():void
  14. {
  15. _border = new Shape();
  16. _border = drawBorder(_borderColour, _borderWidth, _borderAlpha);
  17. addChild(_border);
  18. }
  19.  
  20. private function drawBorder($borderColour:uint = 0x0000, $borderWidth:uint = 1, $borderAlpha:Number = 1):Shape
  21. {
  22. var border:Shape = new Shape();
  23.  
  24. border.graphics.beginFill($borderColour, $borderAlpha);
  25. border.graphics.drawRect($borderWidth, 0, stage.stageWidth-$borderWidth, $borderWidth);
  26. border.graphics.endFill();
  27.  
  28. border.graphics.beginFill($borderColour, $borderAlpha);
  29. border.graphics.drawRect(stage.stageWidth-$borderWidth, $borderWidth, $borderWidth, stage.stageHeight-$borderWidth);
  30. border.graphics.endFill();
  31.  
  32. border.graphics.beginFill($borderColour, $borderAlpha);
  33. border.graphics.drawRect(0, stage.stageHeight-$borderWidth, stage.stageWidth-$borderWidth, $borderWidth);
  34. border.graphics.endFill();
  35.  
  36. border.graphics.beginFill($borderColour, $borderAlpha);
  37. border.graphics.drawRect(0, 0, $borderWidth, stage.stageHeight-$borderWidth);
  38. border.graphics.endFill();
  39.  
  40. return border;
  41. }
  42.  
  43. }
  44.  
  45. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: adrianparr on January 10, 2011

I have now put this into a more concise static class which can be found here ... http://snipplr.com/view/46868/as3-drawpixelborderaroundstage-static-class/

You need to login to post a comment.