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 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:
There are several downsides to accessing resources at runtime:
Away3D supports the use of both embedded and external resources, and both methods will be demonstrated below.
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.