tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/309-onremove-not-called-for-timeline-objects-in-flash-player-9Robotlegs: Discussion 2013-04-28T09:55:57Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T12:43:37Z2011-05-06T12:43:37ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Nick,</p>
<p>this is a bug in early versions of FP 9. The stage doesn't send
the Event.REMOVED_FROM_STAGE event unfortunately. (In very early
versions the REMOVED_FROM_STAGE event type doesn't even exist).</p>
<p>You've got a couple of options, one of which is to manually
dispatch the Event.REMOVED_FROM_STAGE event on behalf of the
object.</p>
<p>You can do this either by relaying (listening for Event.REMOVED,
cloning the event, changing the type to REMOVED_FROM_STAGE and then
redispatching) at a high level, or by dispatching it manually
within your views themselves.</p>
<p>There's a discussion here that covers some of the issues (you
won't have all of them):</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/74-fp-9016">http://knowledge.robotlegs.org/discussions/problems/74-fp-9016</a></p>
<p>Feel free to come back with more specific questions... which
approach you need to take will depend a lot on your code base (Eg
whether these views all share a base type that you can edit).</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T13:17:12Z2011-05-06T13:17:13ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Stray,</p>
<p>Thanks so much for your prompt reply.</p>
<p>I'm not sure that's the cause of the problem. The onRemove is
failing to be triggered when just testing using the test player
straight from Flash CS5.</p>
<p>I've put in handlers with traces for ADDED_TO_STAGE and
REMOVED_FROM_STAGE which show that these events are being fired for
the mediated object.</p>
<p>Attached is the updated source with these handlers.</p>
<p>I actually initially detected the problem because onRemoves
weren't being triggered when running my project in a browser with
Flash Player 10.</p>
<p>Bit of a mystery...</p>
<p>Many thanks,</p>
<p>Nick</p></div>Nicktag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T13:44:23Z2011-05-06T13:44:23ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Nick - ok, so for the purposes of narrowing down...</p>
<p>Can I just confirm that what you're saying is that your
contextView <em>is</em> firing the Event.REMOVED_FROM_STAGE event,
but that for some reason the mediatorMap isn't responding to this
event?</p>
<p>I thought you said "Switching the Flash to target FP 10 causes
the the onRemove to be successfully triggered." - but you're now
saying that FP 10 is experiencing the problem as well?</p>
<p>A simple but possibly not viable for you solution - could you
use addChild/removeChild in the frame code to add and remove the
instances?</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T14:15:37Z2011-05-06T14:15:38ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Stray,</p>
<p>Sorry, I wasn't clear.</p>
<p>Publishing to target Flash Player 9, but running in Flash Player
9 or 10, causes onRemoves not to be fired.</p>
<p>If you modify the Flash to target Flash Player 10, onRemove
seems then to be triggered successfully.</p>
<p>Also my example test file wasn't correctly testing the problem.
I now monitor ADDs and REMOVEs in the context view (attached).
You'll see that both handlers get fired when adding and removing
the mediated sprite, but that the sprite mediator's onRemove fails
to trigger whenever the Flash is published to target player 9.</p>
<p>I presume RL is listening for ADDs and REMOVEs on the context
view as opposed to ADDED_TO_STAGEs and REMOVED_FROM_STAGEs as only
the former get bubbled. Have I got that right - might be that I'm
not understanding how RL is doing its monitoring of display object
additions and removals.</p>
<p>Many thanks for your help,</p>
<p>Nick</p></div>Nicktag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T14:27:10Z2011-05-06T14:27:10ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Nick, no problem.</p>
<p>The mediatorMap listens for ADDED_TO_STAGE and
REMOVED_FROM_STAGE on the contextView.</p>
<p>As you rightly identify - this event doesn't bubble. Robotlegs
doesn't rely on Event bubbling at all. The ADDED_TO_STAGE /
REMOVED_FROM_STAGE events are dispatched by an object when
something is added TO it, or removed FROM it (including the whole
nested stack).</p>
<p>You can look at mediatorMap internals here:</p>
<p><a href=
"https://github.com/Stray/robotlegs-framework/blob/master/src/org/robotlegs/base/MediatorMap.as">
https://github.com/Stray/robotlegs-framework/blob/master/src/org/ro...</a></p>
<p>My understanding is that FP 9 is flaky about when / how it fires
those REMOVED_FROM_STAGE events. It is most flaky in the early
version, where these events don't even exist, but it's flaky in all
FP 9 versions.</p>
<p>There are 2 places where it could be flaking out in your
scenario:</p>
<p>1) Using the timeline to add / remove instances might not be
triggering the events on the container views (contextView is the
only one we care about!)</p>
<p>2) As you move back and forth through the timeline you get some
interesting stuff going on in terms of which instances are the
'same' instance (===) and which are a new instance (==) of the same
class.</p>
<p>So - no point monitoring ADD / REMOVE - it's ADDED_TO_STAGE and
REMOVED_FROM_STAGE that we're interested in, and only as fired by
the contextView.</p>
<p>Hopefully that helps with a bit more digging...</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-06T14:58:52Z2011-05-06T14:58:52ZonRemove not called for timeline objects in Flash Player 9<div><p>Hi Stray,</p>
<p>Thanks for this info.</p>
<p>Okay, I think it's most likely due to what you say with the
ropiness in which FP9 is handling ADDED_TO_STAGE and
REMOVED_FROM_STAGE.</p>
<p>In this case, what I think I'll do (since my clean up code can
happily be executed multiple times without ill-effect), is manually
force a call to onRemove. I found a quite elegant single line using
Signals that can be simply placed into the onRegister handler of
mediators:</p>
<pre>
<code> new NativeSignal(this.view, Event.REMOVED_FROM_STAGE, Event).
addOnce(function(e:Event):void { onRemove(); });</code>
</pre>
<p>since REMOVED_FROM_STAGE seems to be fired correctly in FP9 and
FP10 when used immediately on the view like this.</p>
<p>Thank you for all your help.</p>
<p>Nick</p></div>Nicktag:robotlegs.tenderapp.com,2009-10-18:Comment/70351442011-05-09T13:34:58Z2011-05-09T13:34:58ZonRemove not called for timeline objects in Flash Player 9<div><p>Nice solution!</p>
<p>No problem - I'll close this now, but feel free to reopen it if
you hit any problems.</p>
<p>Stray</p></div>Stray