Thanks Johannes!

Both your example and Stacey's have made my day. Clearly I need to bone up on Delegate.

FWIW - Stacey's example came in 11 bytes under yours - but that was only after I removed an extraneous character that threw an error...

So it's a draw.  :-)

Thank you all for all your help!

-Daniel



-------------------------------------------------------
[EMAIL PROTECTED]
917-750-6398
AIM: dcardena
-------------------------------------------------------




On Apr 12, 2006, at 9:49 PM, Johannes Nel wrote:

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


_______________________________________________
[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

Reply via email to