By Zevan | November 30, 1999
Actionscript:
-
const HALF_PI:Number = Math.PI / 2;
-
const RADS:Number = Math.PI / 180;
-
-
trace(HALF_PI);
-
// convert degrees to radians
-
trace(180 * RADS);
When I have constant values I often forget to go ahead and make use of the const keyword. I used to do this a good deal when AS3 first came out.... not sure why I stopped doing it. Anyway, hopefully this post will help remind me to use them...
A very common use for them is of course defining event types:
Actionscript:
-
// inside a class
-
public static const RENDER_COMPLETE:String = "renderComplete";
Posted in variables | Also tagged flash |
By Zevan | November 30, 1999
Actionscript:
-
stage.frameRate = 30;
-
var footA:MovieClip = makeFoot(0);
-
var footB:MovieClip = makeFoot(Math.PI);
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
graphics.clear();
-
graphics.lineStyle(0,0x000000);
-
graphics.moveTo(footA.x, footA.y);
-
graphics.curveTo(footA.x + 20, footA.y - 50, 200, 100);
-
graphics.curveTo(footB.x + 20, footB.y - 50, footB.x, footB.y);
-
}
-
-
function makeFoot(startAngle:Number):MovieClip {
-
var mc:MovieClip = MovieClip(addChild(new MovieClip()));
-
with(mc.graphics) beginFill(0x000000), curveTo(10,-10, 20, 0);
-
mc.x = 200;
-
mc.y = 200;
-
mc.sx = mc.x;
-
mc.sy = mc.y;
-
mc.t = startAngle;
-
mc.r = 50;
-
mc.addEventListener(Event.ENTER_FRAME, onRunFoot);
-
return mc;
-
}
-
function onRunFoot(evt:Event):void {
-
var mc:MovieClip = MovieClip(evt.currentTarget);
-
with(mc){
-
x = sx + r * Math.cos(t);
-
y = Math.min(sy, sy + r * Math.sin(t));
-
rotation = sy - y;
-
t += .15;
-
}
-
}
This is a funny looking snippet that creates a very primitive walk cycle with the Graphics class and sine and cosine.
Posted in motion | Also tagged flash |