O'Reilly logo

ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, Keith Peters

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

Loading and Interacting with External Movies

Problem

You want to load, and be able to interact with, an external .swf movie into your own movie.

Solution

Use the new Loader class to load the .swf file, and then access the .swf file via the content property of the Loader instance.

Discussion

Recipe 6.6 demonstrates how to load external images via the Loader class. Loading external .swf movies uses the same technique—by calling the load() method on a Loader instance and passing a URL to a .swf instead of an image, the .swf is loaded into the movie. If the Loader is in the main display hierarchy, the .swf also appears on-screen.

This recipe involves creating two separate .swf files, ExternalMovie.swf and LoaderExample.swf. The first movie, ExternalMovie.swf, will be loaded at runtime into the second movie, LoaderExample.swf. The code for ExternalMovie.swf is as follows:

package { import flash.display.Sprite; import flash.display.Shape; public class ExternalMovie extends Sprite { private var _color:uint = 0x000000; private var _circle:Shape; public function ExternalMovie() { updateDisplay(); } private function updateDisplay():void { // If the circle hasn't been created yet, create it // and make it visible by adding it to the display list if ( _circle == null ) { _circle = new Shape(); addChild( _circle ); } // Clear any previously drawn content and draw // a new circle with the fill color _circle.graphics.clear(); _circle.graphics.beginFill( _color ); _circle.graphics.drawCircle( 100, ...

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