You know what sucks? AS3's URLRequest class, that's what. It takes about ten lines of code just to load data from a simple web service. Quiero makes that much easier. So, wanna know what the weather is like in Salem, Oregon? Me neither, but let's find it anyway:
var request:URLRequest = new URLRequest('http://google.com/ig/api');
var loader:URLLoader = new URLLoader();
var variables:URLVariables = new URLVariables();
variables.weather = 'Salem, OR';
request.method = URLRequestMethod.GET;
loader.addEventListener(Event.COMPLETE,onRequestComplete);
loader.load(request);
function onRequestComplete(e:Event):void {
trace(e.target.data);
}
import quiero.*;
Quiero.request({url:'http://google.com/ig/api',method:'get',data:{weather:'Salem, OR'},onComplete:onRequestComplete});
function onRequestComplete(e:RequesterEvent):void {
trace(e.data)
}
See how much easier that was? But Quiero is useful for more than just simple URLLoader requests. Hows about:
Quiero.request({url:'mysomething.swf',loader:addChild(new Loader())});
Quiero.request({url:'someSound.mp3',sound:new Sound()});
var fileReference:FileReference = new FileReference('anImageOrSomething.png');
Quiero.request({url:'upload.php',data:{name:fileReference.name},file:fileReference});
Quiero.request({url:'test.jpg',downloadFile:new FileReference(),downloadName:"image"})
Quiero has exactly one method:
Quiero.request(params:Object,load:Boolean=true,strict:Boolean=true):URLRequest
But the only part you need to worry about is the params object, through which you can pass parameters to Quiero. This object itself requires only one property:
url:String
: The URL that Quiero will call. And oodles of optional parameters. The ones you'll probably use most often aredata
,method
,format
, andonComplete
. Let's take a look at these.data:Object
: A simple AS3 object that contains data to pass to the URL. For instance, to pass a username and password to a login script, you would use{username:"helloperson",password:"password123"}
.method:String
: Tells Quiero how to pass thedata
object, using either GET or POST."get"
and"post"
will work fine here. This data is passed to themethod
property of aURLRequest
object in Quiero's guts.format:String
: Tells Quiero what kind of data to expect. Use a property from theURLLoaderDataFormat
class (referenced byQuiero.formats
).onComplete:Function
: A function called when the request completes. Takes one parameter, aRequestEvent
. You can access the loaded data through the event'sdata
property. Quiero uses these properties for event handling:onIOError:Function
: A callback that expects anIOErrorEvent
parameter, equivalent to listening forIOErrorEvent.IO_ERROR
from an object such as aURLLoader
or aSound
.onSecurityError:Function
: Expects aSecurityError
parameter, equivalent to listening forSecurityErrorEvent.SECURITY_ERROR
.onProgress:Function
: Expects aProgressEvent
parameter, equivalent to listening forProgressEvent.PROGRESS
. These properties will also come in handy:contentType:String
: The MIME type of the data being sent. Use with caution, as the default should normally work fine. This is passed to thecontentType
property of aURLRequest
object.headers:Array
: An array of headers to send with the request. Passed to therequestHeaders
property of aURLRequest
object.forceRefresh:Boolean
: Basically adds a random token named"quiero_flash_token"
to thedata
parameter, ensuring that Flash won't use the cache to make this request.toVars:Boolean
: If set tofalse
, Quiero won't try to convert yourdata
object into aURLVariables
object. Usually you want this to happen, so use with discretion. To load data into aLoader
object:loader:Loader
: TheLoader
that will receive the content aturl
(an image or a .swf file). To load data into aSound
object:sound:Sound
: TheSound
object that will play the sound aturl
. To upload aFileReference
:file:FileReference
: The file to upload tourl
. Note that the AIR classFile
extendsFileReference
.fileFieldName:String
: The field name that the script aturl
will use to find the file on the server. If not specified, it will remain"Filedata"
, which is a good default. To download to aFileReference
:download:FileReference
: AFileReference
object to attempt a download to. Quiero will call itsdownload
method.downloadName:String
: The default name of the file that Quiero will attempt to download.- Note that Quiero has no mechanism for listening to
Event.SELECT
andEvent.CANCEL
callbacks for file dialog handling. Please add listeners for these to thedownload
object.
I'm not sure what will happen if you specify both file
and downloadFile
, but it's reasonable to assume the universe will simply collapse in on itself and such calls should be avoided.
- If
false
,load
will prevent the request from loading right away, allowing you to modify theRequester
that Quiero gives you before firing it off (via itsrequest:URLRequest
property). - If
true
,strict
will warn you about properties passed to theparams
object that don't make any sense to Quiero.
That is all the documentation Quiero requires! Start making awesome things.