Flex HTTPService in Actionscript help

  • Sumen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 421
  • Loc: Rochester or Albany, NY

Post 3+ Months Ago

Hi, I am new to flex (and actionscript really) and in the application I am making I use an HTTPService Object in an actionscript file. The object keeps throwing a FaultEvent and I don't understand the message its giving me or how to fix the problem

the FaultEvent faltstring says:
Quote:
[MessagingError message='Destination 'http://localhost/bearcube2/artists.php' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']


The file definately exists, its a php file that echos xml, that I wish to populate a list with. I've also tried just plain xml files...or xml files on other websites... to see if that would work but I still get that error.

I've also made a crossdomain.xml in my localhost's root that looks like this

Code: [ Select ]
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>
  1. <?xml version="1.0"?>
  2. <!DOCTYPE cross-domain-policy
  3.   SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
  4. <cross-domain-policy>
  5.   <allow-access-from domain="*" />
  6. </cross-domain-policy>


I don't know what channels are, I'm not sure what the error is saying...

What I'm trying to do is have a function that can make http requests based on user input and then populate a list from the xml supplied by the http requests response. Heres the code that applies

My mxml file
Code: [ Select ]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
 
   <mx:Script>
        <![CDATA[
            import com.bearcube.Controller;
            import com.bearcube.ArtistList;
           
           public var controller:Controller = new Controller();
 
            [Bindable]
            private var artistList:ArtistList = ArtistList.getInstance();
           
            private function clickHandler(event:Event):void
            {
            }
        ]]>
    </mx:Script>
 
    <mx:HBox width="100%">
        <mx:Panel width="250" height="200" layout="horizontal">
         <mx:List id="mylist"
        labelField="Artists"
        dataProvider="{artistList.artistList}"
        width="200" height="200"
        itemClick="clickHandler(event)"/>
 
        </mx:Panel>
       
</mx:Application>
 
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  3.  
  4.    <mx:Script>
  5.         <![CDATA[
  6.             import com.bearcube.Controller;
  7.             import com.bearcube.ArtistList;
  8.            
  9.            public var controller:Controller = new Controller();
  10.  
  11.             [Bindable]
  12.             private var artistList:ArtistList = ArtistList.getInstance();
  13.            
  14.             private function clickHandler(event:Event):void
  15.             {
  16.             }
  17.         ]]>
  18.     </mx:Script>
  19.  
  20.     <mx:HBox width="100%">
  21.         <mx:Panel width="250" height="200" layout="horizontal">
  22.          <mx:List id="mylist"
  23.         labelField="Artists"
  24.         dataProvider="{artistList.artistList}"
  25.         width="200" height="200"
  26.         itemClick="clickHandler(event)"/>
  27.  
  28.         </mx:Panel>
  29.        
  30. </mx:Application>
  31.  


My Controller.as file

Code: [ Select ]
package com.bearcube
{
    import mx.rpc.http.HTTPService;
    import mx.rpc.events.FaultEvent;
    import mx.controls.Alert;
 
 
    public class Controller
    {
        private var service:HTTPService;
        public function Controller()
        {
            updateArtists("http://localhost/bearcube2/artists.php");
        }
 
        public function updateArtists(url:String): void
        {
            var artistList:ArtistList = ArtistList.getInstance();
            service = new HTTPService();
            service.destination = url;
            //Alert.show("http://localhost/bearcube2/artists.php");
            service.method = "GET";
            service.addEventListener("result", artistList.updateList);
            service.addEventListener("fault", httpFault);
            service.send();                            
        }
       
        public function httpFault(event:FaultEvent):void {
                var faultstring:String = event.fault.faultString;
                Alert.show(faultstring);
        }
 
    }
}
  1. package com.bearcube
  2. {
  3.     import mx.rpc.http.HTTPService;
  4.     import mx.rpc.events.FaultEvent;
  5.     import mx.controls.Alert;
  6.  
  7.  
  8.     public class Controller
  9.     {
  10.         private var service:HTTPService;
  11.         public function Controller()
  12.         {
  13.             updateArtists("http://localhost/bearcube2/artists.php");
  14.         }
  15.  
  16.         public function updateArtists(url:String): void
  17.         {
  18.             var artistList:ArtistList = ArtistList.getInstance();
  19.             service = new HTTPService();
  20.             service.destination = url;
  21.             //Alert.show("http://localhost/bearcube2/artists.php");
  22.             service.method = "GET";
  23.             service.addEventListener("result", artistList.updateList);
  24.             service.addEventListener("fault", httpFault);
  25.             service.send();                            
  26.         }
  27.        
  28.         public function httpFault(event:FaultEvent):void {
  29.                 var faultstring:String = event.fault.faultString;
  30.                 Alert.show(faultstring);
  31.         }
  32.  
  33.     }
  34. }


My ArtistList.as file (which is my model for the list)
Code: [ Select ]
package com.bearcube
{
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
 
    [Bindable]
    public class ArtistList
    {
        private static var _artistList:ArtistList;
        public static function getInstance():ArtistList
        {
            if(_artistList == null)
            {
                _artistList = new ArtistList();
            }
           
            return _artistList;
        }
               
        public function ArtistList()
        {
            _artistList = this;
        }
       
        public var artistList:ArrayCollection = new ArrayCollection();
       
        public function updateList( event:ResultEvent ):void
        {
            artistList = event.result.artistList.artist as ArrayCollection;
        }
       
    }
}
  1. package com.bearcube
  2. {
  3.     import mx.collections.ArrayCollection;
  4.     import mx.rpc.events.ResultEvent;
  5.  
  6.     [Bindable]
  7.     public class ArtistList
  8.     {
  9.         private static var _artistList:ArtistList;
  10.         public static function getInstance():ArtistList
  11.         {
  12.             if(_artistList == null)
  13.             {
  14.                 _artistList = new ArtistList();
  15.             }
  16.            
  17.             return _artistList;
  18.         }
  19.                
  20.         public function ArtistList()
  21.         {
  22.             _artistList = this;
  23.         }
  24.        
  25.         public var artistList:ArrayCollection = new ArrayCollection();
  26.        
  27.         public function updateList( event:ResultEvent ):void
  28.         {
  29.             artistList = event.result.artistList.artist as ArrayCollection;
  30.         }
  31.        
  32.     }
  33. }



If anyone could help me I'd appreciate it a lot... I've been digging around and haven't found any help...very frustrating since this should be simple :( ... I figure I'm doing something dumb but I'm new to flex and actionscript and I don't see it
thanks in advance
  • Sumen
  • Proficient
  • Proficient
  • User avatar
  • Posts: 421
  • Loc: Rochester or Albany, NY

Post 3+ Months Ago

well after spending a lot of time (I mean ALOT of time) trying to find a solution to the problem... shortly after posting I realize (looking at the documentation for httpservice) that i'm actually just retarded
just changed
service.destination = url;
service.url = url;

oops....
  • Manikese
  • Born
  • Born
  • Manikese
  • Posts: 1

Post 3+ Months Ago

Thank you very much for figuring this out. The only other source that I found was at expert exchange, but I didn't want to pay for a membership.

I'm a Flex/ActionScript noob myself and what happened was that we found a similar example that was wrong: http://livedocs.adobe.com/flex/3/html/h ... ess_2.html

I'm trying use the Model-view-controller (MVC) architectural pattern, so I need to pull the services out of the View (mxml) files.

Best of luck to you.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.