Jump to content
Search Community

Problem with DataLoader and UrlRequest.data

mikaL test
Moderator Tag

Recommended Posts

Hello,

 

I tried this with DataLoader (it works with Flash URLLoader class):

 

public function save(url: string, data: XML): void {			
    var request = new URLRequest(url);
    request.contentType = 'multipart/form-data';
    request.data = data.toXMLString();    //  <== if this is commented out, no error	
    request.method = 'POST';
    new DataLoader(request, { name: 'saveXML' } );
   //... and then .load() etc. ...
}

 

But I get this error in DataLoader constructor:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock.loading.core::LoaderItem/_setRequestURL()

at com.greensock.loading.core::LoaderItem()

at com.greensock.loading::DataLoader()

 

If I comment out request.data = data.toXMLString(); then it doesn't throw the error. Any idea?

 

Mika

Link to comment
Share on other sites

This has to do with the workaround necessary to avoid a bug in Adobe's URLLoader class related to it not correctly appending variables in certain versions of the Flash Player. You should make sure that the "data" property of your URLRequest is a URLVariables object like this:

 

public function save(url: string, data: XML): void {         
    var request = new URLRequest(url);
    request.data = new URLVariables();
    request.xml = data.toXMLString();
    request.method = 'POST';
    new DataLoader(request, { name: 'saveXML' } );
   //... and then .load() etc. ...
}

Link to comment
Share on other sites

Thanks,

 

You probably meant

 

request.data.xml = data.toXMLString();

 

?

 

, but it still doesn't work: the server can't handle it and nothing is uploaded. I really have no idea what POST and multipart/form-data etc. actually mean, but could that be the problem? I mean, does this

 

request.contentType = 'multipart/form-data';

 

work with URLVariables?

 

Of course I can go back to using Flash classes for this, but I'd prefer LoaderMax since the download part works so well.

Link to comment
Share on other sites

Sure - I believe the problem stems mainly from the fact that you're setting the "data" property of your URLRequest to a value that isn't a URLVariables which is technically allowed according to Adobe's docs, but it causes problems in LoaderMax because of the workaround that was necessary for one of Adobe's bugs in the URLRequest class. Frankly it seems much cleaner to always use a URLVariables for the data anyway. I would recommend making sure you set your "data" property to a URLVariables and then just make one of the URLVariables' properties point to your data. See a solution at http://stackoverflow.com/questions/5079 ... st-in-flex (first answer).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...