2 Replies Latest reply on Aug 3, 2010 11:47 PM by mrspok

    combobox selected

    mrspok

      Hi

      im new to flex so please show me mercy:)))

      i cant make my combobox to select first item on application start with data from php class....

      when  items are writed in action script and markup everything works fine but when im getting data from php class i cant select first item at start

      only after i click on combo and then from some action like button click or something it works

      but not at start

      I get data from php class-> remake of adobe example of php class to retreive data

      please help

      <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" xmlns:employeeservice="services.employeeservice.*">
          <fx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.events.FlexEvent;
                 
                  protected function comboBox_creationCompleteHandler(event:FlexEvent):void
                  {
                      dajListeKonkurencjiResult.token = employeeService.dajListeKonkurencji();
                      comboBox.selectedIndex = 0;
                  }
                 
              ]]>
          </fx:Script>
          <fx:Declarations>
              <s:CallResponder id="dajListeKonkurencjiResult"/>
              <employeeservice:EmployeeService id="employeeService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <s:ComboBox x="125" y="101" id="comboBox" creationComplete="comboBox_creationCompleteHandler(event)" labelField="nazwa">
              <s:AsyncListView list="{dajListeKonkurencjiResult.lastResult}"/>
          </s:ComboBox>
      </s:Application>

       

       

       

      public function dajListeKonkurencji() {
           $stmt = mysqli_prepare($this->connection,
                "SELECT
                  id,
                  nazwa,
                  id_kategori
                 FROM
                  konkurencja
                 ORDER by
                  nazwa");
            $this->throwExceptionOnError();

            mysqli_stmt_execute($stmt);
            $this->throwExceptionOnError();

            $rows = array();
            mysqli_stmt_bind_result($stmt, $row->id, $row->nazwa,$row->id_kategori);

            while (mysqli_stmt_fetch($stmt)) {
                $rows&#91;] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt, $row->id, $row->nazwa,$row->id_kategori);
            }

            mysqli_stmt_free_result($stmt);
            mysqli_close($this->connection);

            return $rows;
        }

        • 1. Re: combobox selected
          jeffcg2 Level 1

          Try adding a result event to your CallResponer and moving the selecting of the index to there.

           

          <s:CallResponder id="dajListeKonkurencjiResult" result="dajListeKonkurencjiResult_resultHandler(event)" />

           

           

          protected function dajListeKonkurencjiResult_resultHandler(event:ResultEvent):void
                      {
                          this.comboBox.selectedIndex=0;
                      }

          • 2. Re: combobox selected
            mrspok Level 1

            Thanks ))))

            works great:)))