Introduction

Flash is a lightweight cross-platform runtime for rich media, enterprise applications and mobile applications, as well as an integrated development environment. Flash can be programmed in ActionScript 1/2/3.

Tuesday, September 23rd, 2003 at 7:01 pm

State

Basic implementation:

// :: Context :: //
class Context{
        private var state:State;

        public function request():Void{
                state.handle();
        }
        public function setState(aState:State):Void{
                state = aState;
        }
        public function getState():State{
                return state;
        }
}

// :: State :: //
interface State{
        public function handle():Void;
}

// :: ConcreteStateA :: //
class ConcreteStateA implements State{
        public function handle():Void{
                trace(”ConcreateStateA: handle“);
        }
}

// :: ConcreteStateB :: //
class ConcreteStateB implements State{
        public function handle():Void{
                trace(”ConcreateStateB: handle“);
        }
}

// usage
aContext = new Context();
aContext.setState(new ConcreteStateA());
aContext.request();
aContext.setState(new ConcreteStateB());
aContext.request();

This is only one way to change the state. I have chosen this way for simplicity. You could also change the state dynamically depending on for example a local connection or a mouse press etc. It depends on the context.