whats the purpose of the eventListener inside the constructor? init
is being implicitly called within the class... just dispatch the
event, and set up a listener in your FLA
edolecki
On Nov 13, 2005, at 9:37 AM, Javier Tello wrote:
Still doesn't work. If you look at the code the class fired the
event before deleting itself. Anyway I simplify it without the die
() method:
//
import mx.events.EventDispatcher;
//
//
class EventTry {
//
//members;
//event functions;
private var dispatchEvent:Function;
private var addEventListener:Function;
private var removeEventListener:Function;
//
//fired events;
public var onEvent:Function;
//
//
public function EventTry() {
EventDispatcher.initialize(this);
//here I define "onEvent";
this.addEventListener("onEvent", this);
init();
}
private function init() {
dispatchEvent({type:"onEvent", target:this});
}
}
and in the fla,
import EventTry;
//
var eventry:EventTry=new EventTry();
eventry.onEvent=function(){
trace(""onEvent fired"");
}
I make this class just as an example. Other classes I do before in
the flashmx2004 ide run well.
Please, try to look at it again,
Thanks,
Javier.
El 13/11/2005, a las 14:45, Ian Thomas escribió:
Hi Javier,
This is because you've got things happening in the wrong order:
- You create your EventTry() object, which calls init()
- Init fires the event, but onEvent is still undefined
- Init then calls die()
- Die() deletes the EventTry object
- You then set onEvent to your function - after everything else
has already
happened.
You need to set the onEvent object _before_ you fire the event to
have
anything
meaningful happen.
I can't understand how your old classes would have worked, looking
at this
code. Perhaps you're doing something slightly differently now?
Hope that helps,
Ian
On 11/13/05, Javier Tello <[EMAIL PROTECTED]> wrote:
Hello, I'm having troubles implementing the EventDispatcher class
with
flash8.
I do the same I use to do before, but now the class doesn't fired
the
event. Here is a sample class:
___
import mx.events.EventDispatcher;
//
class EventTry {
//event functions;
private var dispatchEvent:Function;
private var addEventListener:Function;
private var removeEventListener:Function;
//
//fired events;
public var onEvent:Function;
public function EventTry(){
EventDispatcher.initialize(this);
this.addEventListener("onEvent",this);
init();
}
//
private function init(){
dispatchEvent({type:"onEvent", target:this});
die();
}
private function die(){
removeEventListener("onEvent",this);
this=null;
delete this;
trace("EventTry die");
}
}
___
And here is the fla code:
import com.mg.temp.EventTry;
//
var etry:EventTry=new EventTry();
etry.onEvent=function(){
trace("onEvent fired");
}
//end
___
Here I doesn't get the "etry. onEvent" function fired. Also no
error,
it just ignore the statement.
Curiously my older classes run well with such a code.
Any help would be appreciate,
thanks,
Javier.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders