Flash actionscript notes

h1. http://tv.adobe.com/show/actionscript-11-with-doug-winnie/

Creating Instances

Turn object into a movie clip. (Convert to symbol)
Make sure to check, "export to actionscript" and to give it a name
If you have an instance of the object on the stage you have to give that a name to access it from actionscript

trace("Hello, World");  // prints to output, similar to debug console in JS

var myCircle = new Circle(); // makes a new instance, but it won't appear on the stage yet
addChild(myCircle); // this adds it to the display stack

____

Functions

function runMe():void{
 trace("yo");
}

function reposition(newX:Number,myName:String):String{
 myObject.x = newX;
 return("Hello " + myName);
}

________

Events

myObject.addEventListener(MouseEvent.MOUSE_DOWN,callbackFunction);
 function callbackFunction(e:MouseEvent):void {
 trace("my object was clicked");
}

________

Timers

var myTimer = new Timer(1000,3);
myTimer.addEventListener(TimerEvent.TIMER, tickTock);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerFinished);
myTimer.start();
function tickTock(e:TimerEvent):void{
 trace("this gets outputted once a second for three times")
}
function timerFinished(e:TimerEvent):void {
 trace("Timer is Finished");
}

________

The Timeline (frame scripts)

stop();
// below, myObject has its own timeline
myObject.gotoAndStop(10);

----------

The Event Object

// attach a listener to everthing on the stage
addEventListener(MouseEvent.MOUSE_OVER, hover);
// in the function below, e.target is how you access the object that the event was called on
function hover(e.MouseEvent){
 e.target.alpha = .5;
 trace("Now over " + e.target.name");
}

_________

Drag and Drop

myObject.addEventListener(MouseEvent.MOUSE_DOWN, drag);
myObject.addEventListener(MouseEvent.MOUSE_up, drop);

function drag(e.MouseEvent):void{
myObject.startDrag();
}

function drop(e.MouseEvent):void{
myObject.stopDrag();
}

______

Math Functions

var num:Number;
num = Math.floor(5.8);
// num == 5
num = Math.ceil(5.2);
// num == 6
num = Math.round(5.5);
// num == 6
num = Math.ceil(Math.random() * 6);
// num is now equal to a number 1 through 6

______

Animation Basics

/*
 * move an object in a straight line, once every second for ten seconds
 */
// create a timer that broadcasts every second for 10 seconds
var animateTimer:Timer = new Timer(1000,10);

var slopeX = 10;
var slopeY = 15;

animateTimer.addEventListener(TimerEvent.TIMER, moveDot);
function moveDot(e.TimerEvent):void {
 myObject.x += slopeX;
 myObject.y += slopeY;
}

animateTimer.start();

-------

Loops

for(var i:Number = 0; 1 

Article Type

General