Try this :

 import mx.utils.Delegate;
 class Ball {
    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',
 _level0.getNextHighestDepth()  );

        // draw ball
        aBall._x = 100;
        aBall._y = 100;
        aBall.lineStyle(20, 0xff0000, 100);
        aBall.lineTo(0,.2);
        declareEventMethods(aBall);//BWC - CHanged this to pass the item
    }

// pass the mc in
    public function declareEventMethods(p_mc:MovieClip):Void { 
p_mc.onPress =
 Delegate.create(this,onPress);  }4

   private function  onPress () {  dispatchEvent( {type: "press",
 target: this} );  }

 }


- you were trying to detect an OnPRESS eventon the ball class yet it
doesn;t extend Movieclip



> Hi Johannes -
>
> Thank you so much for your suggestions - I really do appreciate the
> help.
>
> I've removed MovieClip extension from the class, but it's still not
> working - it's still the same as where I started - the "Ball" object
> renders, but  events don't trigger the handler.
>
> I've streamlined things slightly - eliminated whitespace mostly, Please
> - I'm so lost here, this seems so simple.
>
> This is where the code is at:
>
> -----------------------------------------------------------------
> timeline.as
> -----------------------------------------------------------------
>
> 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);  }
>
> -----------------------------------------------------------------
> Ball.as
> -----------------------------------------------------------------
>
> import mx.utils.Delegate;
> class Ball {
>
>    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',
> _level0.getNextHighestDepth()  );
>
>       // draw ball
>       aBall._x = 100;
>       aBall._y = 100;
>       aBall.lineStyle(20, 0xff0000, 100);
>       aBall.lineTo(0,.2);
>       declareEventMethods();
>    }
>
>    public function declareEventMethods():Void {  onPress =
> Delegate.create(this,onPress);  }4
>
>    private function  onPress () {  dispatchEvent( {type: "press",
> target: this} );  }
>
> }
>
>
>
>
> -------------------------------------------------------
> [EMAIL PROTECTED]
> 917-750-6398
> AIM: dcardena
> -------------------------------------------------------
>
>
>
>
> On Apr 12, 2006, at 8:55 PM, Johannes Nel wrote:
>
>> ok sorry, you are extending movieclip. i thought for soem reason you
>> were
>> not. there is no reason for you to be extending movieclip, so don't
>>
>> once you have gotten rid of the inheritance then it should work. the
>> reason
>> the onPress function works is due to the fact that you are extending
>> movieclip, and then you assign a different refrence for that function.
>>
>> anyway i hope you understand what i am tryimg to say
>> _______________________________________________
>> Flashcoders@chattyfig.figleaf.com
>> 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
>>
>
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> 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



_______________________________________________
Flashcoders@chattyfig.figleaf.com
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