Simple Stepper Class in AS 2
- New keywords: Class, extends, Public/Private
- DataTyping
- Getter / Setter functions
- Linking a library symbol directly with a class
- and adding custom events with the new EventDispatcher class
Click here to download the source files and the presentation.
Along with me, there were Simon Horwith from Team Macromedia, who took an excellent session on Flex, and Owas Bhat who demonstrated various ways for skinning the Flash 2004 UI components.
Here is the code for the Stepper class:
import mx.events.EventDispatcher
class Stepper extends MovieClip {
// class definitions
private var next_mc:MovieClip;
private var back_mc:MovieClip;
private var label_txt:TextField;
private var _counter:Number = 0;
// event dispatcher props
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
// constructor function
function Stepper () {
EventDispatcher.initialize(this);
init();
}
// will be called by the constructor function
private function init() {
next_mc.onRelease = nextHandler;
back_mc.onRelease = backHandler;
label_txt.autoSize = 'center';
label_txt.text = _counter.toString()
}
private function nextHandler():Void {
_parent.index++ ;
//trace ('next clicked '+_parent._counter);
}
public function backHandler():Void {
_parent.index-- ;
//trace ('back clicked '+ _parent._counter);
}
public function set index (val:Number) {
_counter = val;
label_txt.text = _counter.toString();
//dispath event
dispatchEvent({type:"change"});
}
public function get index ():Number {
return _counter;
}
}



