Sunday, August 19, 2007


Events are WAY different than they used to be. Here's a quick rundown:

You now have to create a listener whenever you have a mouse event. Here is an example:

box_mc.addEventListener(MouseEvent.CLICK, onClick); //add click event and tell it to call onClick function
box_mc.addEventListener(MouseEvent.ROLL_OVER, boxOver); //rollover event, call boxOver function
box_mc.addEventListener(MouseEvent.ROLL_OUT, boxOut); //rollout even, call function called boxOver

function boxOver(event:MouseEvent):void{ = .5;

function boxOut(event:MouseEvent):void{ = 1;

function onClick(event:MouseEvent):void{
//trace("you've been clicked"); -= 15; += 45;

box_mc.buttonMode = true; //this tells box_mc to be a button and show the hand cursor

stage.addEventListener(KeyboardEvent.KEY_DOWN, jump); //add listener just like the mouse events (key down)
stage.addEventListener(KeyboardEvent.KEY_UP, land); //key up listener

function jump(event:KeyboardEvent):void{
box_mc.y -= 50;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, jump); //this will delete the key down listener when you push a key
stage.addEventListener(Event.ENTER_FRAME, flip); //this is the new enterframe event (this will call flip function)

function land(event:KeyboardEvent):void{
box_mc.y += 50;
stage.addEventListener(KeyboardEvent.KEY_DOWN, jump); //this creates a new key down listener when you release a key
stage.removeEventListener(Event.ENTER_FRAME, flip); //this removes the enterframe event when you release a key

function flip(event:Event):void{
box_mc.rotation += 45; //constantly rotates the box 45 degrees
box_mc.x += 10; //constantly moves the box 10 pixels to the right

var link:URLRequest = new URLRequest(""); //make the request

box_mc.addEventListener(MouseEvent.CLICK, onClick); //create the click listener, call function called onClick

function onClick(event:MouseEvent):void{
navigateToURL(link); //this will send the browser to the url specified above
box_mc.buttonMode = true; //make the movieclip a button

this is like the new setInterval

var jumpTimer:Timer = new Timer(5000, 10); //first peramiter is how often, second is how many times

jumpTimer.addEventListener(TimerEvent.TIMER, jump); //sets a listener to the jumpTimer timer, call function "jump"

function jump(event:TimerEvent):void{;

jumpTimer.start(); //this starts the timer DUH

1 comment:

Dessa said...

People should read this.