Author Archives: Zevan

Multiple Graphics Class Calls

CLICK HERE TO COPY
Actionscript:

// draw red circle

with (graphics) beginFill(0xFF0000), drawCircle(200,100,30);

 

// draw 100 gray circles

with (graphics) for (var i:int = 0; i<100; i++) beginFill(0x666666), drawCircle(Math.random()*200, Math.random()*200, Math.random()*10), endFill();

 

// draw a few lines

with (graphics) lineStyle(0, 0x000000), moveTo(10,210), lineTo(20,300), lineTo(30,210), lineTo(40,300), lineTo(50,210), lineTo(60,300);

Sometimes it's tedious to write lines and lines of Graphics class method calls. Using a with [...]

Posted in Graphics | 2 Comments

Click Listener

CLICK HERE TO COPY
Actionscript:

var e:String = "addEventListener";

 

stage[e]("click", function():void{

    trace("clicked", arguments[0]);

});

Strange code to do a click listener. arguments[0] is the event object. (Check out the "warning" page for more info about this).
CLICK HERE TO COPY
Actionscript:

stage.addEventListener(MouseEvent.CLICK, onStageClick);

function onStageClick(evt:MouseEvent):void {

    trace("clicked", evt);

}

Normal way.

Posted in Events | 2 Comments

2D Array Map

CLICK HERE TO COPY
Actionscript:

var col:Array = [0x000000, 0xCCCCCC, 0xFF0000, 0xCCCC00, 0x000055, 0x00CCCC];

 

var map:Array = new Array();

map[0] = [0,0,0,0,0,0,0,0,0,0];

map[1] = [0,0,0,0,0,0,0,0,0,0];

map[2] = [0,5,4,5,4,5,4,5,4,0];

map[3] = [0,4,4,4,4,4,4,4,4,0];

map[4] = [0,4,0,0,0,0,0,0,4,0];

map[5] = [0,3,2,3,2,3,2,3,2,0];

map[6] = [1,1,1,1,1,1,1,1,1,1];

map[7] = [0,2,2,2,2,2,2,2,2,0];

map[8] = [1,1,1,1,1,1,1,1,1,1];

 

for (var i:int = 0; i<map.length; i++){

    for (var j:int = 0; j<map[i].length; j++){

        graphics.beginFill(col[map[i][j]]);

        [...]

Posted in Graphics, arrays | Leave a comment

DisplayObject describeType()

CLICK HERE TO COPY
Actionscript:

for each(var prop:String in describeType(DisplayObject).factory.accessor.@name){

    trace(prop);

}

/* outputs

scaleY

mouseX

mouseY

mask

rotation

alpha

transform

blendMode

x

root

loaderInfo

width

z

rotationX

scale9Grid

filters

rotationY

y

stage

scaleZ

parent

accessibilityProperties

scrollRect

rotationZ

height

name

opaqueBackground

blendShader

cacheAsBitmap

visible

scaleX

*/

I First saw describeType() at senocular's AS3 Tip of the Day on Kirupa.

Posted in DisplayObject, XML | 1 Comment