2 Replies Latest reply on Oct 24, 2009 4:53 AM by workedout

    Repeater + ViewStack

    workedout

      Hey there-  Question for you.  I have a repeater that creates 3 buttons.  I want each Button to display a particular ViewStack item.  However, i receive an error when I try the code below, and I'm not sure why... any help is appreciated!  Thanks.

       

      Error in question:

      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.


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

         <mx:ArrayCollection id="dP">
              <mx:Container name="item1"/>
              <mx:Container name="item2"/>
              <mx:Container name="item3"/>
          </mx:ArrayCollection>
          <mx:Script>
              <![CDATA[
                  import mx.core.Container;           
                  import mx.controls.Button;

                  import flash.events.MouseEvent;

       

                  private function updateViewStack(pageName:Container):void {

                      myViewStack.selectedChild = pageName as Container;

                  }
              ]]>
          </mx:Script>

       

          <mx:Panel>

       

       

              <mx:Tile direction="horizontal" borderThickness="1" borderColor="#999999" borderStyle="solid">  
                  <mx:Repeater id="rP" dataProvider="{dP}">
                      <mx:Button id="btnArray" height="50" width="50"
                          label="{rP.currentItem.name}"
                          click="updateViewStack(event.currentTarget.getRepeaterItem())"
                          data="{rP.currentItem}"/>
                  </mx:Repeater>   
              </mx:Tile>

       

              <mx:ViewStack id="vS">

                  <mx:Canvas id="item1" label="Item 1">
                      <mx:Label text="item1" />
                  </mx:Canvas>

       

                  <mx:Canvas id="item2" label="Item 2">
                      <mx:Label text="item2" />
                  </mx:Canvas>

       

                  <mx:Canvas id="item3" label="Item 3">
                      <mx:Label text="item2" />
                  </mx:Canvas>

              </mx:ViewStack>
       
          </mx:Panel>
      </mx:Application>

        • 1. Re: Repeater + ViewStack
          paul.williams Level 4

          You have declared three Canvas containers as children of your ViewStack and you are creating three separate instances of Container in your ArrayCollection. In your click handler you are trying to set the selectedChild of your ViewStack to one of the Containers from your ArrayCollection. Since these Containers are not children of your ViewStack I would expect some kind of error at this point.

           

          To make this approach work your Repeater dataProvider needs to contain the actual children of your ViewStack. A quick way to do this is with the following line:

           

          <mx:Repeater id="rP" dataProvider="{ [ item1, item2, item3 ] }">

          • 2. Re: Repeater + ViewStack
            workedout Level 1

            Thanks!  Quick follow up question... how would i do this using an external source like an xml file?  Thanks again!