0 Replies Latest reply on Aug 18, 2010 12:53 AM by Abhin S

    to add custom container in actionscript

    Abhin S

      i have written a code in which i am finding difficulty in getting child in vertically..by pressing add new button

       

      clck New Filter class and den add new...

      please check the code..:-

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

      xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:mx="library://ns.adobe.com/flex/mx"

          xmlns:s="library://ns.adobe.com/flex/spark"

          >

       

        <mx:states >

          <mx:State name="si"/>

          <mx:State name="re"/>

          <mx:State name="de"/>

         

        </mx:states>

       

        <fx:Script>

          <![CDATA[

            import mx.controls.Alert; 

            import mx.core.Container;

             public function createNewTextInput(event:MouseEvent):void {

       

            

              var myTextInput:TextInput = new TextInput();

               myTextInput.width=50;

              var myTextInput1:TextInput = new TextInput();

               myTextInput1.width=122;

              myHBox.addChild(myTextInput);

              myHBox.addChild(myTextInput1);   

       

       

              }       

            public function myLabelFunc(item:Object):String

            {

                   return item.firstName + " " + item.lastName;

            }

            public function myLabel1Func(item:Object):String

            {

                   return item.firstName ;

            }

       

              ]]>

        </fx:Script>

       

       

      <mx:VBox

      id="VBox1"

      top="10" 

      >

         

         <mx:HBox

          id="HBox1"

          horizontalAlign="center">

            

      <mx:ComboBox

      id="ComboBox1"

                  includeIn="si"

                  labelFunction="myLabelFunc"

                  labelField="name"

      prompt="Subject"

      width="180" height="20">

                 <mx:dataProvider>

                 <mx:ArrayCollection>

                  <fx:Object firstName="Abhinav" lastName="Somal"/>

                  <fx:Object firstName="Adit" lastName="Kumar"/>

                  </mx:ArrayCollection>

                </mx:dataProvider> 

              </mx:ComboBox>

       

              <s:TextInput

              id="textinput1"           

                  includeIn="re"

                  width="180" height="20"/>

       

              <mx:LinkButton

                  id="linkbutton1"

              label="New Template"

                      click="currentState = 're'"

                      includeIn="si"/>

       

              <mx:LinkButton

              id="linkbutton2"

              label="Clear"

              includeIn="si"/>

                 

             </mx:HBox>

       

             <mx:HBox

               id="HBox2"

               horizontalAlign="center">

       

              <mx:ComboBox

              id="ComboBox2"

              includeIn="si"

              labelFunction="myLabel1Func"

              labelField="name"

      prompt="Filter Class"

                  width="180" height="20">       

                  <mx:dataProvider >

                  <mx:ArrayCollection>

                  <fx:Object  />

                  <fx:Object firstName="B" />

                  </mx:ArrayCollection>

                  </mx:dataProvider>

       

              </mx:ComboBox>

                 

             

              <mx:LinkButton

              id="linkbutton3"

              label="New Filter Class"

              includeIn="si"

              click="currentState = 'de'" />

             

             </mx:HBox>

             <mx:HBox

              id="HBox3"

              horizontalAlign="center">

       

              <s:TextArea

              id="textarea"

              excludeFrom="de"

              text="The selected item is: {ComboBox1.selectedItem.firstName + ' '

              + ComboBox1.selectedItem.lastName};"/> 

       

      <mx:Button

      id="Button1"

      label="Check Message"

      includeIn="si"

      click="Alert.show('Check Message Button is pressed','Alert Box',Alert.OK)" />

       

             </mx:HBox>

       

             <s:TextInput

             id="textinput2"           

                      excludeFrom="re,si"

                  width="180" height="20"/>

             <mx:HBox

                id="HBox4"

                horizontalAlign="center">

             <s:TextInput

             id="textinput3"

             excludeFrom="re,si"

             width="50" height="20"/>

            

             <s:TextInput

             id="textinput4"

             excludeFrom="re,si"

             width="122" height="20"/>

            

             <mx:LinkButton

             id="linkbutton4"

             label="Add New"

             excludeFrom="re,si"

             click="createNewTextInput(event)"/>

            

             </mx:HBox>    

       

             <mx:HBox

                     id="myHBox"

                     horizontalAlign="center"

                     excludeFrom="si,re"/>

         

         <mx:HBox

      id="HBox5"

      horizontalAlign="center">

       

      <mx:Button

      excludeFrom="de"

      id="Button2"

      label="SEND" 

      click="Alert.show('Send Button is pressed','Alert Box',Alert.OK)"/>

       

      <mx:Button

      id="Button3"

      label="Create"

      includeIn="de"

      click="Alert.show('Create Button is pressed','Alert Box',Alert.OK)"/>

       

      <mx:Button

      id="Button4"

      label="Cancel"

      click="currentState = 'si' ;

      Alert.show('Cancel Button is pressed','Alert Box',Alert.OK) "  />

       

         </mx:HBox>

       

      </mx:VBox>

       

      </mx:Application>

       

       

       

      thnkx