Thanks Johannes,

I tried your code but it didn't work - no errors or anything, just didn't trigger the handler. Is there be a problem with my timeline code?
Note - I removed some events and methods to simplify the code.


------------------------------------------------
Class Code:
------------------------------------------------

import mx.utils.Delegate;
class Ball extends MovieClip {

  public var addEventListener:Function;
  public var removeEventListener:Function;
  private var dispatchEvent:Function;

  public function Ball () {
        // initialize EventDispatcher
        mx.events.EventDispatcher.initialize(this);

        // create a ball MC
var aBall:MovieClip = _level0.createEmptyMovieClip('testBall', getNextHighestDepth());

        // draw ball
        aBall._x = 100;
        aBall._y = 100;
        aBall.lineStyle(20, 0xff0000, 100);
        aBall.lineTo(0,.2);
        declareEventMethods();
  }

  public function declareEventMethods():Void {
        // removed onMouseDown, onMouseUp & onRelease functions to simplify
        aBall.onPress = Delegate.create(this,onPress );
  }

  // removed onMouseDown, onMouseUp & onRelease functions to simplify
  private function  onPress () {
         dispatchEvent( {type: "press", target: this} );
  }
}


------------------------------------------------
Timeline Code:
------------------------------------------------

/* create object
----------------------------------*/
var myBall:Ball = new Ball();
myBall.declareEventMethods();

/* add listener
----------------------------------*/
// removed onMouseDown, onMouseUp & onRelease events to simplify
myBall.addEventListener("press", myEventHandler);

/* define handler
----------------------------------*/
function myEventHandler(evt:Object):Void {
  trace('A ' + evt.type + ' event was dispatched by ' + evt.target);
}

// this works - but it's not what I'm trying to do...
// testBall.onPress = function () {myEventHandler(testBall);}



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




On Apr 12, 2006, at 8:32 PM, Johannes Nel wrote:

import mx.utils.Delegate;
class Ball extends MovieClip {

  public var addEventListener:Function;
  public var removeEventListener:Function;
  private var dispatchEvent:Function;

  public function Ball () {
         // initialize EventDispatcher
         mx.events.EventDispatcher.initialize(this);

         // create a ball MC
         var aBall:MovieClip = _level0.createEmptyMovieClip('testBall',
getNextHighestDepth());

         // draw ball
         aBall._x = 100;
         aBall._y = 100;
         aBall.lineStyle(20, 0xff0000, 100);
         aBall.lineTo(0,.2);
declareEventMethods();
  }

  public function declareEventMethods():Void {
aBall.onMouseDown = Delegate.create(this,onMouseDown);
aBall.onMouseUp = Delegate.create(this,onMouseUp );
aBall.onPress = Delegate.create(this,onPress );
aBall.onRelease= Delegate.create(this,onRelease);
}
     private function onMouseDown() {
                 dispatchEvent( {type: "mouseDown", target: this} );
         }
       private function  onMouseUp () {
                 dispatchEvent( {type: "mouseUp", target: this} );
         }
        private function  onPress () {
                 dispatchEvent( {type: "press", target: this} );
         }
        private function  onRelease() {
                 dispatchEvent( {type: "release", 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

Reply via email to