2009-05-21 7 views

Répondre

3

Voici une petite application de démonstration qui démontre ce que vous essayez de faire:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> 

    <mx:Script> 
     <![CDATA[ 
      import mx.core.Container; 

      private function onComboBoxChange():void 
      { 
       stackNav.selectedChild = this[comboNav.selectedItem]; 
      }    

     ]]> 
    </mx:Script> 

    <mx:ComboBox id="comboNav" dataProvider="{['canvas1','canvas2']}" change="onComboBoxChange()"/> 

    <mx:ViewStack id="stackNav" width="400" height="300"> 
     <mx:Canvas id="canvas1" width="100%" height="100%"> 
      <mx:Label text="Hello" horizontalCenter="0" verticalCenter="0"/> 
     </mx:Canvas> 
     <mx:Canvas id="canvas2" width="100%" height="100%"> 
      <mx:Label text="World!" horizontalCenter="0" verticalCenter="0"/> 
     </mx:Canvas> 
    </mx:ViewStack> 

</mx:Application> 

Vous pouvez changer la logique onComboBoxChange() à utiliser selectedIndex ainsi:

stackNav.selectedIndex = comboNav.selectedIndex; 
0

Ou vous pouvez lier l'élément selectedIndex de la propriété viewStack à la propriété selectedIndex de la combinaison:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> 
    <mx:ComboBox id="comboNav" dataProvider="{['canvas1','canvas2']}"/> 

    <mx:ViewStack id="stackNav" width="400" height="300" 
     selectedIndex="{comboNav.selectedIndex}"> 
     <mx:Canvas id="canvas1" width="100%" height="100%"> 
      <mx:Label text="Hello" horizontalCenter="0" verticalCenter="0"/> 
     </mx:Canvas> 
     <mx:Canvas id="canvas2" width="100%" height="100%"> 
      <mx:Label text="World!" horizontalCenter="0" verticalCenter="0"/> 
     </mx:Canvas> 
    </mx:ViewStack> 

</mx:Application> 
0

Vous pouvez utiliser cette solution, mais soyez averti que vous ne pouvez pas pike un mot avec l'espace (essayer de changer « canvas1 » à « toile 1 ») et vous verrez:

[Bindable] private var models:Array = ["tasks","users","bugs"]; 
public function changeViewStackModel():void { 
    //this.modelViewStack.selectedChild=users; //works 
//this.modelViewStack.selectedChild="users"; //does not work 
//this.modelViewStack.selectedChild=this.modelsCombo.selectedItem; //does not work 

    switch(modelsCombo.selectedItem) { 
    case "tasks": modelViewStack.selectedChild=tasks; break; 
    case "users": modelViewStack.selectedChild=users; break; 
    case "bugs": modelViewStack.selectedChild=bugs; break; 
    } 

} 

Code MXML:

<mx:ComboBox id="modelsCombo" dataProvider="{models}" selectedIndex="0" 
    change="changeViewStackModel()"/> 
    <mx:ViewStack x="29.25" y="55" id="modelViewStack" width="90%" height="200"> 
     <mx:Canvas id="tasks" label="Tasks"><mx:Label text="Tasks stack view!!"/> 
     </mx:Canvas> 
     <mx:Canvas id="users" label="Users"><mx:Label text="Users stack view!!"/> 
     </mx:Canvas> 
     <mx:Canvas id="bugs" label="Bugs"><mx:Label text="Bugs stack view!!"/> 
     </mx:Canvas> 
    </mx:ViewStack>