  | |  | EventDispatcher 1 frame delay | EventDispatcher 1 frame delay
2004-02-17 - By Muzak
Back Here 's some more code:
import mx.events.EventDispatcher;
class BasicClass extends MovieClip {
private var __width:Number;
private var __height:Number;
private var preview_mc:MovieClip;
//
private static var __eventInit = EventDispatcher.initialize(BasicClass.prototype);
var addEventListener:Function;
var removeEventListener:Function;
var dispatchEvent:Function;
//
function BasicClass() {
__width = _width;
__height = _height;
_xscale = _yscale=100;
init();
}
function init() {
createChildren();
}
function createChildren() {
draw();
}
function draw() {
dispatchEvent({type: "draw "});
size();
}
function size() {
preview_mc._width = __width;
preview_mc._height = __height;
dispatchEvent({type: "size "});
}
function setSize(w,h){
__width = w;
__height = h;
size();
}
function changeEvent() {
trace( "BasicClass ::: changeEvent ");
dispatchEvent({type: "change "});
}
}
In the FLA, code and component instance in first frame, nothing else.
var handlerObject:Object = {};
handlerObject.draw = function(o) {
trace( "handlerObject ::: draw ");
};
handlerObject.size = function(o) {
trace( "handlerObject ::: size ");
};
handlerObject.change = function(o) {
trace( "handlerObject ::: change ");
};
basic_mc.addEventListener( "draw ", handlerObject);
basic_mc.addEventListener( "size ", handlerObject);
basic_mc.addEventListener( "change ", handlerObject);
//
basic_mc.setSize(200,200);
basic_mc.changeEvent();
// trace output:
BasicClass ::: size
BasicClass ::: setSize
BasicClass ::: size
handlerObject ::: size
BasicClass ::: changeEvent
handlerObject ::: change
So, the 'size ' event only gets triggered when the setSize() method is called.
Maybe my way of saying that 'it takes a frame ' is not correct.
I just assumed that, since there 's a size event dispatched in the size method and i have a listener set up for it, I expected it to
work right away (as soon as the component initializes), which doesn 't seem to be the case.
I think what was unclear to me is when exactly listeners are being added.
Sorry if I 'm not making any sense. I 'm having a hard time explaining what 's in my head :(
Thanks for your time.
kind regards,
Muzak
-- -- Original Message -- --
From: "Tatsuo Kato " <studio@(protected) >
To: <flashcoders@(protected) >
Sent: Tuesday, February 17, 2004 7:59 PM
Subject: Re: [Flashcoders] EventDispatcher 1 frame delay
> hm, I still don 't get your point, Muzak. Neither does Phil, it seems.
>
> It doesn 't take a frame or an interval for an object initialized with
> mx.events.EventDispatcher to be able to dispatch an event.
> It only needs a fact that a listener is registered before dispatching.
>
> And it works for me wherever it 's written, frame1 of _root or the
> component or wherever.
> In order for it to work, it just needs a listener having been registered
> before dispatching.
>
> Cheers,
> --
> Tatsuo Kato
> http://tatsuokato.com
>
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104525
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |