Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created February 18, 2011 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/833653 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/833653 to your computer and use it in GitHub Desktop.
Implementation of Bota's (ialmeida.com) "getPlaceHolder()".
package tea.display
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.Stage;
import flash.geom.Rectangle;
/**
*
* Implementation of Bota's (ialmeida.com) "getPlaceHolder()".
*
* @param p_object Reference.
* @param p_thickness Border thickness.
* @param p_color Border color.
*
* @return A box with a "wireframe" based on reference dimension.
*
* @date 16/02/2011
* @author Rafael Rinaldi (rafaelrinaldi.com)
*
* */
public function getPlaceHolder( p_object : *, p_thickness : Number = 1, p_color : Number = 0xCC0000 ) : Sprite
{
var container : Sprite;
var shape : Shape;
var leftLine : Shape;
var rightLine : Shape;
var x : String = "x";
var y : String = "y";
var width : String = "width";
var height : String = "height";
var bounds : Rectangle;
if(p_object is Stage) {
width = "stageWidth";
height = "stageHeight";
}
if(p_object is Rectangle) {
bounds = p_object;
} else {
bounds = new Rectangle(
p_object[x],
p_object[y],
p_object[width],
p_object[height]
);
}
container = new Sprite;
shape = new Shape;
shape.graphics.lineStyle(p_thickness, p_color);
shape.graphics.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
shape.graphics.endFill();
leftLine = new Shape;
leftLine.graphics.lineStyle(p_thickness, p_color);
leftLine.graphics.moveTo(bounds.x + bounds.width, bounds.y + bounds.height);
leftLine.graphics.lineTo(bounds.x, bounds.y);
rightLine = new Shape;
rightLine.graphics.lineStyle(p_thickness, p_color);
rightLine.graphics.moveTo(bounds.x, bounds.y + bounds.height);
rightLine.graphics.lineTo(bounds.x + bounds.width, bounds.y);
container.addChild(shape);
container.addChild(leftLine);
container.addChild(rightLine);
return container;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment