In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

test_001

Get Adobe Flash player
by oxmo_456 19 Jun 2010
    Embed
/**
 * Copyright oxmo_456 ( http://wonderfl.net/user/oxmo_456 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vhay
 */

package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.display.Graphics;
    import flash.events.MouseEvent;
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            function createButton():MovieClip{
    var button:MovieClip=new MovieClip();
    var stateA:Shape=new Shape();
    var g:Graphics = stateA.graphics;
    g.beginFill(0xFF0000);
    g.drawRect(0, 0, 10, 10);
    g.endFill();
    button["stateA"] = stateA;
    button.addChild(stateA);
    var stateB:Shape=new Shape();
    g = stateB.graphics;
    g.beginFill(0x00FF00);
    g.drawRect(0, 0, 10, 10);
    g.endFill();
    button["stateB"] = stateB;
    button.addChild(stateB);
    stateB.visible=false;
    return button;
}
var nbButtons:int=10;
var buttons:Array=[];
var selectButton:MovieClip;
for (var i : int = 0;i < nbButtons; i++) {
    var button:MovieClip=createButton();
    addChild(button);
    button.y=10;
    button.x=i*12+10;
    addChild(button);
    buttons.push(button);
    setUpButton(button);
}
function setUpButton(button:MovieClip):void {
    button.buttonMode=true;
    button.addEventListener(MouseEvent.ROLL_OVER, buttonRollOver);
    button.addEventListener(MouseEvent.ROLL_OUT, buttonRollOut);
    button.addEventListener(MouseEvent.CLICK, buttonClick);
}
function buttonClick(e:Event):void{
    switchButtonStateToNotSelected();
    switchButtonStateToSelected(e.currentTarget as MovieClip);
}
function switchButtonStateToSelected(button:MovieClip):void{
    button.buttonMode=true;
    button.removeEventListener(MouseEvent.ROLL_OVER, buttonRollOver);
    button.removeEventListener(MouseEvent.ROLL_OUT, buttonRollOut);
    button.removeEventListener(MouseEvent.CLICK, buttonClick);
    button["stateA"]["visible"]=false;
    button["stateB"]["visible"]=true;
    selectButton=button;
}
function switchButtonStateToNotSelected():void{
    if(selectButton) {
        setUpButton(selectButton);
        selectButton["stateA"]["visible"]=true;
        selectButton["stateB"]["visible"]=false;
        selectButton=null;
    }
}
function buttonRollOver(e:Event):void{
    e.currentTarget["stateA"]["visible"]=false;
    e.currentTarget["stateB"]["visible"]=true;
}
function buttonRollOut(e:Event):void{
    e.currentTarget["stateA"]["visible"]=true;
    e.currentTarget["stateB"]["visible"]=false;
}
            
        }
    }
}