5 Replies Latest reply on Sep 30, 2011 10:56 AM by whitefinger

    Displaying data after a event

    whitefinger

      Ok so i have a Main application which has many components and within the Main i have navigation buttons that when pressed calls a component depending on which navigation button was pressed Now all was going well for my first web site until now that i have decided to reuse components to save on web site size, so normally the user would click on me navigation button and it call the component which calls a function at start. and yes i know this function was called at creation complete but any way it shows the page with the data

       

       

      protected function dataGroup_creationCompleteHandler(event:FlexEvent):void
       {    
             startIndex = 0;
             getItems_pagedResult.token = customerService.getItems_paged(/*Enter value(s) for */ startIndex, numItems);
       }
      

      and the website would pull the data from the MySql database and all would be good.

       

      So then i decide that if the Component new which button was pressed it could call the correct procedure to the databse and then i could reuse the component

      and it all looks good as in Network Monitor i can see the correct information being pulled but the data is not being displayed to the screen, so i was wondering if someone coould look to see what im missing out? please

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Skin xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:d="http://ns.adobe.com/fxg/2008/dt"
              xmlns:graphics="assets.graphics.*"
              xmlns:customerservice="services.customerservice.*"
              width="526" height="736">
          <fx:Metadata>[HostComponent("spark.components.List")]</fx:Metadata>
          <fx:Script>
              <![CDATA[
                  import mx.core.mx_internal;
                  import mx.events.FlexEvent;
                  
                  import spark.components.Application;
                  
                  [Bindable]
                  public static var startIndex:int;
                  public static var numItems:int = 9;
                  
                  
                  public function CreateDatalist():void
                  {
                      startIndex = 0;
                      if ( Main.clientsData.clientCurrentState == "SearchThatclients" ) {
                          var firstinitialobj:Object = new Object;
                          firstinitialobj.fname = Main.clientsData.clientFname;
                          firstinitialobj.lname = Main.clientsData.clientLname;
                          firstinitialobj.country = Main.clientsData.clientCountry;
                          firstinitialobj.town = Main.clientsData.clientTown;
                          firstinitialobj.sex = Main.clientsData.clientSex;
                          getItems_pagedResult.token = customerService.searchClients(firstinitialobj);
                          trace("first one");
                      }
                      else if ( Main.clientsData.clientCurrentState == "Ratethatclient" ){
                          startIndex = 0;
                          getItems_pagedResult.token = customerService.getItems_paged(/*Enter value(s) for */ startIndex, numItems);
                          trace("Second one");
                      }
                      else {
                          
                          startIndex = 0;
                          getItems_pagedResult.token = customerService.getItems_paged(/*Enter value(s) for */ startIndex, numItems);
                          trace("third one"+currentState);
                      }
                      trace("This button is working :)");
                  }
                  
                  protected function dataGroup_creationCompleteHandler(event:FlexEvent):void
                  {
                      
                      
                  }
                  
                  protected function button_clickHandler(event:MouseEvent):void
                  {
                      var pageno:int=1;
                      var clientTotal:int = countResult.lastResult;
                      var clientTotoalPage:int = Math.ceil(clientTotal / numItems);
                      
                      if (pageno < clientTotoalPage)
                      {
                          pageno = pageno + 1;
                          startIndex = startIndex + 9;
                          getItems_pagedResult.token = customerService.getItems_paged(startIndex, numItems);
                      }
                      else if (startIndex  >= clientTotoalPage)
                      {
                          startIndex = 0;
                      }  
                      trace("Page Number " + pageno + "how many client " + clientTotal  + "How many pages there are " + clientTotoalPage + "Start index" + startIndex);
                  }
                  
                  protected function button2_clickHandler(event:MouseEvent):void
                  {
                      var pageno:int=1;
                      var clientTotal:int = countResult.lastResult;
                      var clientTotoalPage:int = Math.ceil(clientTotal / numItems);
                      
                      if (pageno < clientTotoalPage)
                      {
                          pageno = pageno + 1;
                          startIndex = startIndex + 9;
                          getItems_pagedResult.token = customerService.getItems_paged(startIndex, numItems);
                      }
                      else if (startIndex  >= clientTotoalPage)
                      {
                          startIndex = 0;
                      }  
                      
                  }
                  
                  protected function button1_clickHandler(event:MouseEvent):void
                  {    
                      if (startIndex  >= 9)
                      {
                          startIndex = startIndex - 9;
                          getItems_pagedResult.token = customerService.getItems_paged(startIndex, numItems);
                      }
                      else if (startIndex  <= 9)
                      {
                          startIndex = 0;
                      }
                  }
                  
                  protected function button3_clickHandler(event:MouseEvent):void
                  {    
                      if (startIndex  >= 9)
                      {
                          startIndex = startIndex - 9;
                          getItems_pagedResult.token = customerService.getItems_paged(startIndex, numItems);
                      }
                      else if (startIndex  <= 9)
                      {
                          startIndex = 0;
                      }
                  }
                  
                  protected function richText_creationCompleteHandler(event:FlexEvent):void
                  {
                      countResult.token = customerService.count();
                  }
                  
              ]]>
          </fx:Script>
          <s:states>
              <s:State name="normal"/>
              <s:State name="disabled"/>
          </s:states>
          <fx:Declarations>
              <s:CallResponder id="getItems_pagedResult" />
              <customerservice:CustomerService id="customerService" showBusyCursor="true"/>
              <s:CallResponder id="countResult"/>
          </fx:Declarations>
          
          <s:DataGroup id="dataGroup" d:userLabel="Repeated Item" x="0" y="0" width="128" height="549"
                       clipAndEnableScrolling="true"
                       creationComplete="dataGroup_creationCompleteHandler(event)"
                       dataProvider="{getItems_pagedResult.lastResult}"
                       itemRenderer="components.RateClientDataListSkin2RepeatedItemSkin"
                       x.normal="0" y.normal="81" width.normal="526" height.normal="718">
              <s:layout>
                  <s:VerticalLayout/>
              </s:layout>
              <s:layout.normal>
                  <s:TileLayout horizontalGap="65" verticalGap="86"/>
              </s:layout.normal>
          </s:DataGroup>
          <s:Button d:userLabel="ButtonSkinNextBottom" includeIn="normal" x="377" y="866" click="button2_clickHandler(event)"
                    skinClass="components.ButtonSkinNext"/>
          <s:Button d:userLabel="ButtonSkinBackBottom" includeIn="normal" x="0" y="866" click="button3_clickHandler(event)"
                    skinClass="components.ButtonSkinBack"/>
          <s:BitmapImage d:userLabel="TotalItemsbottom" includeIn="normal" x="192" y="869" smooth="true"
                         source="@Embed('/assets/images/clientnewest/TotalItems.png')">
              <s:mask>
                  <s:Group x="0" y="0">
                      <s:Path winding="evenOdd" data="M 9.95 0 L 141 0 C 146.5 0 150.95 4.45 150.95 9.95 L 150.95 33.95 C 150.95 39.5 146.5 43.95 141 43.95 L 9.95 43.95 C 4.45 43.95 0 39.5 0 33.95 L 0 9.95 C 0 4.45 4.45 0 9.95 0">
                          <s:fill>
                              <s:SolidColor color="#ff0000"/>
                          </s:fill>
                      </s:Path>
                  </s:Group>
              </s:mask>
          </s:BitmapImage>
          <s:RichText d:userLabel="Pagebottom" includeIn="normal" x="210" y="881" color="#f8f8ef"
                      fontFamily="Myriad Pro" fontSize="24" kerning="off" lineHeight="120%"
                      whiteSpaceCollapse="preserve">
              <s:content><s:p><s:span>P</s:span><s:span kerning="auto">age</s:span></s:p></s:content>
          </s:RichText>
          <s:RichText d:userLabel="1 of 4bottom" includeIn="normal" x="274" y="881" color="#f8f8ef"
                      fontFamily="Myriad Pro" fontSize="24" kerning="off" lineHeight="120%"
                      whiteSpaceCollapse="preserve">
              <s:content><s:p><s:span>1 of 4</s:span></s:p></s:content>
          </s:RichText>
          <s:Button id="button" includeIn="normal" x="363" y="2" click="button_clickHandler(event)"
                    skinClass="components.ButtonSkinNext"/>
          <s:Button includeIn="normal" x="0" y="2" width="138" click="button1_clickHandler(event)"
                    skinClass="components.ButtonSkinBack"/>
          <s:BitmapImage d:userLabel="TotalItems" includeIn="normal" x="178" y="5" smooth="true"
                         source="@Embed('/assets/images/clientnewest/TotalItems.png')">
              <s:mask>
                  <s:Group x="0" y="0">
                      <s:Path winding="evenOdd" data="M 9.95 0 L 141 0 C 146.5 0 150.95 4.45 150.95 9.95 L 150.95 33.95 C 150.95 39.5 146.5 43.95 141 43.95 L 9.95 43.95 C 4.45 43.95 0 39.5 0 33.95 L 0 9.95 C 0 4.45 4.45 0 9.95 0">
                          <s:fill>
                              <s:SolidColor color="#ff0000"/>
                          </s:fill>
                      </s:Path>
                  </s:Group>
              </s:mask>
          </s:BitmapImage>
          <s:RichText d:userLabel="Page" includeIn="normal" x="196" y="17" color="#f8f8ef"
                      fontFamily="Myriad Pro" fontSize="24" kerning="off" lineHeight="120%"
                      whiteSpaceCollapse="preserve">
              <s:content><s:p><s:span>P</s:span><s:span kerning="auto">age</s:span></s:p></s:content>
          </s:RichText>
          <s:RichText id="richText" d:userLabel="1 of 4" includeIn="normal" x="260" y="17" color="#f8f8ef"
                      creationComplete="richText_creationCompleteHandler(event)" fontFamily="Myriad Pro"
                      fontSize="24" kerning="off" lineHeight="120%" text="{countResult.lastResult}"
                      whiteSpaceCollapse="preserve">
              <s:content><s:p><s:span>1 of 4</s:span></s:p></s:content>
          </s:RichText>
      </s:Skin>
      
      

      Now i know that dataGroup_creationCompleteHandler is now empty but thats cos i would like the data to be filled when the user click on the button and not at the creation of the web site