My problem wasn't receiving null...
I send an HTTPService. The ResultEvent creates an ArrayCollection. I wanted my
class to return that ArrayCollection but what is happening is right after my
HTTPService is sent, my class returns my ArrayCollection before the ResultEvent
has time to fill it... therefore it is null....
I'm now trying to implement an EventDispatcher but am getting a little
confused...
Does this look right??? :
[
{
{
service.url =
service.useProxy =
service.method =
service.resultFormat =
service.showBusyCursor =
service.addEventListener(ResultEvent.RESULT, Bindable]
publicclassClientServices
extendsEventDispatcherprivatevarserviceArray:ArrayCollection;privatevarserviceXML:XML;
publicfunctionClientServices
(target:IEventDispatcher=null)super(target);varservice:HTTPService =
newHTTPService();'test.php';false;'POST';'e4x';true;function(event:ResultEvent):void{
serviceArray =
serviceXML = event.result
dispatchEvent(event)
}
);
service.send();
}
}
Thanks.newArrayCollection();asXML;varourxml:XML;foreach(ourxml
inserviceXML.elements()) serviceArray.addItem(ourxml);
________________________________
From: actionscript_czar <[email protected]>
To: [email protected]
Sent: Wednesday, April 8, 2009 12:18:04 PM
Subject: [flexcoders] Re: How can I have my class return an ArrayCollection?
If you are having problems with it giving you a null object before the
ResultEvent function is called then make a function that returns an empty
ArrayCollection if it is currently null.
Perhaps
function getServiceArray( ):ArrayCollection
{
if( this.serviceArray == null )
{
this.serviceArray = new ArrayCollection( );
}
return this.serviceArray( );
}
If that isn't what you are having problems with, perhaps more specificity could
help us help you.
--- In flexcod...@yahoogro ups.com, - - <sailorsea21@ ...> wrote:
>
> I tried that but it returns an empty ArrayCollection because it's only
> created within the ResultEvent Function once the HTTPService is successful.. .
>
> Thanks.
>
>
>
>
> ____________ _________ _________ __
> From: valdhor <valdhorlists@ ...>
> To: flexcod...@yahoogro ups.com
> Sent: Wednesday, April 8, 2009 11:20:44 AM
> Subject: [flexcoders] Re: How can I have my class return an ArrayCollection?
>
>
> Umm.. Add a public function that returns serviceArray ?
>
> --- In flexcod...@yahoogro ups.com, "sailorsea21" <sailorsea21@ ...> wrote:
> >
> > Hi everyone,
> > how can I have this following class return me an ArrayCollection whenever I
> > call it????
> >
> > [Bindable]
> > public class Services
> > {
> > public var serviceArray: ArrayCollection;
> > public var serviceXML:XML;
> >
> > public function getServices( ):void
> > {
> > var service:HTTPService = new HTTPService( );
> > service.url = "test.php";
> > service.useProxy = false;
> > service.method = "POST";
> > service.resultForma t = "e4x";
> > service.showBusyCur sor = true;
> > service.addEventLis tener(ResultEven t.RESULT,
> > function (event:ResultEvent) :void
> > {
> > serviceArray = new ArrayCollection( );
> > serviceXML = event.result as XML;
> > var ourxml:XML;
> > for each(ourxml in serviceXML.elements ()) serviceArray. addItem(ourxml) ;
> > }
> > );
> > service.send( );
> > }
> > }
> >
>