My favorites | English | Sign in

o3d.ArchiveRequest Class Reference

Inherits o3d.ObjectBase

List of all members.


Detailed Description

An ArchiveRequest object is used to carry out an asynchronous request for a compressed archive (containing multiple files). Note: The archive must have as its first file a file named 'aaaaaaaa.o3d' who's contents is 'o3d'. This is to prevent O3D being used to open archive files that were not meant for it.
var request = pack.createArchiveRequest();
request.open("GET", url);

request.onfileavailable = myFileAvailableCallback;
request.onreadystatechange = myReadyStateChangeCallback;
request.send();

function myFileAvailableCallback(rawData) {
  dump("uri: " + rawData.uri + "\n");
  dump("content: " + rawData.stringValue + "\n");

  // You can pass a RawData to various creation functions. Note: rawData
  // is only valid until you remove the request.
  // Examples:
  if (rawData.uri == 'mytexture.jpg')
    pack.createTexture2d(rawData, makeMips);
  if (rawData.uri == 'myvertices.bin')
    vertexBuffer.set(rawData);
  if (rawData.uri == 'myAudio.mp3')
    audioSystem.createSound(rawData);
}

function myReadyStateChangeCallback() {
  if (request.done) {
    if (request.success) {
      // there were no errors trying to read the archive
    } else {
      dump(request.error);
    }
  }
}

// When you are done with the RawDatas loaded by the request, remove
// the request from the pack to free them.
pack.removeObject(request);

Public Member Functions

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

Public Properties

number bytesReceived o3d.ArchiveRequest
string className o3d.ObjectBase
number clientId o3d.ObjectBase
o3d.RawData data [**DEPRECATED**] o3d.ArchiveRequest
boolean done o3d.ArchiveRequest
string error o3d.ArchiveRequest
function(!o3d.RawData): void onfileavailable o3d.ArchiveRequest
function(): void onreadystatechange o3d.ArchiveRequest
number readyState o3d.ArchiveRequest
number streamLength o3d.ArchiveRequest
boolean success o3d.ArchiveRequest
string uri o3d.ArchiveRequest

Member Function Documentation

boolean ArchiveRequest.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.
ArchiveRequest.open ( string method
string uri )

Sets 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
ArchiveRequest.send ( )

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


Member Property Documentation

number ArchiveRequest.bytesReceived

The number of bytes downloaded so far. You can use this value along with streamLength to figure out the download progress. This property is read-only.

string ArchiveRequest.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 ArchiveRequest.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 ArchiveRequest.data [**DEPRECATED**]

A RawData object representing the file that is currently available. Note: This value is only valid inside the onfileavailable callback. Note: This property is deprecated. It is now an argument of the onfileavailable callback.

boolean ArchiveRequest.done

Indicates whether processing for this FileRequest has finished. This property is read-only.

string ArchiveRequest.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.

function(!o3d.RawData): void ArchiveRequest.onfileavailable

A callback that gets called each time a file fully downloads and becomes available. This property is write-only.

function(): void ArchiveRequest.onreadystatechange

A callback that gets called each time readyState changes. This property is write-only.

number ArchiveRequest.readyState

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.
  • number ArchiveRequest.streamLength

    The length of the entire archive in bytes. Use this value along with bytesReceived to figure out the download progress. This property is read-only.

    boolean ArchiveRequest.success

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

    string ArchiveRequest.uri

    The uri of the archive being downloaded. This property is read-only.