Resource management

Quite a number of the materials included in Away3D rely on textures that exist in external image like a PNG, JPG, or GIF file. There are two ways of dealing with external files: embedding them or accessing them at runtime.

ActionScript includes the Embed keyword, which can be used to embed external files directly inside a compiled SWF file. There are a number of benefits to embedded resources:

  • The Flash application can be distributed as a single file
  • There is no wait when accessing the resources at runtime
  • The security issues associated with accessing remote resources are avoided
  • There is no additional network traffic once the SWF is downloaded
  • The SWF file can be run offline
  • The embedded files can have additional compression applied

The downside to embedding resources is that the size of the final SWF is increased, resulting in a longer initial download time.

Alternatively, the external files can be saved separately and accessed at runtime, which has the following advantages:

  • The SWF file is smaller, resulting in shorter initial download times
  • Resources are only downloaded when they are needed, and cached for future access
  • Resources can be updated or modified without recompiling the SWF file

There are several downsides to accessing resources at runtime:

  • Permissions on the server hosting the resources may need to be configured before the external files can be accessed
  • Distribution of the final Flash application is more difficult due to the increased number of individual files
  • There will be a delay when the application is run as the remote resources are downloaded

Away3D supports the use of both embedded and external resources, and both methods will be demonstrated below.

Tip

Embedding the resources is usually the best option when managing resources. It prevents a number of possible errors due to unreliable networks and security restrictions, and produces a SWF file that is much simpler to distribute and publish.

However, for applications where it is not possible to know what resources will be required beforehand, like a 3D image gallery, loading external resources is the only option. You may also want to load external resources for applications where there is a large volume of data that does not need to be downloaded immediately, like a large game with levels that the player won't necessarily see in a single sitting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.225.220