4 Replies Latest reply on Jul 7, 2011 7:58 AM by theranchboy

    View reuse and the <mx:Viewstack> component

    theranchboy

      Hi guys

       

      I'm new to Flex and I've got a problem I can't get rid of.

       

      In my Flex app, I've got several workflows and 2 of them start with the same screen.

       

      The first screens of each worklows are placed in a ViewStack component (because only one workflow must be visible at a time).

       

      As a nice developper, I tried to avoid duplication of code and so, the 2 similar mxml files reference the same custom view component. They also share a part of the controller.

       

      Everything seems great but at runtime, I notice the 2 controllers are executed at the same time (for example popup messages are displayed twice, etc...). Yet, the views are not supposed to share instances...

       

      I thought it could be related to the lifecycle of components (creation, destruction, etc ...) and the creationPolicy but I didn't find a solution for this. Components seem to be "managed" by Flex. Of course, only one view/controller should be active at a time.

       


      Here's my main view "MainView.mxml" :

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

           (...)

           <mx:ViewStack creationPolicy="all">
                (...)
                <view3:View1 backgroundAlpha="0" id="myFirstView" borderStyle="none" width="100%" height="100%" creationComplete="initializationComplete()" hideEffect="{myWL}" showEffect="{myWR}"/>
                <view3:View2 backgroundAlpha="0" id="mySecondView" borderStyle="none" width="980" height="100%" creationComplete="initializationComplete()" hideEffect="{myWL}" showEffect="{myWR}"/>
           </mx:ViewStack>

           (...)

      </mx:Application>


      My first view "View1.mxml" :

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="980" backgroundColor="#FFCC33">
          <mx:Script>
          <![CDATA[
              include "CommonController.as";
              (...)
          ]]>
         </mx:Script>

         <myDomain:MyCustomComponent id="myCustomComponent"/>
      </mx:Canvas>

       

      My second view "View2.mxml" :

       

          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="980" backgroundColor="#FFCC33">
             <mx:Script>
              <![CDATA[
                  include "CommonController.as";
                  (...)
              ]]>
              </mx:Script>

             <myDomain:MyCustomComponent id="myCustomComponent"/>
          </mx:Canvas>

       

       

      I hope I'm clear enough.

       

      Thanks for reading me.