0 Replies Latest reply on Aug 6, 2010 1:59 AM by Abhin S

    to implement two functions from a link button

    Abhin S

      i have created a script:

       

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

      <s:Application minWidth="955" minHeight="600"

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

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

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

          initialize="createListener()">

       

      <fx:Declarations>

      </fx:Declarations>

       

      <fx:Script>

          <![CDATA[

              import spark.events.IndexChangeEvent;

              // Define a custom function for the labelFunction property

              // to display an Object in the DDL control.

              public function myLabelFunc(item:Object):String {

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

              }

              // Define a custom function for the labelToItemFunction property

              // to convert the new value to an Object of the correct format

              // for storage in the data provider of the control.

              public function myLabelToItemFunc(value:String):Object {

                   var tempObj:Object = new Object();

                   var spaceChar:int = value.indexOf(' ');

                   tempObj.firstName = value.substr(0, spaceChar);

                   tempObj.lastName = value.substr(spaceChar+1, value.length);

                   return tempObj;

                  }

                   // Event handler to determine if the selected item is new.

                  protected function myCB_changeHandler(event:IndexChangeEvent):void

                  {

                       // Determine if the index specifies a new data item.

                       if(myCB.selectedIndex == spark.components.ComboBox.CUSTOM_SELECTED_ITEM)

                           // Add the new item to the data provider.

                           myCB.dataProvider.addItem(myCB.selectedItem);

                  }

       

       

              import spark.components.ComboBox;

             private function setLabel():void {

                  if (l2.label=="Show ComboBox") {

                      l2.label = "Show TextBox";

       

                                     } else {               

                      l2.label = "Show ComboBox";

       

                  }

                }

                private function createListener():void {

                      l2.addEventListener(MouseEvent.CLICK,showCustomBox);               

                  }

                import mx.controls.Alert;

                private function showCustomBox(e:MouseEvent):void{

                t2.text += " listener." + "\n";

                Alert.show("An event occurred.");

       

                }

       

       

              }

       

          ]]>

      </fx:Script>

       

       

          <s:states >

          <s:State name="Immediate"/>

          <s:State name="Deferred"/>

          </s:states>

       

      <s:BorderContainer borderColor="#0b85b7"

          cornerRadius="8"

          borderWeight="4">

      <s:VGroup top="10" horizontalAlign="center" >

      <s:ComboBox id="myCB"

                  includeIn="Immediate"

                  itemCreationPolicy="immediate"

       

                  labelFunction="myLabelFunc"

      labelToItemFunction="myLabelToItemFunc"

      change="myCB_changeHandler(event);">

                 <s:dataProvider>

                 <mx:ArrayCollection>

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

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

                  </mx:ArrayCollection>

                </s:dataProvider> 

              </s:ComboBox>

       

       

              <s:TextInput id="t1"

       

                  includeIn="Deferred"           

                  itemCreationPolicy="deferred"/>

       

       

       

              <mx:LinkButton id="l2" label="Show TextBox"

                click="currentState='Deferred';setLabel();"/>

       

              <s:TextArea id="t2"

             

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

              + myCB.selectedItem.lastName};

              {l2.label};

              {b1.label};

             

              "/> 

       

      <mx:Button id="b1" label="SEND"  >

      </mx:Button>

       

       

            

        

      </s:VGroup>

      </s:BorderContainer>   

      </s:Application>

       

       

      in this i changed the link label,but i am not able to get back the dropdown list ..

      kindly help..