Author Archives: Zevan

Format Phone #

CLICK HERE TO COPY
Actionscript:

var phoneField:TextField = new TextField();

with (phoneField) {

    type=TextFieldType.INPUT;

    maxChars=12;

    restrict="0-9";

    border=true;

    width=100;

    height=20;

    x=y=20;

}

addChild(phoneField);

 

phoneField.addEventListener(TextEvent.TEXT_INPUT, onInput);

 

function onInput(evt:TextEvent):void {

    if (phoneField.length==3 || phoneField.length==7) {

        phoneField.appendText("-");

        var leng:int=phoneField.text.length;

        phoneField.setSelection(leng, leng);

    }

}

Quick way to make sure text input [...]

Posted in string manipulation | Tagged , , | Leave a comment

perlinNoise()

CLICK HERE TO COPY
Actionscript:

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

addChild(new Bitmap(canvas));

 

addEventListener(Event.ENTER_FRAME, onLoop);

function onLoop(evt:Event):void {

  canvas.perlinNoise(200,200, 2, 1, true, false,0, true,

                              [new Point(mouseX, mouseY),

                              new Point(-mouseX, -mouseY)]);

    [...]

Posted in BitmapData, pixel manipulation | Tagged , , , | 1 Comment

drawPath() Circle Segment

drawPath() is flash 10 player only
CLICK HERE TO COPY
Actionscript:

[SWF(width=400,height=400,backgroundColor=0xEFEFEF,frameRate=30)]

 

const TWO_PI:Number = Math.PI * 2;

 

var resolution:Number = 50;

var step:Number = TWO_PI / resolution;

var maxIndex:int = 0;

 

var coords:Vector.<Number> = new Vector.<Number>();

var drawCommands:Vector.<int> = new Vector.<int>();

 

// populate vectors

for (var i:Number = 0; i <TWO_PI + step; i += step){

    coords.push(100 * Math.cos(i));

    coords.push(100 * Math.sin(i));

    [...]

Posted in Graphics, Vector | Tagged , , , | Leave a comment

Isometric Box

CLICK HERE TO COPY
Actionscript:

stage.frameRate = 30;

 

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

    makeBoxSegment(200, 200 - i, i * 2);

}

 

function makeBoxSegment(xp:Number, yp:Number, col:uint):Sprite {

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

    with (isoBox) scaleY = .5, y = yp, x = xp;

    var box:Shape = Shape(isoBox.addChild(new Shape()));

    box.rotation = 45;

    with (box.graphics) [...]

Posted in DisplayObject, Graphics | Tagged , , , | 2 Comments