Skip navigation
PremierITA
Currently Being Moderated

HTTPService in ActionScript

Nov 16, 2007 9:27 AM

I've created this class

quote:


package services
{
import mx.collections.ArrayCollection;
import mx.rpc.http.HTTPService;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

public class RSSService implements IService
{
private var _feeds:ArrayCollection;
private var _titleChannel:String;

private var _rssService:HTTPService;

public function RSSService(url:String) {
_rssService= new HTTPService();
_rssService.url= url;
_rssService.useProxy= false;
}

public function send():void {
_rssService.send();
_rssService.addEventListener(ResultEvent.RESULT, resultHandler);
_rssService.addEventListener(FaultEvent.FAULT, faultHandler);
}

private function resultHandler(event:ResultEvent):void {
_feeds= event.result.rss.channel.item;
_titleChannel= event.result.rss.channel.title;
}

private function faultHandler(event:FaultEvent):void {

}

public function getResult():Object {
if (_feeds == null) _rssService.send();

var result:Object= new Object();
result.feeds= _feeds;
result.titleChannel= _titleChannel;
return result;
}

}
}



and i use it in this way
quote:


[Bindable]
public var feed:ArrayCollection;

[Bindable]
public var titleChannel:String;
private function onConfirm():void {
var service:RSSService= new RSSService(rssUrl.selectedItem.data);
var obj:Object= service.getResult();
titleChannel= obj.titleChannel;
feed= obj.feeds;
currentState= 'reader';
}


in the Application file.
When i launch the application, the HTTPService object doesn't call resultHandler(event:ResultEvent) method, so the _feeds Array is empty.

Why?

I need tutorials, where i can found they?

Byr
 
Replies
  • Currently Being Moderated
    Nov 19, 2007 2:33 AM   in reply to PremierITA
    Are you sure your URL is getting called at all? What if you add some alert message in the fault hanlder?

    ATTA
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2007 4:11 AM   in reply to PremierITA
    Hi,

    it seems ti should work. thing is...you do not call getResult() immediately before resultHandler fires. So, make sure resultHandler fires and then call getResult().

    Thanks

    KBala
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2007 5:38 AM   in reply to PremierITA
    just dispatch an event in this function

    xxxxx your code xxxxx
    private function resultHandler(event:ResultEvent):void {
    _feeds= event.result.rss.channel.item;
    _titleChannel= event.result.rss.channel.title;

    ********dispatch the event here**************
    }


    and, capture the event where you use the class's instance.

    thanks

    KBala
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 20, 2007 3:57 AM   in reply to PremierITA
    hi,

    i rewirte your code like this

    class
    ------------------

    package services
    {
    import flash.events.EventDispatcher;
    import mx.collections.ArrayCollection;
    import mx.rpc.http.HTTPService;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import flash.events.Event;

    [Event(name="result",type="mx.rpc.events.ResultEvent")]
    public class RssService extends EventDispatcher
    {
    private var _feeds:ArrayCollection;
    private var _titleChannel:String;

    private var _rssService:HTTPService;

    public function RssService(url:String)
    {
    super();
    _rssService= new HTTPService();
    _rssService.url= url;
    _rssService.useProxy= false;
    }

    public function send():void
    {
    _rssService.send();
    _rssService.addEventListener(ResultEvent.RESULT, resultHandler);
    _rssService.addEventListener(FaultEvent.FAULT, faultHandler);
    }

    private function resultHandler(event:ResultEvent):void
    {
    _feeds= event.result.rss.channel.item;
    _titleChannel= event.result.rss.channel.title;
    var result:Object= new Object();
    result.feeds= _feeds;
    result.titleChannel= _titleChannel;
    var evt:ResultEvent = new ResultEvent("result",false,true,result);
    dispatchEvent(evt);
    }

    private function faultHandler(event:FaultEvent):void
    {

    }


    }
    }



    Implementation
    ----------------------------

    import mx.rpc.events.ResultEvent;
    import services.RssService;
    import mx.core.SoundAsset;
    private var r:RssService;

    private function init():void
    {
    r = new RssService("url here");
    r.addEventListener(ResultEvent.RESULT,resultHandler)
    r.send()

    }

    private function resultHandler(event:ResultEvent):void
    {
    // use event.result here
    }


    this will be solve your issue, good luck!

    Thanks

    KBala
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points