Center rectangle with random registration point
reload to generate a new rectangle with different registration point
♥0 |
Line 23 |
Modified 2012-09-05 18:05:35 |
MIT License
archived:2017-03-20 02:19:01
ActionScript3 source code
/**
* Copyright milchreis ( http://wonderfl.net/user/milchreis )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9lprq
*/
package
{
import flash.display.Sprite;
import flash.display.Shape;
public class FlashTest extends Sprite
{
public function FlashTest()
{
// write as3 code here..
var w:int = 150, h:int = 200;
var s:Shape = new Shape();
s.graphics.beginFill(0x00FF00);
s.graphics.drawRect(-w * Math.random(), -h * Math.random(), w, h);
s.graphics.drawCircle(0, 0, 5);
s.graphics.endFill();
addChild(s);
var left:Number = s.getRect(stage).left, top:Number = s.getRect(stage).top;
s.x = (stage.stageWidth - w)/2
+ (s.x - left); // offset origin - left edge
s.y = (stage.stageHeight - h)/2
+ (s.y - top ); // offset origin - top edge
}
}
}