2 Replies Latest reply on Jul 31, 2009 11:33 AM by BosDog

    view states for components

    BosDog Level 1

      Hi hoping someone could help. I understand view states and can use them. However in this situation I want to have a view state for a control bar but I already have 2 view states for another component (a panel component) in my Flex app and want to separate the control bar view state from the panel view state.

       

      Therefore when I set the currentState = 'showBtn' it's affecting the panel view state and I don't want it to. I've tried putting the <mx:states> tag in under the component i'm trying to add the button view state to but i'm getting an "Initializer for the property 'states' is not allowed here" error.

        • 1. Re: view states for components
          Gregory Lafrance Level 6

          I don't fully understand your situation.

           

          You should be able to have the control bar and panel be separate MXML components with their own view states, then just say:

           

          myPanel.currentState = "whatever";

           

          and

           

          myControlBar.currentState = "whatever";

          • 2. Re: view states for components
            BosDog Level 1

            i've tried that... when i start using the id of the component like myPanel.currentState = "whatever" it tells me the currentState whatever is undefined. it only seems to work if i do currenState = "whatever". here is some of my code to help you see my problem:

             

             

             

             

            <mx:Script>

            <![CDATA[

             

             

             

             

             

             

             

             

             

             

             

             

            private function toggleFilter():void

            {

             

             

            if (p1.currentState == 'viewRequests'

            ){

            p1.currentState =

             

            'searchFilter'

            ;

            filterButton.label =

             

            'Hide Filter'

            ;

            }

             

             

            else

            {

            p1.currentState =

             

            'viewRequests'

            ;

            filterButton.label =

             

            'Show Filter'

            ;

             

             

            }

             

             

             

             

             

             

             

            private function buttonBar():void

            {

             

             

            if

            (changeQueue.selectedItem.REQ_BY_ID == Application.application.parameters.emplid){

            queueControlBar.currentState =

             

            'showRecallBtn'

            ;

            }

             

             

            else

            {

            queueControlBar.currentState =

             

            ''

            ;

             

            ]]>

             

             

             

            </mx:Script>

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            <mx:states>

             

             

            <mx:State name="viewRequests"

            >

             

             

            <mx:AddChild relativeTo="{p1}" position="firstChild"

            >

             

             

            <mx:HBox id="resultBox" width="100%" height="100%"

            >

             

             

            <mx:DataGrid id="changeQueue" x="0" y="0" width="100%" height="100%" dataProvider="{SAMService.getRequests.lastResult}" change="buttonBar();"

            >

             

             

            <mx:columns>

             

             

            <mx:DataGridColumn headerText="Change ID" dataField="CHANGE_ID" visible="false"

            />

             

             

             

             

            <mx:DataGridColumn headerText="Change Type" dataField="CHANGE_TYPE"

            />

             

             

            <mx:DataGridColumn headerText="Status" dataField="STATUS"

            />

             

             

            <mx:DataGridColumn headerText="Request Date" dataField="REQ_DT" labelFunction="doDateLabel"

            />

             

             

            <mx:DataGridColumn headerText="Requested By ID" dataField="REQ_BY_ID" />

             

             

            </mx:columns>

             

             

            </mx:DataGrid>

             

             

            </mx:HBox>

             

             

            </mx:AddChild>

             

             

            </mx:State>

             

             

             

            <mx:State name="searchFilter"

            >

             

             

            <mx:AddChild relativeTo="{p1}" position="secondChild"

            >

             

             

            <SearchPanel id="searchPanel" width="100%" height="100%"

            />

             

             

            </mx:AddChild>

             

             

            </mx:State>

             

             

             

            <mx:State name="showRecallBtn"

            >

             

             

            <mx:AddChild relativeTo="{queueControlBar}" position="lastChild"

            >

             

             

            <mx:Button label="Recall Item" icon="@Embed(source='images/recall.gif')" enabled="{changeQueue.dataProvider.length > 0}"

            />

             

             

            </mx:AddChild>

             

             

            </mx:State>

             

             

            </mx:states>

             

             

            <mx:HBox x="0" y="360" width="95%" horizontalAlign="center" paddingLeft="25" paddingRight="25">

             

            <mx:Panel id="p1" width="100%" height="90%" layout="absolute" title="Change Request Queue" currentState="viewRequests">

             

            <mx:ControlBar>

             

            <mx:HBox id="queueControlBar" width="100%" horizontalAlign="center" currentState="">

             

            <mx:Button label="Details" icon="{detailsIcon}" enabled="{changeQueue.selectedIndex>-1}" click="WindowManager.add(getDetails(), this, true);"/>

             

            <mx:Button id="filterButton" label="Show Filter" icon="@Embed(source='images/search.png')" click="toggleFilter();"/>

             

            <mx:Button id="OICbutton" label="Export OIC Changes" icon="@Embed(source='images/export.png')" enabled="{changeQueue.dataProvider.length > 0}" click="oicChanges();"/>

             

            </mx:HBox>

             

            </mx:ControlBar>

             

            </mx:Panel>

             

            </mx:HBox>