Game Development Reference
In-Depth Information
Working with Multiple SWF Files
At some point, you
ll probably be in the position of using multiple
SWF files to support a game. Perhaps you have multiple game
levels, each in their own SWF, or you have externalized all your
need to use a Loader object, which is part of the display package.
The syntax looks like the following:
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.MovieClip;
public class LoaderExample extends Sprite {
protected var resourceLoader:Loader;
protected var resources:MovieClip;
public function LoaderExample() {
protected function loadResources():void {
if (!resourceLoader) resourceLoader = new
resourceLoader.load(new URLRequest
( Event.COMPLETE, resourcesComplete, false, 0, true);
protected function resourcesComplete(e:Event):void {
resources = as MovieClip;
protected function unloadResources():void {
In the loadResources method of this example, a new Loader
object is created (if one doesn
t already exist) and is used to load a
SWF named
A listener is then added to the
s contentLoaderInfo object, which will dispatch events about
the Loader
s progress. Once the load has completed, the resources
variable is assigned to the content of the Loader. If at some point
the data needs to be unloaded, the method unloadResources can
be called to dump the SWF. Developers familiar with AS3 already
will note that the new unloadAndStop, introduced in CS4, is a big
Search Nedrilad ::

Custom Search