23 April 2009

ActionScript Elevator System

My latest project belongs to '100% Useless Creations' category. It's an Elevator system which simulates how elevator works (imagine that!).

For start, I don't have stage independent elevator, but when project is finished it will be implemented. Instead I have whereIsIt function which locates elevator position based on elevator movie clip position.

function whereIsIt():Number {
var elPos = Math.floor(Math.abs(elevator_mc._y - 350));
return elPos;

I have 2 Boolean values 'up' and 'down' for elevator movement direction. Array calls holds values representing floors where elevator is heading next. When it reaches its destination, calls.shift() is called and than wait function. This function stops the elevator for given number of frames, in this case 36.

function wait() {
if (waitCounter > 0) {
waitSemaphore = true;
waitCounter -= 1;
waitSemaphore = false;
waitCounter = 36;

When system starts, variable waitSemaphore is set to false. This variable and wait function are basically simple counter, command which tells the elevator to stop for 36 frames before it goes to the next floor.

Besides gotoFloor function only function left is onEnterFrame function for elevator movie clip.

elevator_mc.onEnterFrame = function() {
if (calls.length > 0) {
if(up) {
this._y -= 2;
if(down) {
this._y += 2;
// trace("elevator is at: "+whereIsIt()+" floor.");

flash actionscript elevator system image preview




template by blogger templates