My favorites | English | Sign in

o3d.FileRequest Class Reference

Inherits o3d.ObjectBase

List of all members.


Detailed Description

A FileRequest is used to carry out an asynchronous request for a file to be loaded. Its use parallels that of XMLHttpRequest; you create one, call open, set the onreadystatechange callback, and call send. Note that unlike XMLHttpRequests, FileRequests cannot be reused. For RawData loads, on success the RawData will be stored in the data field on the FileRequest itself. It is only valid until the FileRequest is freed by calling pack.removeObject(request).
var request = pack.createFileRequest("RAWDATA");
request.open("GET", url, true);
request.onreadystatechange = function() {
  if (request.done) {
    if (request.success) {
      var rawData = request.data;
      // do something with raw data like create a bitmap.
      ...
    } else {
      dump('Load of rawdata returned failure.');
    }
    // Free the request (and the rawData)
    pack.removeObject(request);
  }
};
request.send();

Public Member Functions

boolean  isAClassName(className) o3d.ObjectBase
open(method, uri, async) o3d.FileRequest
send() o3d.FileRequest

Public Properties

string className o3d.ObjectBase
number clientId o3d.ObjectBase
o3d.RawData data o3d.FileRequest
boolean done o3d.FileRequest
string error o3d.FileRequest
boolean generateMipmaps [**DEPRECATED**] o3d.FileRequest
function(): void onreadystatechange o3d.FileRequest
number readyState o3d.FileRequest
boolean success o3d.FileRequest
o3d.Texture texture [**DEPRECATED**] o3d.FileRequest
string uri o3d.FileRequest

Member Function Documentation

boolean FileRequest.isAClassName ( string className ) [inherited from o3d.ObjectBase]

Takes the name of a class as an argument, and returns true if this object is either an instance of that class or derives from that class.

var t = pack.createObject('o3d.Transform');
t.isAClassName('o3d.Transform');    // true
t.isAClassName('o3d.ParamObject');  // true
t.isAClassName('o3d.Shape');        // false
Parameters:
className Name of class to check for.
Returns:
boolean.true if this object is a or is derived from the given class name.
FileRequest.open ( string method
string uri
boolean async )

Set up several of the request fields.

Parameters:
method "GET" is the only supported method at this time
uri the location of the file to fetch
async true is the only legal value at this time
FileRequest.send ( )

Send the request. Unlike XMLHttpRequest the onreadystatechange callback will be called no matter what, with success or failure.


Member Property Documentation

string FileRequest.className [inherited from o3d.ObjectBase]

The concrete class name for an object derived from ObjectBase. If you want to know if an object is of a certain type you should use objectBase.isAClassName

var t = pack.createObject('o3d.Transform');
t.className == 'o3d.Transform';  // true
This property is read-only.
number FileRequest.clientId [inherited from o3d.ObjectBase]

Unique id of the object. This id will be unique, even across multiple O3D clients in the same page. This property is read-only.

o3d.RawData FileRequest.data

On completion of successful RawData file loads, this holds the loaded RawData. This property is read-only.

boolean FileRequest.done

This indicates whether any further processing will be done on this FileRequest. This property is read-only.

string FileRequest.error

An error message. If done is true and success is false this will be an error message describing what went wrong. This property is read-only.

boolean FileRequest.generateMipmaps [**DEPRECATED**]

Whether or not to generate mip-maps on textures that are loaded (default: true). Mip-maps are not generated for DXTC textures. DDS files can contain pre-computed mip-maps for DXTC textures though. Loading textures through FileRequest is depreated.

function(): void FileRequest.onreadystatechange

A callback to call whenever the ready state of the request changes. This property is write-only.

number FileRequest.readyState

This holds the same values as in XMLHttpRequest:

  • 0 = uninitialized
  • 1 = opened
  • 2 = sent
  • 3 = receiving
  • 4 = loaded (the file has been downloaded, but may or may not have been parsed yet) This property is read-only.
  • boolean FileRequest.success

    This field is only valid if done is true. It indicates whether or not the request succeeded. If it failed error holds an error message. This property is read-only.

    o3d.Texture FileRequest.texture [**DEPRECATED**]

    On completion of successful texture file loads, this holds the loaded texture. Loading textures through FileRequest is depreated.

    string FileRequest.uri

    The URI this request is for. This property is read-only.