Note that there are some explanatory texts on larger screens.

plurals
  1. POFlex 3 - Invalidation in show event handler breaks lifecycle
    primarykey
    data
    text
    <p>Just wondering if anyone has encountered this and has a good fix. </p> <p>Here is how to reproduce:</p> <p>Create a tab navigator (or viewstack, whatever) and add a couple tabs.</p> <p>On your tab add a show event handler. Inside the event handler call invalidateProperties() and invalidateDisplayList() on one of the children of your tab. Put a break point on the childs commitProperties() and updateDisplayList(). You'll notice that the updateDisplayList() gets called before commitProperties() which results in incorrect behaviour. </p> <p>I noticed this problem when setting a DataGrid's dataprovider from inside the show handler. Setting the dataProvider causes the grid to invalidate both properties and displayList, updateDisplayList() will get called first, then commitProperties() which will result in the grid not updating the rows. </p> <p>It appears the root of the problem is that the show event gets dispatched from within LayoutManagers validateDisplayList() loop, so invalidating a child object from within the show handler results in its updateDisplayList() getting called immediately. </p> <p>I'm aware that I can use callLater() inside the show handler or several other hacky solutions but I would prefer to fix the root of the problem as I dont want to be finding / fixing this issue every time someone uses the show event and bad things happen. </p> <p>I'm considering changing UIComponent.setVisible() which dispatches the show event and using callLater() on the dispatchEvent() so the show event wont get dispatched mid validation cycle unless anyone has a better idea.</p> <pre><code>&lt;mx:Script&gt; &lt;![CDATA[ import mx.controls.Label; private var tabLabel:Label; private function onCreationComplete():void { var ifactory:IFactory = TestLabel; tabLabel = Label(ifactory.newInstance()); tab1.addChild(tabLabel); } private function onTab1Show():void { tabLabel.invalidateProperties(); tabLabel.invalidateDisplayList(); } ]]&gt; &lt;/mx:Script&gt; &lt;mx:Component id="TestLabel"&gt; &lt;mx:Label text="Test"&gt; &lt;mx:Script&gt; &lt;![CDATA[ override protected function commitProperties():void { super.commitProperties(); } override protected function updateDisplayList(w:Number, h:Number):void { super.updateDisplayList(w, h); } ]]&gt; &lt;/mx:Script&gt; &lt;/mx:Label&gt; &lt;/mx:Component&gt; &lt;mx:TabNavigator height="200" width="200" creationComplete="onCreationComplete()"&gt; &lt;mx:Canvas id="tab1" height="100%" width="100%" label="Tab 1" show="onTab1Show()" /&gt; &lt;mx:Canvas height="100%" width="100%" label="Tab 2" /&gt; &lt;/mx:TabNavigator&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload