And don't forget to add:

    import mx.core.Application;

Up the top :)

On Mon, May 26, 2008 at 2:11 PM, Josh McDonald <[EMAIL PROTECTED]> wrote:

> Ok mate, here's the problem:
>
> public function FlexbController()
>         {
>             //turn the key, start it up....
>             addEventListener( FlexEvent.CREATION_COMPLETE, onInit );
>             trace("Controller");
>         }
>
> What you need, is this:
>
> public function FlexbController()
>         {
>             //turn the key, start it up....
>             Application.application.addEventListener(
> FlexEvent.CREATION_COMPLETE, onInit );
>             trace("Controller");
>         }
>
> The reason for this, is the way CREATION_COMPLETE is dispatched - which is
> from the bottom of your display tree upward. It has to be this way, because
> it's dispatched only after all the children of a component have already had
> CREATION_COMPLETE dispatched. So first it is dispatched on all instantiated
> UIComponents that don't have any children. Then (probably on the next frame,
> but ask Alex) it's dispatched on their container components, and so on and
> so forth until finally (as far as we care) it's dispatched on your root
> Application. It might be then dispatched on a few containers up to the
> systemManager, but again Alex would know better than me.
>
> Now what happens in your case, CREATION_COMPLETE is dispatched on your
> FlexbController, and then you're dispatching the GET_NEWS_EVENT immediately.
> But, the current instance of FlexbController is not yet part of the
> displayTree, because it hasn't been completely added to the Application's
> children yet. So the event has nowhere to bubble to - and never reaches the
> Application, or the SystemManager.
>
> But, if you defer onInit() until CREATION_COMPLETE is dispatched on the
> Application itself, you know that the display tree is complete (in its
> initial layout at least), and you can safely dispatch the event and have it
> bubble all the way to the top of the tree at SystemManager.
>
> -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]
>



-- 
"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