O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing Runtime Loaded .swf Assets

To remove a runtime-loaded .swf asset from an application, we must first nullify all references the application has to the asset and then either nullify all references the application has to the Loader object that loaded the asset or invoke unload( ) on the Loader object that loaded the asset.

However, before we remove the asset from the application, we must disable the asset and its display children, if any, so that it does not continue to consume system and network resources once removed.

The typical tasks required to disable a loaded .swf asset are divided between the application that loaded the asset and the asset itself. The application that loaded the asset should perform the following tasks before removing the asset:

  • If the asset is still loading, the application must stop the load operation. For example:

    try {
      theAssetLoader.close();
    } catch (e:*) {}
  • As part of nullifying all references to the asset, the application must remove the asset from all parent DisplayObjectContainer instances. For example:

    container.removeChild(theAsset);

The asset, itself, should perform the following tasks before being removed:

  • Tell any loaded .swf child assets to disable themselves.

  • Stop any sounds from playing.

  • Stop the main timeline, if it is currently playing.

  • Stop any movie clips that are currently playing.

  • Close any connected network objects, such as instances of Loader, URLLoader, Socket, XMLSocket, LocalConnection, NetConnections, and NetStream.

  • Nullify all references ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required