This is better, more extensible
// on timeline
var myBall:Ball2 = Ball2.createInstance( this, 2 ).init();
myBall.addEventListener( 'ALL', this );
function onBallPress():Void {
trace("onBallPress");
}
// Ball Class
import com.qdc.events.QDispatcher;
import com.dynamicflash.utils.Delegate;
class Ball2 extends MovieClip
{
// constants
public static var CLASS_NAME : String = "Ball2";
public static var SYMBOL_NAME : String = "testBall";
// methods
public function dispatchEvent() {};
public function addEventListener() {};
public static function createInstance( parent:MovieClip,
depth:Number, name:String ) : Ball2
{
if( depth == undefined) depth =
parent.getNextHighestDepth();
if( name == undefined) name = SYMBOL_NAME + depth;
return Ball2( parent.attachMovie( SYMBOL_NAME, name,
depth));
}
public function init() : Ball2
{
QDispatcher.initialize( this );
this._x = 100;
this._y = 100;
this.lineStyle(20, 0xff0000, 100);
this.lineTo(0,.2);
return this;
}
public function onLoad() : Void
{
aBall.onPress = dispatchEvent( { type : 'onBallPress' } );
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Patrick
Matte
Sent: Thursday, 13 April 2006 1:12 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Need help understanding EventDispatcher
I dont see exactly why use for the event dispatcher.
Wouldn't this be good as well ?
// on timeline
import Ball2.as;
import mx.utils.Delegate;
var myBall:Ball2 = new Ball2();
myBall.onBallPress = Delegate.create(this,onBallPress);
myBall.addEvents();
function onBallPress():Void {
trace("onBallPress");
}
// ball class
import mx.utils.Delegate;
class Ball2 {
public var onBallPress:Function;
private var aBall:MovieClip;
public function Ball2 () {
// 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);
}
public function addEvents():Void{
aBall.onPress = Delegate.create(this,onBallPress);
}
}
_______________________________________________
[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
_______________________________________________
[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