Thursday, July 28, 2011
Review
import flash.events.KeyboardEvent;
import flash.utils.Timer;
/*
INTERMEDIATE AUTHORING
WEEK 2
*/
// CUSTOM OBJECTS
var plane:Object = new Object(); // creates a new object
plane.x = 200;
plane.y = 300;
plane.pitch = 0;
plane.roll = 5;
plane.yaw = 5;
trace(plane.roll);
// PROPERTIES
// POSITION
square01_mc.x = 100;
square01_mc.y = 300;
// SIZE (#1)
//square01_mc.width = 40;
//square01_mc.height = 40;
// SIZE (#2)
square01_mc.scaleX = .5; // scales using decimals between 0 and 1
square01_mc.scaleY = .5;
//square01_mc.scaleX = square01_mc.scaleY = .5; // one-line shortcut for setting
// the same value to multiple properties
// TRANSPARENCY
square01_mc.alpha = .75;
// ROTATION
square01_mc.rotation = 45; // sets the rotation to 45 degrees
square01_mc.rotation += 15; // adds 15 degrees to the current value
square01_mc.rotation -= 45; // rotate 45 degrees CCW
// EVENT LISTENERS
// MOUSE EVENTS
square01_mc.addEventListener(MouseEvent.CLICK, onClick);
square02_mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
//square01_mc.rotation += 15;
event.target.rotation -= 15;
}
// KEYBOARD EVENTS
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeypress);
function onKeypress(event:KeyboardEvent):void {
trace(event.keyCode);
switch(event.keyCode) {
case 38:
trace("up")
square02_mc.y -= 10;
break;
case 37:
trace("left");
square02_mc.x -= 10;
break;
case Keyboard.DOWN:
trace("down")
square02_mc.y += 10;
break;
case Keyboard.RIGHT:
trace("right");
square02_mc.x += 10;
break;
}
}
// TIMER EVENTS
var theTimer:Timer = new Timer(1000,5); // delay in milliseconds, repeat count (zero = forever)
theTimer.addEventListener(TimerEvent.TIMER,onTimer);
theTimer.start();
function onTimer(event:TimerEvent):void {
trace("Timer");
}
// ENTER FRAME EVENT
stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);
function onFrameLoop(event:Event):void {
square01_mc.rotation += 20;
}
Labels:
Week 2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment