4 Replies Latest reply on Mar 1, 2010 7:23 AM by alice_data

    Image Coming from URLRequest Not Displaying?

    alice_data Level 1

      Hi,

       

        I have a main app here with a subclass that is supposed to "send images" based on the "parameters" that sends to a HTTPService.

        However, even though the url seems to be generating correctly, I could not see the image. Since my PHP is working fine with the url as shown in the trace statements from my app, I am assuming that there has to be something else that I am missing here.

       

        Below is the code that generates the image, is there something here I am missing?

       

      package map
      {
           import colorize.*;    
           import com.zavoo.svg.*;    
           import flash.display.Sprite;
           import flash.events.Event;
           import flash.net.URLLoader;
           import flash.net.URLRequest;
           import flash.net.URLVariables;    
           import mx.containers.Canvas;
           import mx.core.UIComponent;

       

          public class SvgMap extends UIComponent {
             
              public var canvas:Sprite;
              [Embed(source="USA_Counties_with_FIPS_and_names.svg")]
              public var usaMap:Class;
              public var paths:SvgPaths;                 
             
              private var patient_from:Array;   
              private var drive_time:Array;
              private var drive_distance:Array;
              private var college:Array;
              private var high_school:Array;
              private var income:Array;
              private var population:Array; 
              private var countyName:XMLList;
              private var stateColors:Array;
              private var horizontal_bar:Canvas;
          
          public function SvgMap():void {
                 
                      canvas = new usaMap();
                      canvas.width = 650;
                      canvas.height = 500;
                      addChild(canvas);
                      trace("Canvas Parent: " + canvas.parent);                            
              }
          public function passBox(passedBox:Canvas):void{
              horizontal_bar = passedBox;       
          }
           public function setParameters(passedArray:Array,passedArray7:Array):void {
                                                
                  from = passedArray;          
                  stateColors= passedArray7;   
                  changeMap(from,stateColors);           
                                    
              }       
              public function changeMap(passedArray:Array,passedArray7:Array):void{   
                      
              removeChild(this.canvas);              
              canvas = new Sprite();
              canvas.width = 600;
              canvas.height = 500;
              addChild(canvas);     
                     
              var from_string:String = from.join("-");
              var state_colors_string:String = stateColors.join("-");       
                
              var loader:URLLoader = new URLLoader();          
              var url:String = "http://tdc-queuing/test/generic.php?from=" + from_string + "&state_colors=" + state_colors_string;
              var variables:URLVariables = new URLVariables();
              variables.patient_from= patient_from_string;
              variables.state_colors = state_colors_string;
              var encode:String= encodeURI(url);   
              var pattern:RegExp = /#/g;
              var decode:String = encode.replace(pattern,"%23");   
              var request:URLRequest = new URLRequest(decode);       
              request.method = "GET";       
              loader.load(request);       
              loader.addEventListener(Event.COMPLETE, onLoadComplete);
              }       
             
              public function onLoadComplete(event:Event):void {
                      var loader:URLLoader = URLLoader(event.target);              
                      paths = new SvgPaths(loader.data);      //the canvas exists
                      paths.drawToGraphics(this.canvas.graphics, 2, 10, 10);
              }           
          }
      }

       

      Thanks for your help. Anything is appreciated.

       

      Alice

        • 1. Re: Image Coming from URLRequest Not Displaying?
          NonTakenUserName Level 1

          Would you happen to have that PHP on an external-facing server that I could use to run a test with this code?

          • 2. Re: Image Coming from URLRequest Not Displaying?
            alice_data Level 1

            Hi,


            For testing purposes, here is the package:

             

            package map
            {
                 import colorize.*;   
                 import com.zavoo.svg.*;   
                 import flash.display.Sprite;
                 import flash.events.Event;
                 import flash.net.URLLoader;
                 import flash.net.URLRequest;
                 import flash.net.URLVariables;   
                 import mx.containers.Canvas;
                 import mx.core.UIComponent;

             

             

             

                public class SvgMap extends UIComponent {
                  
                    public var canvas:Sprite;
                    [Embed(source="USA_Counties_with_FIPS_and_names.svg")]
                    public var usaMap:Class;
                    public var paths:SvgPaths;                
                  
                    private var from:Array;  
                    private var stateColors:Array;
                    private var horizontal_bar:Canvas;
               
                public function SvgMap():void {
                      
                            canvas = new usaMap();
                            canvas.width = 650;
                            canvas.height = 500;
                            addChild(canvas);
                            trace("Canvas Parent: " + canvas.parent);                           
                    }
                public function passBox(passedBox:Canvas):void{
                    horizontal_bar = passedBox;      
                }
                 public function setParameters(passedArray:Array,passedArray7:Array):void {
                                                     
                        from = passedArray;         
                        stateColors= passedArray7;  
                        changeMap(from,stateColors);          
                                         
                    }      
                    public function changeMap(passedArray:Array,passedArray7:Array):void{  
                           
                    removeChild(this.canvas);             
                    canvas = new Sprite();
                    canvas.width = 600;
                    canvas.height = 500;
                    addChild(canvas);    
                          
                    var from_string:String = from.join("-");
                    var state_colors_string:String = stateColors.join("-");      
                     
                    var loader:URLLoader = new URLLoader();         
                    var url:String = "http://localhost/test/generic.php?from=" + from_string + "&state_colors=" + state_colors_string;
                    var variables:URLVariables = new URLVariables();
                    variables.from= from_string;
                    variables.state_colors = state_colors_string;
                    var encode:String= encodeURI(url);  
                    var pattern:RegExp = /#/g;
                    var decode:String = encode.replace(pattern,"%23");  
                    var request:URLRequest = new URLRequest(decode);      
                    request.method = "GET";      
                    loader.load(request);      
                    loader.addEventListener(Event.COMPLETE, onLoadComplete);
                    }      
                  
                    public function onLoadComplete(event:Event):void {
                            var loader:URLLoader = URLLoader(event.target);             
                            paths = new SvgPaths(loader.data);      //the canvas exists
                            paths.drawToGraphics(this.canvas.graphics, 2, 10, 10);
                    }          
                }
            }

             

            And, this is the PHP:

             

            <?php

             

            header("Content-type: image/svg+xml"); //Outputting an SVG

             

            $from = $_GET['from'];
            $state_colors= $_GET['state_colors'];

             

            $from = explode("-", $from);
            $state_colors= explode("-", $state_colors);

             

            #Load the Map
            $ourFileName= "USA_Counties_with_FIPS_and_names.svg";
            $fh = fopen($ourFileName, "r") or die("Can't open file");
            $contents = fread($fh,filesize($ourFileName));
            $lines2= file($ourFileName);

             

            foreach ($lines2 as $line_num => $line2) {

             

            $style_line_num = $line_num+3;
            $line2 = trim($line2);

             

                  if(preg_match("/^style/",$line2)) {

             

                   $rest = substr($line2,0,-1);        

             

                   for ($j=$line_num;$j<=$style_line_num;$j++){
                     if(preg_match("/inkscape:label/",$lines2[$j])) { 
                        $location = explode("=",$lines2[$j]);
                        $location2 = substr($location[1],1,-6); 
                      
                        if(in_array($location2, $from)) {
                      
                         $key= array_search($location2,$from); //Find out the position of the index in the array
                         $colors_style = ";fill:" . $state_colors[$key];  //Use the index from array_search to apply to the color index
                         $rest2 = substr($line2,0,-1). $colors_style . "\"";           
                         echo $rest2 . "\n";
                        }
                        else echo $line2 . "\n";           

             

                     } //end preg_match inkscape       
                 } //end for loop
               }  //If preg_match style

             

                 else echo $line2 . "\n"; //else if preg_match style    
            } //end for each  

             

            fclose($fh);
            ?>

             

            Thanks for your help.

            • 3. Re: Image Coming from URLRequest Not Displaying?
              Flex harUI Adobe Employee

              I'm not going to be able to run your test case.  Maybe someone else can

              help.  The key is going to what happens in onLoadComplete

              1 person found this helpful
              • 4. Re: Image Coming from URLRequest Not Displaying?
                alice_data Level 1

                Hi,

                 

                  When I tried to add trace statements to the url that would be executing to my HTTPService, looks like that the url is accurate, and the "variables" that would be passing is right as well. However, I have noticed that when it goes to onLoadComplete, and I print out the output from URLLoader, it does come out in the way I have projected, with the correct modifications.

                 

                  Yet, the image I thought that would be printed out never did. Is there anything wrong with my onLoadComplete here?

                 

                  public function onLoadComplete(event:Event):void {
                                var loader:URLLoader = URLLoader(event.target);                         
                                paths = new SvgPaths(loader.data);      //the canvas exists
                                trace(loader.data); //prints out the correct data with the state colors and states variables passed through correctly as projected
                                paths.drawToGraphics(this.canvas.graphics, 2, 10, 10);
                                var trans:Transform = new Transform(canvas);
                                trace(trans.pixelBounds);      //Nothing is shown
                        }           
                    }

                 

                Thanks for your help.