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



Reply via email to