Author Archives: Zevan

Mini Tween Engine

CLICK HERE TO COPY
Actionscript:

var box:MovieClip = new MovieClip();

box.graphics.beginFill(0xFF0000);

box.graphics.drawRect(-25,-25,50,50);

addChild(box);

 

stage.addEventListener(MouseEvent.CLICK, onStageDown);

function onStageDown(evt:MouseEvent):void{

    moveTo(box, "x", 300, 2, Back.easeOut);

    moveTo(box, "y", 200, 2, Back.easeOut);

    moveTo(box, "scaleX", 2, 2, Back.easeOut);

    moveTo(box, "rotation", 180, 2, Quartic.easeOut, onDone);

    stage.removeEventListener(MouseEvent.CLICK, onStageDown);

}

                     

function onDone():void {

    moveTo(box, "x", 120, 2, [...]

Posted in dynamic, motion, properties | Leave a comment

Number.toFixed()

CLICK HERE TO COPY
Actionscript:

var someValue:Number = 2.0480531167374427;

 

// want to show only 3 decimal places?

trace(someValue.toFixed(3)); // outputs 2.048

An easy way to get rid of extra decimal values. This is useful when you want to show decimal values in text fields. I only recently noticed this in the docs, I used to do this type of thing:
CLICK [...]

Posted in Number | Tagged , | 4 Comments

XOR Color Invert

CLICK HERE TO COPY
Actionscript:

var yellow:uint = 0xFFFF00;

 

// draws yellow circle

with(graphics) beginFill(yellow), drawCircle(100,100,50);

 

// invert the color using XOR assignment

// yellow becomes 0x0000FF

yellow ^= 0xFFFFFF;

 

// draws blue  circle

with(graphics) beginFill(yellow), drawCircle(200,100,50);

Just a fun use for XOR. You could also do it without XOR assignment:
CLICK HERE TO COPY
Actionscript:

with(graphics) beginFill(yellow ^ 0xFFFFFF), drawCircle(200,100,50);

Playing a little with bitwise operators is [...]

Posted in Operators, one-liners | Tagged , , | Leave a comment

Toggle .visible

CLICK HERE TO COPY
Actionscript:

// toggle a DisplayObject's visible property

var shape = new Shape();

 

shape.visible = !shape.visible;

trace(shape.visible); // outputs false

 

shape.visible = !shape.visible;

trace(shape.visible); // outputs true

 

shape.visible = !shape.visible;

trace(shape.visible); // outputs false

 

shape.visible = !shape.visible;

trace(shape.visible);  // outputs true

This is pretty obvious to anyone with a full understanding of the ! operator. It's useful for things
like checkboxes and other types of [...]

Posted in Operators | Leave a comment