0 Replies Latest reply on Oct 27, 2009 7:27 PM by !_emily

    Invisible ViewStack Items + Binding Issues

    !_emily

      Here is a simplified version of my issue:

       

      I have an application with a ViewStack.

      I have an ArrayCollection (called pages) in which each item holds data for a corresponding item in the ViewStack.

      I have a variable (called currentPage) that points to the ArrayCollection item for the currently visible ViewStack item.

      Finally, in each ViewStack item, I use bindings to set the values of the UI component properties.

       

      Every ViewStack item has a title and this title is set by:

       

          <mx:Label id="pageTitle" text="{wseModel.currentPage.title}"/>

       

      This works just fine. I know that when the visible ViewStack items title reads Title A all of the invisible ViewStack items titles also read Title A (even if their corresponding ArrayCollection item title isn't Title A). That's okay though, because all of the ViewStack items have a Label whose text is set to {wseModel.currentPage.title} and I don't care if the invisible ViewStack items show the wrong title while they're invisible.

       

      I run into problems in places where  the ViewStack items data/components don't match up so well, however. For example, each page has multiple states. But, pages have different numbers of states and different names for their states. Each ArrayCollection item has a format property which holds the value of that pages state. So when I use something like:

       

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:v="views.*" xmlns:comp="components.*"
           currentState="{wseModel.currentPage.format}">

       

      if wseModel.currentPage.format is equal to format1 and an invisible page in the ViewStack doesn't have a format1, I receive the error "ArgumentError: Undefined state 'format1'....."

       

      I resolved this problem with the following:

       

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:v="views.*" xmlns:comp="components.*"
          currentState="{this.visible ? wseModel.currentPage.format : ' '}">

       

      Even though this works, I know it's a big hack. And, like I said, this is the simplest of this type of error that I encounter. In other places, I've had to go so far as to do things like, if (this.parent.visible) { ...

       

      Does anyone know how I can go about maintaining my bindings while not running into problems with invisible ViewStack items? Or, do I need to do something like remove my bindings and set values in a show handler on my ViewStack items.

       

      Thanks in advance for any help!