2011-11-05 4 views
0

나는 Spark ButtonBar를 가지고 있는데, ViewStack으로 올바르게 연결 시켰습니다. 현재 응용 프로그램 (AIR)을 실행하면 기본적으로 ButtonBar의 첫 번째 버튼이 선택됩니다. 두 번째 단추를 기본적으로 선택되게하려면 어떻게합니까?기본적으로 선택된 ButtonBar에서 버튼을 만드는 방법은 무엇입니까?

<mx:ViewStack id="viewStack"> 
    <s:NavigatorContent id="Page 1"> 
     <!-- Other stuff in here --> 
    </s:NavigatorContent> 
    <s:NavigatorContent id="Page 2"> 
     <!-- Other stuff in here --> 
    </s:NavigatorContent> 
</mx:ViewStack> 

<s:ButtonBar dataProvider="{viewStack}" selectedIndex="1"></s:ButtonBar> 
+0

이전에는 사용하지 않았지만 버튼 막대에 selectedIndex가 있습니까? 플렉스 빌더 3을 사용하여 프레임 워크 3.0에서 잘 기억한다면 그랬습니다. –

+0

시도했지만 ButtonBar의 첫 번째 버튼은 선택한 인덱스에 대한 값과 상관없이 선택되지 않았습니다. 기묘한! – Titus

+0

hehe, 그것을 위해 데이터 공급자를 할당 한 후 넣을 지, 아니면 creationcomplete 이벤트에서 그냥 기술 문제를 피하기 위해 넣으십시오. 버튼을 클릭하고 myButtonBar.selectedIndex = 1과 같은 순간에 selectedIndex를 변경하려고 시도한 적이 있습니까? ; 작동하는 경우 .. selectedIndex가 전달되고 있다는 것입니다. 데이터 공급자가 할당되기 전에 .. 다음에 dataproviderChanged 이벤트가 있으면 할당하지 않아도됩니다. –

답변

1

나는 잘 했는가. selectedIndex가 작동하지 않습니까?

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <s:ButtonBar 
     selectedIndex="2" width="400" height="300"> 
     <s:dataProvider> 
      <s:ArrayCollection> 
       <fx:String>1</fx:String> 
       <fx:String>2</fx:String> 
       <fx:String>3</fx:String> 
      </s:ArrayCollection> 
     </s:dataProvider> 

    </s:ButtonBar> 

</s:Application> 

편집 :

이 당신을하는 데 도움이?

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 
      import mx.events.CollectionEvent; 
      [Bindable] 
      private var dataSource:ArrayCollection = new ArrayCollection(); 

      private function init():void 
      { 

       dataSource = new ArrayCollection(new Array("1","2","3")); 
       dataSource.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionEventChange); 
       dataSource.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE)); 

      } 

      private function collectionEventChange(event:CollectionEvent):void 
      { 
       this.btnBar.selectedIndex = 2; 
      } 
     ]]> 
    </fx:Script> 
    <s:ButtonBar id="btnBar" dataProvider="{dataSource}" 
     width="400" height="300" > 

    </s:ButtonBar> 

</s:Application> 
+0

답변 해 주셔서 감사합니다. ' = "0"bottom = "0"dataProvider = "{dataSource} selectedIndex ="1 ""/>'그러나'selectedIndex'는 여전히 작동하지 않는 것 같습니다. – Titus

+0

언제 데이터 소스를 asign합니까? –

+0

나는 그 안에''과''를 사용하고 있습니다. (이것을 반영하기 위해 질문을 업데이트했습니다.) 도움을 주셔서 다시 한번 감사드립니다! – Titus

0

당신은 버튼 줄이 채워지기 후 선택된 인덱스 구성 요소가 초기화 된 후 를 설정해야합니다. 버튼 바는 데이터 제공자의 변경을 감지했을 때만 버튼을 생성합니다 (바인딩 된 후 변경 표시기를 연결하여 단추를 생성합니다).

그래서 Mr.의 수정 된 답변에는 CollectionEvent 리스너 내에서 선택한 색인을 설정하는 것이 포함되어 있습니다.

더 강력한 솔루션은 버튼 모음을 서브 클래스 화하고 조정할 수 있습니다. defaultSelectedIndex 멤버를 추가하거나이 기능을 listbase의 모든 하위 클래스에 추가 할 수있는 mixin을 만듭니다. defaultSelectedIndex는 데이터 제공자가 변경 될 때 선택된 인덱스를 지정된 값으로 설정합니다.

관련 문제