Hi,

I'm knocking up some simple tests to get EventDispatcher and Delegate
working, but I can't seem to get my rather simple example to work:

// MyButton.as

// EventDispatcher
import mx.events.EventDispatcher;
// Delegate
import mx.utils.Delegate;

class MyButton
{
        public var dispatchEvent:Function;
        public var addEventListener:Function;
        public var removeEventListener:Function;
        public var dispatchQueue:Function;
        
        private var mcButton:MovieClip;
        
        function MyButton (mcButton)
        {
                EventDispatcher.initialize (this);
                this.mcButton = mcButton;
                this.init ();
        }

        function init ()
        {
                this.mcButton.objRef = this;
                
                this.mcButton.onRelease = function ()
                {
                        Delegate.create(this.objRef, onClick)
                }
                // clearInterval(timeInt);
        }
        
        function onClick ()
        {
                dispatchEvent ({type:'click', target:this, message:'Hey dude the
button was clicked'});
        }

};


// ButtonListener.as

// EventDispatcher
import mx.events.EventDispatcher;
// Delegate
import mx.utils.Delegate;

class ButtonListener {

        public var dispatchEvent:Function;
        public var addEventListener:Function;
        public var removeEventListener:Function;
        public var dispatchQueue:Function;
        
        private var myButton:MyButton;
        
        function ButtonListener ()
        {
                myButton = new MyButton(_root.mcButton);
                
                myButton.addEventListener('click', Delegate.create(this, 
onClick));
        }
        
        function onClick (eventObj)
        {
       trace(eventObj.target);
       trace(eventObj.type);
       trace(eventObj.message);
       trace(eventObj.time);
        }
};


// Timeline
import MyButton;
import ButtonListener;
var myButtonListener = new ButtonListener();


I'm sure it's something blindingly obvious, but how do I get my
ButtonListener class to hear the 'click' event ?

Thanks,

Jon

--


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett
_______________________________________________
[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