flash on 2011-2-2

by omari
Build Intro
Learn class
make the square
♥0 | Line 104 | Modified 2011-02-02 21:36:28 | MIT License
play

ActionScript3 source code

/**
 * Copyright omari ( http://wonderfl.net/user/omari )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vFps
 */

package {
    import flash.display.*;
    import flash.events.*;
    
    public class Main extends MovieClip {
        private var intro:Intro;
        private var learn:Learn;
        private var drag:Drag;
        private var currentScreen:MovieClip;
        
        public function Main() {
            intro = new Intro();
            addChild(intro);
            currentScreen = intro;
            learn = new Learn();
            drag = new Drag();
        }
        public function gotoLearn():void {
            removeChild(currentScreen);
            addChild(learn);
            currentScreen = learn;
        }
        public function gotoDrag():void {
            removeChild(currentScreen);
            addChild(drag);
            currentScreen = drag;
        }
   
///////////////Build Intro
    import flash.display.*;
    import flash.events.*;
    
    class Intro extends MovieClip {
        
        public function Intro() {
            addEventListener(Event.ADDED_TO_STAGE, addedHandler);
            addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
            
            instructions_mc.visible = false;
            instructions_btn.addEventListener(MouseEvent.CLICK, showInstructions);
            playGame_btn.addEventListener(MouseEvent.CLICK, playGame);
        }
        private function addedHandler(event:Event):void {
            this.x = stage.stageWidth / 2;
            this.y = stage.stageHeight / 2;
        }
        private function removedHandler(event:Event):void {
            
        }
        private function showInstructions(event:MouseEvent):void {
            instructions_mc.visible = !instructions_mc.visible;
        }
        private function playGame(event:MouseEvent):void {
            MovieClip(parent).gotoLearn();
        }
    }


/////////Learn class
    import flash.display.*;
    import flash.events.*;
    
    class Learn extends MovieClip {
        private var clipArray:Array;
        private var labelArray:Array;
        
        public function Learn() {
            addEventListener(Event.ADDED_TO_STAGE, addedHandler);
            addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
            
            tooltip.visible = false;
            clipArray = [northAmerica, southAmerica, europe, asia, africa, australia];
            labelArray = ["northAmerica", "southAmerica", "europe", "asia", "africa", "australia"];
            
            for(var i:int = 0; i < clipArray.length; i++) {
                clipArray[i].addEventListener(MouseEvent.ROLL_OVER, over);
                clipArray[i].addEventListener(MouseEvent.ROLL_OUT, out);
            }
            
            learnBtn.alpha = 0.5;
            dragBtn.buttonMode = true;
            dragBtn.addEventListener(MouseEvent.CLICK, dragBtnClicked);
        }
        private function addedHandler(event:Event):void {
            this.x = stage.stageWidth / 2;
            this.y = stage.stageHeight / 2;
            
            addEventListener(Event.ENTER_FRAME, everyFrame);
        }
        private function removedHandler(event:Event):void {
            removeEventListener(Event.ENTER_FRAME, everyFrame);
        }
        private function everyFrame(event:Event):void {
            tooltip.x = mouseX;
            tooltip.y = mouseY;
        }
        private function over(event:MouseEvent):void {
            tooltip.visible = true;
            var index:int = clipArray.indexOf(event.currentTarget);
            tooltip.gotoAndStop(labelArray[index]);
        }
        private function out(event:MouseEvent):void {
            tooltip.visible = false;
        }
        private function dragBtnClicked(event:MouseEvent):void {
            MovieClip(parent).gotoDrag();
        }
    }
}

s
//////////////////////make the square
import flash.display.Sprite;

class Square extends Sprite {

public var s:Sprite=new Sprite;

public function Square():void{

s.graphics.beginFill(0xff9988);
s.graphics.drawRect(10,10,150,150);
s.graphics.endFill();
addChild(s);
}
}
}