By Zevan | November 25, 2008
CLICK HERE TO COPY
Actionscript:
stage.frameRate = 30;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void{
if (int(Math.random()*5)==1){
for (var i:int= 0; i<10; i++) createParticle();
}
}
function createParticle():void{
var s:MovieClip = new MovieClip();
s.graphics.beginFill(0);
s.graphics.drawCircle(0,0,Math.random()*10 + 2);
s.velX = Math.random()*10-5
s.velY = Math.random()*10-5
s.posX = s.x = 200;
s.posY = s.y = 200;
[...]
By Zevan | November 24, 2008
CLICK HERE TO COPY
Actionscript:
this.myVar = "I am a dynamic variable";
trace(this.myVar);
// trace(myVar) // will cause an error
This code will add dynamic untyped variables to the timeline. Although this example is pretty useless, it scratches the surface of an interesting topic.... by default all flash timeline code gets compiled into a giant dynamic document class that uses [...]
By Zevan | November 23, 2008
CLICK HERE TO COPY
Actionscript:
var counter:int = 0;
graphics.lineStyle(0,0x000000);
recursive();
function recursive():void{
if (counter <4000){
graphics.moveTo(10,10);
graphics.lineTo(counter, 200);
counter+=4;
// don't call recursive(), use setTimeout instead
setTimeout(recursive,0);
}else{
trace(counter / 4 + " lines were drawn");
}
Be careful with [...]
By Zevan | November 22, 2008
CLICK HERE TO COPY
Actionscript:
MovieClip.prototype.tint = function(col:uint):void {
var ct:ColorTransform = transform.colorTransform;
ct.color = col;
this.transform.colorTransform = ct;
}
var circle:MovieClip = MovieClip(addChild(new MovieClip()));
with (circle.graphics) {
beginFill(0x123455);
drawCircle(0,0,50);
x = 100;
y = 100;
}
circle.tint(0xFF0000);
When AS3 first came out I didn't realize that prototype was still around.... This adds a function called [...]