Yes!!
Thanks a lot Martin, in the way you explain it, works. I didnĀ“t notice it before because in real coding perhaps doesn't have such issue. But it's something to remember.

_________________
that still wont work because you are dispatching the event before you bind the function as the handler.

what are you trying to achieve (apart from getting the event to fire), i know this is just an example, but it seems a bit strange.

anyway, you cant call init in the constructor to dispatch the event, because theres no method to handle the event.

you could take out the call to init from the constructor and call it seperately, then it should work :
_____________

So the sample code can look like this:

//
//import classes;
import mx.events.EventDispatcher;
//
//
class EventTry {
        //
        //members;
        //event functions;
        private var dispatchEvent:Function;
        public var addEventListener:Function;
        private var removeEventListener:Function;
        //
        //fired events;
        public var onEvent:Function;
        //
        private var msg:String;
        //
        public function EventTry(msg:String) {
                this.msg = msg;
                EventDispatcher.initialize(this);
                this.addEventListener("onEvent", this);
                //init();
        }
        public function getMsg():String {
                return msg;
        }
        //
        public function callEvent() {
                dispatchEvent({type:"onEvent", target:this});
                die();
        }
        //
        private function die() {
                removeEventListener("onEvent", this);
                trace("EventTry deleted");
        }
}

And the fla:
import com.mg.temp.EventTry;
//
var eventry:EventTry = new EventTry("hello again");
eventry.onEvent = function() {
        trace(this.getMsg());
};
eventry.callEvent();
//second call to see the event removed.
eventry.callEvent();
//
stop();
____________
Also thanks for the other useful approaches.
Regards,

Javier.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to