Author Archives: Zevan

Basic Tint Function

CLICK HERE TO COPY
Actionscript:

// display object, red (0-255), green, blue, amount (0-1)

function tint(dsp:DisplayObject, r:Number, g:Number, b:Number, amount:Number=1):void {

    if (amount != 1) {

        r *= amount;

        g *= amount;

        b *= amount;

    }

    amount = 1-amount;

    var ct:ColorTransform = transform.colorTransform;

    ct.redOffset [...]

Posted in color | Tagged , , , | 1 Comment

Mouse Velocity

CLICK HERE TO COPY
Actionscript:

var velocityInfo:TextField = new TextField();

velocityInfo.x = 20;

velocityInfo.y = 20;

addChild(velocityInfo);

 

var prevX:Number = mouseX;

var prevY:Number = mouseY;

var velX:Number = 0;

var velY:Number = 0;

 

addEventListener(Event.ENTER_FRAME, onLoop);

 

function onLoop(evt:Event):void {

     

     velX = mouseX - prevX;

     velY = mouseY - prevY;

     

     velocityInfo.text = velX + ", " + velY

     

    [...]

Posted in motion | Tagged , , , | 5 Comments

Animate Along a Path

CLICK HERE TO COPY
Actionscript:

stage.frameRate = 30;

var pencil:Shape = new Shape();

addChild(pencil);

 

var index:int = 0;

var points:Array = new Array();

var circle:Shape = new Shape();

circle.graphics.beginFill(0x000000);

circle.graphics.drawCircle(0,0, 5);

addChild(circle);

 

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

stage.addEventListener(MouseEvent.MOUSE_UP, onUp);

 

circle.addEventListener(Event.ENTER_FRAME, onMoveCircle);

 

function onDown(evt:MouseEvent):void {

    pencil.graphics.lineStyle(0,0x000000);

    pencil.graphics.moveTo(mouseX, mouseY);

    stage.addEventListener(MouseEvent.MOUSE_MOVE, onDraw);

}

 

function onUp(evt:MouseEvent):void {

    stage.removeEventListener(MouseEvent.MOUSE_MOVE, onDraw);

}

 

function onDraw(evt:Event):void {

    pencil.graphics.lineTo(mouseX, mouseY);

    points.push(new Point(mouseX, mouseY));

}

 

function onMoveCircle(evt:Event):void {

    if (points.length>0) {

  [...]

Posted in arrays, motion | Tagged , | 2 Comments

new Sprite() One-liner

CLICK HERE TO COPY
Actionscript:

var s:Sprite = Sprite(addChild(new Sprite()));

A way to make a new sprite, add it to the display list and store a reference to it.
Figured this out on my own... but have since seen it around on a few flash blogs here and there... thought it deserved a post.

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