import Ball.as;
/* create object */
var myBall:Ball = new Ball();
myBall.declareEventMethods();
/* add listener */
myBall.addEventListener("press", myEventHandler);
/* define handler */
function myEventHandler(evt:Object):Void { trace('evt.type: ' +
evt.type + ' | evt.target' + evt.target); }
import mx.utils.Delegate;
class Ball {
public var addEventListener:Function;
public var removeEventListener:Function;
private var dispatchEvent:Function;
private var aBall:MovieClip;
public function Ball () {
// initialize EventDispatcher
mx.events.EventDispatcher.initialize(this);
// create a ball MC
aBall = _level0.createEmptyMovieClip(
'testBall',_level0.getNextHighestDepth() );
// draw ball
aBall._x = 100;
aBall._y = 100;
aBall.lineStyle(20, 0xff0000, 100);
aBall.lineTo(0,.2);
declareEventMethods();
}
public function declareEventMethods():Void {
aBall.onPress = Delegate.create(this,onPress);
}
private function onPress () {
dispatchEvent( {type: "press",target: this} );
}
}
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com