4 Replies Latest reply on Feb 9, 2010 7:50 AM by alice_data

    How to Display SVG Embedded in HTTService? (PHP)

    alice_data

      Hi,

       

      I don't know if anyone on this list has tried to do this. I have a few files that I have generated SVG with PHP, and I am trying to load them into my Flex app. Looks like that the XMLList that I tried to convert from XML was generated correctly, and I could get it to print out as an XML String. However, how can I get the "image" to show up?

       

      <?xml version="1.0"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="population_map.send()"

          <mx:Script>

              <![CDATA[

       

                  import mx.collections.XMLListCollection;    

                 import mx.rpc.events.ResultEvent;

                 import mx.rpc.events.FaultEvent;

                 import mx.controls.Alert;

                 private var alert:Alert;

                 [Bindable]private var searchResult:XML;

                 [Bindable]private var xmlList:XMLList;

       

                 private function httpService_fault(event:FaultEvent):void {

       

                      var title:String = event.type + " (" + event.fault.faultCode + ")";

                      var text:String = event.fault.faultString;

                      alert = Alert.show(text, title);             

                  }

       

                  private function httpService_result(event:ResultEvent):void {

       

                        searchResult = event.result as XML; 

                        xmlList = XMLList(searchResult);          

                        //var xmlListCollection:XMLListCollection = XMLListCollection(xmlList); 

                      //I can the error tellling me that I cannot convert XMLList@3613c49 to mx.collections.XMLLIstCollection

                  }

              ]]>

       

          </mx:Script>

       

             <mx:HTTPService id="population_map" url="http://tdc-queuing/test/population_5grade.php"

             fault="httpService_fault(event);" result="httpService_result(event)" resultFormat="e4x"/>    

       

                 <mx:Text text="{searchResult.toXMLString()}"/>  

      </mx:Application>

       

        I don't want to save the file generated by PHP here to an SVG here, because I am trying to use a slider to allow users to customize the colors on the SVG.

       

      Thanks for your help.

       

      Alice

        • 1. Re: How to Display SVG Embedded in HTTService? (PHP)
          Flex harUI Adobe Employee

          You might just need:

              import mx.collections.XMLListCollection

           

          But you probably also need to run a query on the result XML to get an

          XMLList.  Then you need a parser to convert the SVG to graphics.

          • 2. Re: How to Display SVG Embedded in HTTService? (PHP)
            alice_data Level 1

            Hi,

             

            The PHP (HTTPService) here is a SVG parser itself, since I can click on the url from my own computer with the PHP address and see the "SVG image", but looks like I cannot do that here with Flex. I have the first line as you suggested in my code example here, but looks like I can print out the text string here of the entire HTTPService xmlstring, but I cannot get it to print out the actual image.

             

            Does this help explaining what my issue here may be?

             

            Thanks for your help.

             

            Alice

            • 3. Re: How to Display SVG Embedded in HTTService? (PHP)
              Flex harUI Adobe Employee

              Like I said, Flex does not have any code that will interpret the SVG and

              draw it for you.  Check out the Deng project.  There might be other third

              party solutions.

               

              Flex will transcode SVG and compile time, but not when loaded over the

              network.

              • 4. Re: How to Display SVG Embedded in HTTService? (PHP)
                alice_data Level 1

                Hi,

                 

                  This helps, but I am having troubles determining the differences between loading and compiling time.

                  Here is the code, and right now it does display only text because I set it to mx:Text, but can I get it to display it as something else so that my "SVG" in the HTTPService can be embedded otherwise?

                 

                <?xml version="1.0"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="population_map.send()">
                   
                    <mx:Script>
                        <![CDATA[
                            import mx.collections.XMLListCollection;       
                           import mx.rpc.events.ResultEvent;
                           import mx.rpc.events.FaultEvent;
                           import mx.controls.Alert;
                           private var alert:Alert;
                             [Bindable]private var searchResult:XML;
                             [Bindable]private var xmlList:XMLList;

                 

                            private function myDataTipFunc(val:String):String {
                                var myNumber:Number = Number(val);
                                var roundedValue:String= String(myNumber.toFixed(2));
                                return "Current value: " + roundedValue;
                            }
                           
                           private function httpService_fault(event:FaultEvent):void {
                                var title:String = event.type + " (" + event.fault.faultCode + ")";
                                var text:String = event.fault.faultString;
                                alert = Alert.show(text, title);               
                            }

                 

                            private function httpService_result(event:ResultEvent):void {
                                  searchResult = event.result as XML;   
                                  xmlList = XMLList(searchResult);            
                                  //var xmlListCollection:XMLListCollection = XMLListCollection(xmlList);    
                            }
                        ]]>
                    </mx:Script>
                       <mx:HTTPService id="population_map" url="http://localhost/population_5grade.php"
                       fault="httpService_fault(event);" result="httpService_result(event)"
                           resultFormat="e4x"/>      
                           <mx:Text text="{searchResult.toXMLString()}"/>         

                           <!--This of course loads the svg text output, but is it possible to get it to be displayed as an image?-->
                         <mx:HSlider height="80" dataTipFormatFunction="myDataTipFunc"/>
                </mx:Application>

                 

                Thanks for your help.

                 

                Alice