Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread dnk
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

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* Your email settings:
Individual Email | Traditional

* To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)

* To change settings via email:
mailto:[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED]

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:

RE: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread Alex Harui
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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread dnk
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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread Josh McDonald
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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread Josh McDonald
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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread Josh McDonald
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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread dnk

Dude, you rule!

Thanks s much!

Dnk


On 25-May-08, at 9:12 PM, Josh McDonald wrote:


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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread Josh McDonald
No probs mate, it was pissing me off not know what the problem was, too :)

-J

On Mon, May 26, 2008 at 2:22 PM, dnk [EMAIL PROTECTED] wrote:

   Dude, you rule!

 Thanks s much!

 Dnk


 On 25-May-08, at 9:12 PM, Josh McDonald wrote:

 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

Re: [flexcoders] custom event not added - almost solved.

2008-05-25 Thread dnk

Yeah this one was a bit of a mind [EMAIL PROTECTED]@!#. Much appreciated.

DNK


On 25-May-08, at 9:26 PM, Josh McDonald wrote:

No probs mate, it was pissing me off not know what the problem was,  
too :)


-J


On Mon, May 26, 2008 at 2:22 PM, dnk [EMAIL PROTECTED] wrote:
Dude, you rule!


Thanks s much!

Dnk


On 25-May-08, at 9:12 PM, Josh McDonald wrote:


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