AddedToStage called twice
Hi,
I have a problem, and I don't understand the cause.
I attached a sample project, with FDT.
I have a Context, an InitSiteCommand (called at startup) wich adds a view (Home). In HomeMediator, on "onRegister", I add a view (Player) and I'm listening for the event AddedToStage. But, the last event it's called twice ! You can see tracelog...
If someone could help me ? Maybe I do something wrong or it's a robotlegs issue. I used to work with Robotlegs for a while yet.
Thanks you.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Ondina D.F. on 08 Aug, 2011 05:58 PM
Hi myrddin
You forgot to attach your code:)
See this thread
http://knowledge.robotlegs.org/discussions/questions/253-understand...
and look at Shaun’s answers.
Without seeing your code, I would say to remove the listener like this:
public function SomeView()//constructor
{
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToTheStage,false,0,false);
}
public function onAddedToTheStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToTheStage);
doSomething();
}
If the view has a Mediator, you can doSomething() in its onRegister by calling view.doSomething()
If this doesn’t solve your problem, please attach your code or just paste a snippet.
Ondina
2 Posted by myrddin on 09 Aug, 2011 08:18 AM
Hi Ondina,
Sorry, It seems to me to have attached it...
For my problem, of course I can remove the listener but it's not normal that it's called twice... furthermore in an strange order.
Thanks,
myrddin
Support Staff 3 Posted by Ondina D.F. on 09 Aug, 2011 12:01 PM
Hi myrddin,
I can’t give you an accurate explanation of the event’s capture, target and bubble phases and how it traverses the display object tree up and down and the exact order of execution. It is beyond my level of expertise.
You’ll find lots of articles about this topic on the internet(s) ;)
“Event.ADDED_TO_STAGE fires twice” has been reported as a bug http://bugs.adobe.com/jira/browse/FP-1569 (Flash Player 10 - 10_0_12_36), that appears to be fixed, but it isn’t.
I have 10,3,181,34 installed. I haven’t tried it with newer versions of the flash player.
So my workaround was correct. Use removeEventListener.
If you try it without robotlegs, you’ll see that the behaviour is different depending on where you place addChild(new Player()).
If you place it in Home’s constructor the ADDED_TO_STAGE fires once. If you place it in Home’s onAddedToStage ADDED_TO_STAGE will fire twice.
With robotlegs, placing the addChild() in the onRegister() is the same as having it in Home.onaddedToStage().
Would it be an acceptable solution for you to use Event.ADDED instead of Event.ADDED_TO_STAGE?
Ondina
Ondina D.F. closed this discussion on 02 Nov, 2011 03:42 PM.