Author Archives: Zevan

Matrix.transformPoint()

CLICK HERE TO COPY
Actionscript:

var circle:Shape = Shape(addChild(new Shape()));

with(circle.graphics) beginFill(0x00000), drawCircle(0,0,10);

 

var point:Point = new Point();

var trans:Matrix = new Matrix();

trans.rotate(Math.PI);

trans.scale(.5, .5);

trans.tx = stage.stageWidth / 2;

trans.ty = stage.stageHeight / 2;

 

addEventListener(Event.ENTER_FRAME, onLoop);

 

function onLoop(evt:Event):void {

    point.x = mouseX - trans.tx;

    point.y = mouseY - trans.ty;

   

    point = trans.transformPoint(point);

   

    circle.x = point.x;

    [...]

Posted in misc, motion | Tagged , , | Leave a comment

BitmapData.floodFill()

CLICK HERE TO COPY
Actionscript:

var canvas:BitmapData = new BitmapData(400,400,false, 0xCC0000);

addChild(new Bitmap(canvas));

 

var s:Shape = new Shape();

s.graphics.beginFill(0x00CCCC);

s.graphics.moveTo(Math.random()*400,Math.random()*400);

for(var i:int = 0; i<10; i++){

    s.graphics.lineTo(Math.random()*400,Math.random()*400);

}

canvas.draw(s);

 

stage.addEventListener(MouseEvent.CLICK, onDown);

function onDown(evt:MouseEvent):void {

    canvas.floodFill(mouseX, mouseY, 0x000000);

}

floodFill() is basically the paint bucket (fill) tool in any bitmap drawing program. The above example draws an arbitrary blue polygon to a red background. Click anywhere on [...]

Posted in BitmapData, pixel manipulation | Tagged , | Leave a comment

E4X and ActionScript Variables

CLICK HERE TO COPY
Actionscript:

var backgroundColor:uint = 0xEFEFEF;

var borderColor:uint = 0xFF0000;

var buttonOverColor:uint = 0x0000FF;

var buttonOutColor:uint = 0x00CCCC;

 

var uiColors:XML = <ui>

    <default color="0xCCCCCC" />

    <background color = { backgroundColor } />

   

    <!-- note hexidecimal formatting code -->

    <border color={ ("0x" + borderColor.toString(16)) } />

   

    <button overColor={ buttonOverColor} outColor={ [...]

Posted in XML, color, variables | Tagged , , , | Leave a comment

E4X Filtering

CLICK HERE TO COPY
Actionscript:

var userInfo:XML = <users>

  <user fname="joe" lname="smith" age="31" />

  <user fname="mildred" lname="calder" age="64" />

  <user fname="ben" lname="nathanson" age="20" />

  <user fname="james" lname="biuford" age="19" />

  <user fname="nick" lname="calhoun" age="45" />

</users>;

 

 

trace("Users over 20:\n");

trace(userInfo.user.(@age> 20).toXMLString());

 

trace("\nUsers with the name nick:\n");

trace(userInfo.user.(@fname == "nick" ).toXMLString());

 

// use regular expressions with e4x

trace("\nUsers with name starting with j:\n");

trace(userInfo.user.(/^j/.test(@fname)));

 

/*

outputs:

 

Users over 20:

 

<user fname="joe" [...]

Posted in XML | Tagged , , , , | 2 Comments