0

SelectComponent.mxmlファイルからコンボボックスから値を読み取るコードがあり、コンポーネントはSelectComponetのオブジェクトを作成することによってMain.mxmlファイルで読み取られています-Main.mxmlのコードを確認してください私は最初の出力のみを取得していますSelectComponent.mxml の Combobox の値で、そのコンボボックスからどの値を選択しても、最初の値のみに対応する出力が得られます。その値のみに対応する参照を取得する方法を教えてください。

this file is Main.mxml
**<?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:views="Views.*"
           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>
<fx:Script>

    <![CDATA[




        import Model.SampleModel;

        import Views.SelectComponet;

        import flash.utils.getDefinitionByName;

        import mx.controls.*;
        import mx.core.Repeater;
        import mx.core.UIComponent;

         var mode:SampleModel = SampleModel.getInstace();   
         var model = ["Paritosh","Akhil","Chirag","Suresh"];
        private function generateComponent(e:MouseEvent):void{


         var selectedItemObject:SelectComponet = new SelectComponet();

         var name1:String  = selectedItemObject.comb.selectedItem.toString();
         mx.controls.Alert.show(name1);
         var val:String = "mx.controls."+name1;
         var cls:Class = getDefinitionByName(val) as Class;
         var instance:UIComponent = new cls(); 
         mode.selectedComponent = instance.className;

        if (instance) {
            switch (instance.className) {
                 case "ComboBox":
                     ComboBox(instance).dataProvider = model;
                     v2.removeAllChildren();
                     v2.addChild(instance);

                      break;
                 case "CheckBox":
                      v2.removeAllChildren();

                     for(var i:int=0;i<model.length;i++){
                    var instance:UIComponent = new cls();
                    CheckBox(instance).label = model[i];
                     v2.addChild(CheckBox(instance));  
                     }
                     break;
                 case "List":
                     List(instance).dataProvider = model;
                     v2.removeAllChildren();
                     v2.addChild(instance);
                     break;
                 case "DataGrid":
                     DataGrid(instance).dataProvider = model;
                     v2.removeAllChildren();
                     v2.addChild(instance);
                     break;
             }


         }
        }
    ]]>
</fx:Script>
<mx:ApplicationControlBar width="946" height="44">
    <mx:Label text="Dynamic Component Generation"/>

</mx:ApplicationControlBar>


<mx:HDividedBox x="10" y="52" width="935" height="409">
    <mx:VBox id="v1" width="350" height="447" horizontalScrollPolicy="on"
             verticalScrollPolicy="off">
        <mx:Label text="Select Output Format"/>
        <views:SelectComponet id = "comb2"/>
        <mx:ComboBox id="comb1">

            <mx:dataProvider>
                <fx:String>CheckBox</fx:String>
                <fx:String>ComboBox</fx:String>
                <fx:String>List</fx:String>
                <fx:String>DataGrid</fx:String>
            </mx:dataProvider>
        </mx:ComboBox>



    <mx:Button id="butt" label="Get Output"      click="generateComponent(event)"/> 

    </mx:VBox>
    <mx:VBox id="v2" width="350" height="447" horizontalScrollPolicy="on"
             verticalScrollPolicy="off">

    </mx:VBox>
</mx:HDividedBox>

  </s:Application>**

     and this is SelectComponent.mxml

  **<?xml version="1.0" encoding="utf-8"?>
  <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->



  </fx:Declarations>
  <fx:Script>
    <![CDATA[
          import Model.SampleModel;
          private var model:SampleModel = SampleModel.getInstace();

    ]]>
    <mx:ComboBox id="comb">

  <mx:dataProvider>
      <fx:String>ComboBox</fx:String>
      <fx:String>CheckBox</fx:String>
      <fx:String>List</fx:String>
      <fx:String>DataGrid</fx:String>
  </mx:dataProvider>
  </mx:ComboBox>

  </s:Group>**
4

1 に答える 1

0

問題はここにあるようです:

     var selectedItemObject:SelectComponet = new SelectComponet();

     var name1:String  = selectedItemObject.comb.selectedItem.toString();

アクチュエルコンポボックスからではなく、関数で作成された別の非表示のコンポボックスから値を取得しています

「selectedItemObject.comb.selectedItem」の代わりに「comb2.comb.selectedItem」を使用する必要があります

良い1日を !

于 2012-07-06T12:53:44.210 に答える