flash on 2011-1-31

by omari
♥0 | Line 64 | Modified 2011-01-31 20:10:12 | 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/cMDR
 */

package mensah.interactive{
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.*;
    import fl.transitions.easing.*;
    import mensah.interactive.ButtonSet;

    public class DisablingButton extends MovieClip {



        var labels:Array;
        var thisParent:*;
        var thisIndex:int;

        public function DisablingButton() {
            labels=this.currentLabels;
            this.addEventListener(MouseEvent.CLICK, disableButton);
            this.addEventListener(MouseEvent.ROLL_OVER, over);
            this.addEventListener(MouseEvent.ROLL_OUT, out);

            this.addEventListener(Event.ADDED, setParent);
        

        function disableButton(event:MouseEvent):void {
            for (var i:int=0; i < labels.length; i++) {
                if (labels[i].name == "disable") {
                    this.gotoAndPlay("disable");
                }
                this.removeEventListener(MouseEvent.CLICK,disableButton);
                this.removeEventListener(MouseEvent.ROLL_OVER,over);
                this.removeEventListener(MouseEvent.ROLL_OUT,out);
                enableOthers();
            }
        }

            function enableButton():void {
                this.addEventListener(MouseEvent.CLICK,disableButton);
                this.addEventListener(MouseEvent.ROLL_OVER,over);
                this.addEventListener(MouseEvent.ROLL_OUT,out);
                this.gotoAndStop(1);
            }

            function over(event:MouseEvent):void {
                for (var j:int=0; j < labels.length; j++) {
                    if (labels[j].name == "over") {
                        this.gotoAndPlay("over");
                    }
                }
            }

            function out(event:MouseEvent):void {
                for (var k:int=0; k < labels.length; k++) {
                    if (labels[k].name == "out") {
                        this.gotoAndPlay("out");
                    }
                }
            }

            function setParent(event:Event):void {
                if (this.parent is ButtonSet) {
                    thisParent=ButtonSet(this.parent);
                    for (var w:int=0; w < thisParent.buttons.length; w++) {
                        if (this == thisParent.buttons[w]) {
                            thisIndex=w;
                        }
                    }
                }
            

            function enableOthers():void {
                for (var z:int=0; z < thisParent.buttons.length; z++) {
                    if (z != thisIndex) {
                        thisParent.buttons[z].enableButton();
                    }
                }
            }

        }