2011-02-03 9 views
0

私はその件名に複数のエントリを許可するデータ入力アプリケーションを設計しています。たとえば、複数の機関から教育を受けた可能性があります。各教育エントリはフォームであり、アプリユーザーはボタンをクリックして別のエントリを追加できます。これは空白ですが同一のフォームです。ダイナミックなフレックスフォームの複製

私はそれが状態とカスタムフォームのコンポーネントを含んでいるが、すべてがどのように適合しているかはわかりません。誰かがそれを達成する方法についていくつかの光を当てることができますか?いくつかのサンプルコードは非常に高く評価されます。

ありがとうございます。

答えて

0

要件がある場合、必要なフレックスバージョンですか?最新のFlex 4コードを使用していますか?一般的に言えば、これはFlexでの非常に簡単な作業です。AnEntry.mxmlのMXMLでクラス定義を作成します。これはTextInput(またはラベルとTextInputなど、各エントリに必要なもの)です。 Flex 3のボタンのクリックハンドラでthis.addChild(new AnEntry())またはFlex 4でthis.addElement(new AnEntry());を呼び出します。送信するには、0から開始してthis.numChildrenに行くループと、各TextInputのループをHTTPServiceのparamsとして渡します。フレックス3.4

[AnEntry.mxml]

<?xml version="1.0" encoding="utf-8"?> 
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml"> 
    <mx:Label text="Link:"/> 
    <mx:TextInput id="theTextInput"/> 
</mx:Box> 

[MainApplication.mxml]

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

    <mx:Script> 
     <![CDATA[ 
      import mx.rpc.http.HTTPService; 
      protected function button1_clickHandler(event:MouseEvent):void 
      { 
       var params:Object = {}; 
       var paramCount:Number=0; 
       // TODO Auto-generated method stub 
       for(var i:Number = 0; i<numChildren; i++) 
       { 
        var currentChild:DisplayObject = getChildAt(i); 
        if(currentChild is AnEntry) 
        { 
         params[paramCount++] = (currentChild as AnEntry).theTextInput.text; 
        } 
       } 
       var httpService:HTTPService = new HTTPService(); 
       httpService.method = "POST" 
       httpService.url = "http://www.shaunhusain.com/somewhere.php"; 
       httpService.send(params); 
      } 
     ]]> 
    </mx:Script> 


    <mx:Button label="Add Entry" click="this.addChild(new AnEntry())"/> 
    <mx:Button label="Submit Info" click="button1_clickHandler(event)"/> 
</mx:Application> 

に対してコンパイル以下

2つのファイルが、これはあなたが行く取得する場合、私に知らせてください。 Flexの1週間の動画検索の初心者であれば、Flex開発を開始する上で参考になる素晴らしいチュートリアルです。 Flexの4のための

改正:

[MainApplication.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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <s:layout> 
     <s:VerticalLayout/> 
    </s:layout> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 
     import mx.rpc.http.HTTPService; 
     protected function button1_clickHandler(event:MouseEvent):void 
     { 
     var params:Object = {}; 
     var paramCount:Number=0; 
     // TODO Auto-generated method stub 
     for(var i:Number = 0; i<numChildren; i++) 
     { 
     var currentChild:DisplayObject = getChildAt(i); 
     if(currentChild is AnEntry) 
     { 
     params[paramCount++] = (currentChild as AnEntry).theTextInput.text; 
     } 
     } 
     var httpService:HTTPService = new HTTPService(); 
     httpService.method = "POST" 
     httpService.url = "http://www.shaunhusain.com/somewhere.php"; 
     httpService.send(params); 
     } 
     ]]> 
    </fx:Script> 


    <mx:Button label="Add Entry" click="this.addElement(new AnEntry())"/> 
    <mx:Button label="Submit Info" click="button1_clickHandler(event)"/> 

</s:Application> 

[AnEntry.mxml]

<?xml version="1.0" encoding="utf-8"?> 
<mx:Box xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <mx:Label text="Link:"/> 
    <mx:TextInput id="theTextInput"/> 
</mx:Box> 
+0

私は物事を複雑にされたと思います。とにかく、あなたのコードは間違いなく正しい方向に私を指摘しました。 Sparkを反映させるために小さな変更を加えてFlex 4でコードを実行しましたが、期待通りにビジュアル要素をコンテナに追加していませんでした。何か不足していますか?知恵を共有してくれてありがとう。 – Jay

+0

Flex 4でも動作するはずですが、addChildをaddElementに変更するだけで済むと思います。 – shaunhusain

+0

Flex 4.0用にコンパイルされたバージョンを含めるように編集しましたが、まだ問題があるように見える場合はお知らせください。 – shaunhusain