Category Archives: ActionScript3

Loop, Nested Grid – Create myBoxes

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.TweenMax;

public class createBoxes extends MovieClip {
private var boxNum:int = 100;
private var cols  :int = 10;

public function createBoxes():void {
var rows:int = Math.ceil(boxNum / cols);

for (var py:int = 0; py < rows; py++) {
for (var px:int = 0; px < cols; px++) {
var box:Box = new Box();
box.x = box.width * px;
box.y = box.height * py;
box.addEventListener(MouseEvent.ROLL_OVER, _rollOVER);
box.addEventListener(MouseEvent.ROLL_OUT, _rollOUT);
addChild(box);
} //END FOR

} //END FOR

} //END function
private function _rollOVER($evt:MouseEvent) {
var thisBox = $evt.target;
TweenMax.to(thisBox,.25,{alpha:0});
}
private function _rollOUT($evt:MouseEvent) {
var thisBox = $evt.target;
TweenMax.to(thisBox,.25,{alpha:1});
}
}

}

ThreeBoxes – TweenMax, TimelineLite

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.easing.*;

public class ThreeBoxes extends MovieClip {
private var box1:Box1 = new Box1 ();
private var box2:Box2 = new Box2 ();
private var box3:Box3 = new Box3 ();
private var button:Button = new Button ();
private var timeline:TimelineLite = new TimelineLite({onComplete:myFunction});

public function ThreeBoxes ():void {

timeline.append(TweenLite.to(box1, 1, {y:70}));
timeline.append(TweenLite.to(box2, 1, {y:70}),-0.5);
timeline.append(TweenLite.to(box3, 1, {y:70}));

timeline.appendMultiple([new TweenLite(box1, 1, {y:70,alpha:0}),
new TweenLite(box2, 1, {y:70,alpha:0}),
new TweenLite(box3, 1, {y:70,alpha:0})], 1, TweenAlign.START,0.2);

// timeline.addLabel(“box3Up”, 1.5);

button.addEventListener(MouseEvent.ROLL_OVER,_rollOver);
button.addEventListener(MouseEvent.ROLL_OUT,_rollOut);

box1.x = 104;
box1.y = 165;
box2.x = 238;
box2.y = 165;
box3.x = 372;
box3.y = 165;
button.x = 194;
button.y = 292;
addChild(box1);
addChild(box2);
addChild(box3);
addChild(button);
}

private function _rollOver($evt:MouseEvent):void {
timeline.reverse();
}
private function _rollOut($evt:MouseEvent):void {
timeline.play();
}
/*        private function _rollOver($evt:MouseEvent):void {
timeline.gotoAndPlay(“box3Up”);
}
private function _rollOut($evt:MouseEvent):void {
timeline.reverse();
}
*/

private function myFunction ():void{
trace(“Done!”);
}
}
}

TweenNano – easing

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.greensock.TweenNano;
import com.greensock.easing.*;
public class WW3 extends MovieClip {
var fighter:Fighter = new Fighter ();
public function WW3 () {
stage.addEventListener( MouseEvent.CLICK, myClick);
addChild(fighter);
fighter.x = 200;
fighter.y = 200;
trace(“I am a fighter!”);
}
private function myClick($evt:MouseEvent) {
TweenNano.to(fighter, 1, {x:$evt.localX, y:$evt.localY});
trace($evt.localX);
trace($evt.localY);
}
}
}

KeyboardEvent, MouseEvent, addChild, addEventListener

package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

 

public class Wednesday extends MovieClip{
var alien:MushroomMan = new MushroomMan();
public function Wednesday() {
alien.addEventListener( MouseEvent.CLICK, attack);
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyPressed);
addChild(alien);
alien.x = 300;
alien.y = 300;
alien.width = 80;
alien.height = 80;
trace(“woof! woof! woof!”)
}
private function attack($evt:MouseEvent) {
trace(“Meow! Meow! Meow!”);
}
private function keyPressed($evt:KeyboardEvent) :void {
switch($evt.keyCode)
{
case Keyboard.RIGHT :
alien.x += 5;
break;
case Keyboard.LEFT :
alien.x -= 5;
break;
case Keyboard.UP :
alien.y -= 5;
break;
case Keyboard.DOWN :
alien.y += 5;
break;
default :
trace(“a different key was pressed”);
break;
}
}
}
}