3 Replies Latest reply on Mar 3, 2010 9:30 AM by alice_data

    Converstion from Sprite to IUIComponent Type Errors




        I have something here that tells me


      TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite@3233901 to mx.core.IUIComponent.
          at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()[C:\autobuild\3.2.0\frameworks\pr ojects\framework\src\mx\core\Container.as:3259]
          at mx.core::Container/addChildAt()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\c ore\Container.as:2207]
          at mx.core::Container/addChild()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\cor e\Container.as:2140]
          at map::SvgMap/onLoadComplete()
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at flash.net::URLLoader/onComplete()


      As weird as it may sound, when I tried to convert the extends to IUIComponent, instead of UIComponent, for the class type, it tells me that I cannot do that because I cannot convert it to an interface.


      Here is the complete code:


      package map
           import colorize.*;    
           import com.zavoo.svg.*;        
           import flash.display.Sprite;
           import flash.events.Event;
           import flash.net.URLVariables;
           import flash.net.URLLoader;
           import flash.net.URLRequest;    
           import mx.containers.Canvas;
           import mx.core.UIComponent;
          public class SvgMap extends UIComponent {       
          public var canvas:Sprite;      
              public var paths:SvgPaths;                
              private var from:Array;   
          private var stateColors:Array;
          public var horizontal_bar:Canvas;
           public function changeMap(passedArray:Array,passedArray7:Array):void{                        
              var from_string:String = from.join("-");
              var state_colors_string:String = stateColors.join("-");                  
          var loader:URLLoader = new URLLoader();
          var url:String = "http://localhost/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.addEventListener(Event.COMPLETE, onLoadComplete);
          public function onLoadComplete(event:Event):void {
                        canvas = new Sprite(); 
                      var loader:URLLoader = URLLoader(event.target); 
                      paths = new SvgPaths(loader.data);   
                      paths.drawToGraphics(canvas.graphics, 2, 10, 10);


      Obviously it does not like something in my onLoadComplete, but the question is, what?