In this code:

private function onInit( event:Event ):void
{
        systemManager.addEventListener( GetNewsEvent.GET_NEWS_EVENT,
                handler_GetNewsEvent );

        systemManager.addEventListener( AddNewsEvent.ADD_NEWS_EVENT,
                handler_AddNewsEvent );

        systemManager.addEventListener(
NewsDataLoadedEvent.NEWS_LOADED_EVENT,
                handler_NewsLoadedEvent );

        getNewsData();

        trace("onInit");

}

You're calling getNewsData before you do the trace from your init() method,
so you're getting the order you want but it looks otherwise. Whenever I've
using this sort of trace statement to debug a process execution, I make it
the first line of the method, and I suggest it's a good habit to have :)

When you call addEventListener, it has an immediate effect. But when you
call dispatchEvent, it sits in a queue until all other processing for this
frame is completed. Alex can tell you whether it's run in the last part of
this frame, or the first part of the next, but it's neither here nor there.
If you're adding a handler, and then calling the code that dispatches that
event, you should still be receiving the event in your handler, leaving me
to believe that something else is the cause of your woes.

How big is your project? If it's a reasonable size (and doesn't contain any
business secrets or anything), zip it up and upload it somewhere, and I'll
download the whole thing and have a look- I'm sure I'll be able to figure
out what you're doing wrong.

-J

On Mon, May 26, 2008 at 1:35 PM, dnk <[EMAIL PROTECTED]> wrote:

> Yeah that is what I thought.
>
> my onInit is called in my constructor  with:
>
> addEventListener( FlexEvent.CREATION_COMPLETE, onInit );
>
>
> The requests for data are usually called after other adding of the
> events, but within the same function  (onInit).
>
> I think I will just ad my addEventListener calls direct in my
> constructor and see what happens there.
>
> dnk
>
>
> On 25-May-08, at 2:08 PM, Alex Harui wrote:
>
> > Timers are normally not necessary. You need to have a clear
> > understanding of the application lifecycle and its events. I don't
> > know
> > when your onInit is getting called, but if it is after a request for
> > data has been sent, that's too late, you need to do it before the
> > request.
> >
> > -----Original Message-----
> > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
> > On
> > Behalf Of dnk
> > Sent: Sunday, May 25, 2008 11:40 AM
> > To: flexcoders@yahoogroups.com
> > Subject: Re: [flexcoders] custom event not added - almost solved.
> >
> > Ok, I might be onto something here.... I added trace statements in all
> > handlers and contructors, etc....
> >
> > And the order my traces come back are:
> >
> > Controller
> > getNewsData
> > onInit
> >
> > The order my traces SHOULD come back are:
> >
> > Controller
> > onInit
> > getNewsData
> >
> > Since my event listeners are setup in my onInit, and if they are being
> > added after my initial dispatchEvent is sent... well obviously they
> > will not be called.....
> >
> > So as a test I changed my onInt from:
> >
> > private function onInit( event:Event ):void
> > {
> > //setup event listeners
> > /*systemManager is where event listener hangs
> > out defines the
> > relationship between event and handler*/
> >
> > systemManager.addEventListener(
> > GetNewsEvent.GET_NEWS_EVENT,
> > handler_GetNewsEvent );
> > systemManager.addEventListener(
> > AddNewsEvent.ADD_NEWS_EVENT,
> > handler_AddNewsEvent );
> >
> > systemManager.addEventListener( NewsDataLoadedEvent.NEWS_LOADED_EVENT,
> > handler_NewsLoadedEvent );
> > getNewsData();
> >
> > trace("onInit");
> >
> > }
> >
> > To:
> >
> > private function onInit( event:Event ):void
> > {
> > //setup event listeners
> > /*systemManager is where event listener hangs
> > out defines the
> > relationship between event and handler*/
> >
> > systemManager.addEventListener(
> > GetNewsEvent.GET_NEWS_EVENT,
> > handler_GetNewsEvent );
> > systemManager.addEventListener(
> > AddNewsEvent.ADD_NEWS_EVENT,
> > handler_AddNewsEvent );
> >
> > systemManager.addEventListener( NewsDataLoadedEvent.NEWS_LOADED_EVENT,
> > handler_NewsLoadedEvent );
> > //getNewsData();
> > //dispatchEvent(new
> > GetNewsEvent(GetNewsEvent.GET_NEWS_EVENT));
> >
> > // Set a timer since the below function does not
> > seem to get fired.
> > var myTimer:Timer = new Timer(1, 1);
> > myTimer.addEventListener("timer", getNewsData);
> > myTimer.start();
> >
> > trace("onInit");
> >
> > }
> >
> > So I essentially setup a timer object to fire once like a second
> > later, and it works.
> >
> > So now this does in fact work as expected, but the method does not
> > seem "proper" to me.
> >
> > How would others get around this? Just do it the way I did? Or is
> > there a more "proper" and "elegant" solution for this?
> >
> > DNK
> >
> > On 24-May-08, at 9:09 PM, Alex Harui wrote:
> >
> > >
> > > Who's dispatching and how?
> > >
> > >
> > >
> > > When does the control get instantiated? Could it be after
> > > creationComplete?
> > >
> > >
> > >
> > > If the controller is not a UIComponent, it will not get a
> > > creationComplete.
> > >
> > >
> > >
> > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
> > > On Behalf Of dnk
> > > Sent: Friday, May 23, 2008 4:48 AM
> > > To: flexcoders@yahoogroups.com
> > > Subject: [flexcoders] custom event not added
> > >
> > >
> > >
> > > Hi there,
> > >
> > > I have a controller that is adding my custom event listeners, but
> > for
> > > some reason my event handler was not being fired.
> > >
> > > My original code was (snippet):
> > >
> > > (in controler)
> > >
> > > //constructor
> > > public function FlexbController()
> > > {
> > > //turn the key, start it up....
> > > addEventListener( FlexEvent.CREATION_COMPLETE, onInit );
> > > }
> > >
> > > private function onInit( event:Event ):void
> > > {
> > > //setup event listeners
> > > /*systemManager is where event listener hangs out defines the
> > > relationship between event and handler*/
> > >
> > > systemManager.addEventListener( GetNewsEvent.GET_NEWS_EVENT,
> > > handler_GetNewsEvent );
> > > systemManager.addEventListener( AddNewsEvent.ADD_NEWS_EVENT,
> > > handler_AddNewsEvent );
> > >
> > >
> > systemManager.addEventListener( NewsDataLoadedEvent.NEWS_LOADED_EVENT,
> > > handler_NewsLoadedEvent );
> > > getNewsData();
> > >
> > > }
> > >
> > > And I had trace statements in all of my handlers... this is how i
> > > noticed things were not working as they should.
> > >
> > > SO I added a simple check like (in my FlexbController constructor):
> > >
> > > if (systemManager.addEventListener( GetNewsEvent.GET_NEWS_EVENT,
> > > handler_GetNewsEvent ))
> > > {
> > > trace("true");
> > > } else {
> > > trace("false");
> > > }
> > >
> > > And I obviously am getting "false".
> > >
> > > Ideas?
> > >
> > > dnk
> > >
> > >
> > >
> > >
> >
> > ------------------------------------
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
> > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
> > Links
> >
> >
> >
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
> Links
>
>
>
>


-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]

Reply via email to