4 Replies Latest reply on Apr 17, 2011 5:10 AM by IngoK3

    Issues with displaying retrived database content

    IngoK3

      First off, hello everyone.

       

      Secondly I've got an issue that I've been struggling with now for a while. I'm trying to tie data from a MySQL database, through the use of PHP classes, to my Flex project.

      I've gone through the initial PHP'ing and that now works like a charm (returning values in an object).

      The problem I have is that when I try to assign a value from the retrieved data to an object in my flex project (for example a label (labelID.text = retrivedData) it wont work. I've looked at the tutorial videos, and tried to use the same methods as shown (or as near to them as possible).

      Essentially what I'm trying to do is have a combo box fill with data collected through the creationComplete method (works fine). I then want to have a onChange event that calls a custom function that, with the selected item's data value (ie not selectedIndex, but in my case selectedItem.type), does another call to the PHP class. I then want this new information populating the .text, .source, .label value of a number of items in my flex project. None of this works.

       

      Preferably I would also want to be able (within the custom AS function) to call another function in my PHP class to retrive yet another array of data. This would then populate the next Combo Box.

       

      I really hope this got confusing enough .

       

      Please keep in mind that I am very new to the whole world of Flex, so be gentle.

       

      EDIT: I got was able to populate the label I mentioned, but only by using text="{fetchNameResult.lastResult[0].Name}". Only fetchNameResult.lastResult.Name wont work.

       

      CODE:

       

       

      <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:ns1="*" xmlns:controller="services.controller.*">
       <fx:Script>
       <![CDATA[
       import com.adobe.serializers.utility.TypeUtility;
       import mx.controls.Alert;
       import mx.events.*;
       import spark.events.*;
      
      
       protected function panesDrop_creationCompleteHandler(event:FlexEvent):void
       {
       getPLResult.token = controller.getPL("PL");
       }
      
       public function changeName(event:Event):void {
       var number:int = event.currentTarget.selectedItem.Type;
       fetchNameResult.token = controller.fetchName(number);
       typeName.text = fetchNameResult.lastResult.Name;
       typeImg.source = fetchNameResult.lastResult.Img;
       typeDescPL.text = fetchNameResult.lastResult.Desc;
       var typeId:int = fetchNameResult.lastResult.ID;
       getHeightResult.token = controller.getHeight(typeId);
       }
      
       ]]>
       </fx:Script>
       <s:states>
       <s:State name="ChoseLine"/>
       <s:State name="NatureL"/>
       <s:State name="PassiveLine"/>
       </s:states>
       <fx:Declarations>
       <s:CallResponder id="getPLResult"/>
       <s:CallResponder id="fetchNameResult"/>
       <s:CallResponder id="getHeightResult"/>
       <controller:Controller id="controller" 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:BorderContainer x="10" y="10" width="701" height="580" skinClass="spark.skins.spark.BorderContainerSkin" backgroundColor="#FB7701" cornerRadius="20" id="canvas" height.ChoseLine="380">
       <s:BorderContainer x="10" y="10" width="679" dropShadowVisible="true" cornerRadius="6" id="headerCanvas" backgroundAlpha="1.0" contentBackgroundColor="#FFFFFF" contentBackgroundAlpha="1.0" height="92" x.NatureL="10" y.NatureL="10">
       <s:Label text="Prisverktyget" fontSize="24" fontWeight="bold" fontFamily="Georgia" id="headerL" x="10" y="10"/>
       <s:Button x="585" y="59" id="changeL" label="€ndra Serie" enabled.ChoseLine="false" click.NatureL="currentState='ChosenLine';" click.PassiveLine="currentState='ChosenLine';"/>
       <s:Button x="418" y="59" label="Se dina upplagda fšnster" id="askQuote" enabled="false" click.PassiveLine="currentState='savedWindows';"/>
       </s:BorderContainer>
       <s:Button includeIn="ChoseLine" x="547" y="332" label="Nature Line" id="buttonNL" width="142" height="31" click="currentState='NatureL';"/>
       <s:Button x="401" y="332" label="Passive Line" id="buttonPL" width="142" height="31" includeIn="ChoseLine" click="currentState='PassiveLine';"/>
       <s:BorderContainer x="10" y="119" width="679" height="203" cornerRadius="6" dropShadowVisible="true" id="mainCanvas" height.NatureL="284" height.PassiveLine="284" x.PassiveLine="9" y.PassiveLine="120">
       <mx:Image x="51" y="26" source="PL.jpg" width="260" height="66" id="PLimg" includeIn="ChoseLine"/>
       <mx:Image x="371" y="26" source="NL.jpg" width="260" height="66" id="NLimg" includeIn="ChoseLine"/>
       <s:Label includeIn="ChoseLine" x="52" y="117" text="Passive Line-serien har fšnster med ett U-vŠrde pŒ lŒga 0,5. Dessa Šr vŒra mest energieffektiva standardfšnster." width="207" height="64" id="PLlabel"/>
       <s:Label x="373" y="117" text="Nature Line-serien har fšnster som passar de allra flesta applikationer. Med ett U-vŠrde pŒ 1,0 och endast 70mm inbyggnadsdjup Šr de ett mycket bra val." width="207" height="74" includeIn="ChoseLine" id="NLlabel"/>
       <s:ComboBox includeIn="PassiveLine" x="27" y="29" id="panesDrop" creationComplete="panesDrop_creationCompleteHandler(event)" labelField="Name" width="336" change="changeName(event)">
       <s:AsyncListView list="{getPLResult.lastResult}"/>
       </s:ComboBox>
       <s:Label includeIn="PassiveLine" x="28" y="14" text="VŠlj ditt fšnster (vŠlj fšr mer beskrivning)" id="panesDropL"/>
       <s:Label includeIn="PassiveLine" x="27" y="71" id="typeName" width="369" fontWeight="bold"/>
       <s:Label includeIn="PassiveLine" x="29" y="172" text="Hšjd" id="dropHeightL"/>
       <s:Label includeIn="PassiveLine" x="201" y="174" text="Bredd" id="dropWidthL"/>
       <s:Label includeIn="PassiveLine" x="27" y="105" width="251" height="61" id="typeDescPL"/>
       <mx:Image includeIn="PassiveLine" x="448" y="33" width="175" height="168" id="typeImg"/>
       <s:ComboBox includeIn="PassiveLine" x="28" y="191" id="dropHeight" labelField="Height">
       <s:AsyncListView list="{getHeightResult.lastResult}"/>
       </s:ComboBox>
       <s:ComboBox includeIn="PassiveLine" x="194" y="191" id="dropWidth"/>
       </s:BorderContainer>
       </s:BorderContainer>
      </s:Application>
      
      
      
      
        • 1. Re: Issues with displaying retrived database content
          Tanu Jain Level 2

          Your last line

          "{fetchNameResult.lastResult[0].Name}". Only fetchNameResult.lastResult.Name wont work."

           

          indicates that the result fetched from server is a collection of objects and not a single item value. Hence, u need to iterate or fetch the data item at the specific index of the lastResult.

           

          --

          Tanu

          1 person found this helpful
          • 2. Re: Issues with displaying retrived database content
            IngoK3 Level 1

            Yes I see your point. Then my conclusion would be that putting the line typeName.text = fetchNameResult.lastResult[0].Name; inside the custom function changeName() would solve the problem, but after trying it I can say it doesn't.

             

            Could it be an issue where the line to set the typeName.text value is executed before the async result from fetchNameResult has been populated and returned from the SuperController.as file? Since if I just try it with typeName.text = "test", it shows up fine in the application when calling the function.

             

            This issue is really doing my head in, and any help solving it would make my week

            • 3. Re: Issues with displaying retrived database content
              Tanu Jain Level 2

              In this case, assigning typeName.text = lastResult's data wont work because value is not available at that time.

               

              Calls made to server through php/java are asynchronous in nature, hence their returned results are not readily available.

               

              One needs to fetch the returned result in the resultHandler of the webservice/httpservice called. Handle the Result event of the service and make appropriate assignments for required data.

               

              --

              Tanu

              1 person found this helpful
              • 4. Re: Issues with displaying retrived database content
                IngoK3 Level 1

                I see. I will try to research the topic a bit, but any code examples of how to achieve this would be invaluable, considering my complete newbie-ness regarding action script and flex design.