Hooman's Portfolio  
 Contact  
 Hootris  
 Dinky Chase  
 Hooman to Eves  
 Eves To Hooman  
Simple Button ActionScript 3.0

Another Flash Demo

This is another simple demo I wrote in AS3. Here, I am experimenting with the Flash authoring environment - the two buttons were created beforehand in the Flash editor rather than at runtime. The code for the demo is provided at the bottom of the page.

Click the add and subtract buttons or use the arrow keys to see what happens.


Note: The following code was added straight into the first frame of the flash movie.

var num:Number = 0;
var dx:Number = 0, dy:Number = 0;

Counter.addEventListener(MouseEvent.CLICK, CountIt);
SubCounter.addEventListener(MouseEvent.CLICK, SubIt);
TheCount.text = "0"

var Box:Sprite = new Sprite();
var T:TextField = new TextField;

T.text = "Use the arrow keys to move me.";
T.width = 300;
T.x = 20;

Box.graphics.lineStyle(0x000000);
Box.graphics.beginFill(0x777777);
Box.graphics.drawRect(0, 0, 200, 20);
Box.graphics.endFill();
Box.x = 150;
Box.y = 250;

this.addChild(Box);
Box.addChild(T);

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyUnpressed);

var mainTimer:Timer = new Timer(5); // every 20 milliseconds
mainTimer.addEventListener(TimerEvent.TIMER, MainLoop);
mainTimer.start();

function CountIt(e:MouseEvent):void {
num++;
TheCount.text = String(num);
}

function SubIt(e:MouseEvent):void {
num--;
TheCount.text = String(num);
}

function KeyPressed(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.LEFT) dx = -2;
if (e.keyCode == Keyboard.RIGHT) dx = 2;
if (e.keyCode == Keyboard.UP) dy = -2;
if (e.keyCode == Keyboard.DOWN) dy = 2;
}

function KeyUnpressed(e:KeyboardEvent):void {
if (e.keyCode == Keyboard.LEFT) dx = 0;
if (e.keyCode == Keyboard.RIGHT) dx = 0;
if (e.keyCode == Keyboard.UP) dy = 0;
if (e.keyCode == Keyboard.DOWN) dy = 0;
}

function MainLoop(e:TimerEvent):void {
Box.x += dx;
Box.y += dy;
if (Box.x < 0) Box.x = 0;
if (Box.y < 0) Box.y = 0;
if (Box.x > 350) Box.x = 350;
if (Box.y > 380) Box.y = 380;
e.updateAfterEvent()
}

Latest Work:

Applications
Content Management System
Local Developer
Manager's Advantage
Manager's Advantage Support

Games • ActionScript 3
Hootris
Dinky Chase (not finished)

Demos • ActionScript 3
Loading and Saving XML
Physics - 2D Collision
Physics - 1D Collision
Scroller
Filters Demo
Transition Demo
Tween Demo
Psychedelic Stage Light
Video Player
Hotdog Guitar
Filters and Gradients
Keyboard Demo
Hello World
Simple Button

Previous Work:

Applications • Turbo Pascal
Map Editor
Master GFX 16
Hooman's File Manager

Games
Stone Bringer
The Original Hootris

Demos • C++ / DirectX
Fish