MovieManager

Kind of class:class
Inherits from:Dispatcher
Classpath:org.asapframework.management.movie.MovieManager
File last modified:Sunday, 05 November 2006, 11:40:08
The MovieManager handles administration, loading and retrieving of separate SWF movies.

Start the loading process by calling loadMovie.
After this, three events of type MovieManagerEvent can be expected: when the movie has initialized, has been loaded, and is ready.
Ready is defined as both initialized and loaded.

Once a movie has been loaded, its localController can be retrieved by name or by backtracing from any point within any movieclip to its nearest localController.

A typical sequence of events will be:
  • loadMovie is called with an SWFData block containing a container movieclip, a name and an url
  • the SWF starts being loaded
  • the code in the first frame of the loaded movie is run, usually creating a LocalController
  • movieCreated is called by the LocalController object, the controller gets its name from the data block loadMovie was called with, the controller is known to the MovieManager
  • onLoadDone is called by the loader, indicating 100% of the SWF has been loaded; the event onMovieLoaded is broadcast
  • movieInitialized is called by the LocalController object, indicating the controller is done initializing and ready to start; the event "onMovieInitialized" is broadcast
  • when the movie has been loaded and initialized, the event onMovieReady is broadcast
Note that it is left up to whoever loads the movie, or controls the application, or to the loaded movie itself, to actually start the movie.

Naming of movies:
- use a unique name for each movie
- use publicly accessible constants for movie names. This makes it easier to change names throughout the application.
- the name has to be given when loading the movie with MovieManager.getInstance().loadMovie().
This means the local controller of a standalone running movie does not have a name.
This can be circumvented (if necessary) by giving the local controller its name locally when it is running standalone.
ILocalController has a function isStandalone() for checking this.
Usage:
  • This example shows an application controller (subclass of LocalController) that loads a menu SWF:
    class MovieNames {
        public static var NAME_APPLICATION:String = "application";
        public static var NAME_MENU:String = "menu";
    
        public static var URL_MENU:String = "menu.swf";
    }
    
    class AppController extends LocalController {  
        public function AppController (inTimeLine:MovieClip) {
            super(inTimeLine);
    
            // Set name of controller so other controllers can find the reference of this by name if necessary
            setName(MovieNames.NAME_APPLICATION); 
    
            // listen for event when movies are loaded and ready to play
            MovieManager.getInstance().addEventListener(MovieManagerEvent.ON_MOVIE_READY, EventDelegate.create(this, handleMovieReady));
            // load the menu movie and give it the name specified in MovieNames.NAME_MENU
            MovieManager.getInstance().loadMovie( MovieNames.NAME_MENU, MovieNames.URL_MENU, inTimeLine.swfholder, true);
        }
    
        private function handleMovieReady (e:MovieManagerEvent) {
            Log.info("handleMovieReady: movie with name = '" + e.name + "' has been loaded.", toString());
        }
    }
Events broadcasted to listeners:

Summary


Constructor
Class properties
Instance properties
Class methods
Instance methods
  • loadMovie (inName:String, inURL:String, inMovieClip:MovieClip, inIsVisible:Boolean) : Boolean
    • Start loading the movie with path inSource.url into movieclip inSource.mc, and adds it to the list of movies under the name inSource.name
  • showMovie (inName:String) : Boolean
    • Tries to find the movie with the specified name and shows it if it has loaded and started the movie is approached through the LocalController of the movie, and not shown directly
  • hideMovie (inName:String) : Boolean
    • Tries to find the movie with the specified name and hides it if it has loaded and started the movie is approached through the LocalController of the movie, and not hidden directly.
  • isMovieLoaded (inName:String) : Boolean
    • Looks for the movie and checks whether it has been loaded
  • removeMovie (inMovie:Object, inShouldRemoveMovieClip:Boolean) : Boolean
    • Tries to find the movie with the specified identifier, empties the attached movieclip and removes the movie data from the list after this action, a movie has to be loaded again using loadMovieInClip it is not checked whether a movie is being loaded, has been loaded or has been started, so this is tricky when a movie is in the loader
  • getNearestLocalController (inSender:Object) : LocalController
    • Retrieve a local controller from the scope of an object.
  • getLocalControllerWithName (inName:String) : LocalController
    • Finds a local controller by name
  • movieCreated (inCtrl:LocalController, inMC:MovieClip) : Void
    • Handles the event sent by local controllers to notify that the local controller that sends the event has been created.
  • handleControllerNameChanged (inCtrl:LocalController, inName:String) : Void
    • Handles the event sent by local controllers that their name has been set externally.
  • movieInitialized (inCtrl:LocalController) : Void
    • Handles the event sent by local controllers to notify that the local controller that sends the event has initialized.
  • addMovie (inName:String, inURL:String, inMovieClip:MovieClip) : Boolean
    • Adds a movie with specified properties to the list, after checking if a movie with the same name exists already Note: If you want to re-use the same movieclip for multiple SWFs, use removeMovie; otherwise use a different movieclip holder for each loaded SWF.
  • checkProgress (inData:MovieData) : Void
    • Check whether the movie has been created, loaded and initialized.
  • getMcData (inName:String) : MovieData
    • Retrieves the movie data for the movie specified by the identifier
  • getMcDataForMovieClip (inMc:MovieClip) : MovieData
    • Retrieves the movie data for the movie specified by a movieclip reference
  • getMovieIndex (inName:String) : Number
    • Retrieves in the list the index of the movie specified by the identifier
  • toString : String
Event handlers
  • onLoadDone (e:LoaderEvent) : Void
    • Handles the event sent by the loader to notify that the movie has been loaded (100%) if the movie with the specified name is found, the movie is set to "loaded"
  • onLoadError (e:LoaderEvent) : Void
    • Handles the event sent by the loader to notify that there was an error loading the file

Constructor

MovieManager

private function MovieManager (
)

Private constructor

Class properties

sInstance

static private sInstance:MovieManager = null
(read)

Instance properties

loader

loader:Loader
(read,write)

The org.asapframework.util.loader.Loader loader class used by MovieManager.

mControllerCache

private mControllerCache:Object
(read)

mLoader

private mLoader:Loader
(read)

mMovies

private mMovies:Array
(read)

Contains a list of objects of type org.asapframework.moviemanagement.MovieData

Class methods

getInstance

static function getInstance (

Access point for the one instance of the MovieManager

Instance methods

addMovie

private function addMovie (
inName:String, inURL:String, inMovieClip:MovieClip) : Boolean

Adds a movie with specified properties to the list, after checking if a movie with the same name exists already
Note: If you want to re-use the same movieclip for multiple SWFs, use removeMovie; otherwise use a different movieclip holder for each loaded SWF.
Parameters:
inName :
unique identifying name for the movie to be loaded
inURL :
url where the swf can be found
inMovieClip:
movieclip object in which the swf is to be loaded
Returns:
  • false if another movie with the same name exists in the list, otherwise true

checkProgress

private function checkProgress (
inData:MovieData) : Void

Check whether the movie has been created, loaded and initialized.
If so, send event onMovieReady
Parameters:
inData:
MovieData, the data block for the movie to be checked
Events broadcasted to listeners:

getLocalControllerWithName

function getLocalControllerWithName (
inName:String) : LocalController

Finds a local controller by name
Parameters:
inName:
unique identifier for the loaded movie
Returns:
  • The controller for that movie, or null if none was found

getMcData

private function getMcData (
inName:String) : MovieData

Retrieves the movie data for the movie specified by the identifier
Parameters:
inName:
the name to be used as identifier
Returns:
  • null if the movie data was not found, otherwise an object of type MovieData

getMcDataForMovieClip

private function getMcDataForMovieClip (
inMc:MovieClip) : MovieData

Retrieves the movie data for the movie specified by a movieclip reference
Parameters:
inMc:
the movieclip reference
Returns:
  • null if the movie data was not found, or an object of type MovieData

getMovieIndex

private function getMovieIndex (
inName:String) : Number

Retrieves in the list the index of the movie specified by the identifier
Parameters:
inName:
the name to be used as identifier
Returns:
  • the index in the list, or -1 if the movie data was not found

getNearestLocalController

function getNearestLocalController (
inSender:Object) : LocalController

Retrieve a local controller from the scope of an object.
Finds the first local controller
Parameters:
inSender:
object or movieclip or button
Returns:
  • The first local manager upwards in the parent chain, starting from the sender object.
Implementation note:
  • Because the lookup of the manager can (in some cases)
    be expensive, the found managers are stored in an associative array. When
    this method is called, the array is first consulted.

    Note Stephan: the way it is implemented now, it doesn't work. The original inSender is lost after the first _parent.
    Once this has been cleared, removeMovie has to be extended to include proper cache emptying

handleControllerNameChanged

function handleControllerNameChanged (
inCtrl:LocalController, inName:String) : Void

Handles the event sent by local controllers that their name has been set externally.
This updates the internal data with the new name
Parameters:
inCtrl:
the local controller whose name has been changed

hideMovie

function hideMovie (
inName:String) : Boolean

Tries to find the movie with the specified name and hides it if it has loaded and started
the movie is approached through the LocalController of the movie, and not hidden directly.
Parameters:
inName:
the name used as identifier for the movie to be hidden
Returns:
  • false if the movie wasn't found, loaded or started; true otherwise

isMovieLoaded

function isMovieLoaded (
inName:String) : Boolean

Looks for the movie and checks whether it has been loaded
Parameters:
inName:
the name used as identifier for the movie
Returns:
  • false if the movie wasn't found or wasn't loaded, otherwise true

loadMovie

function loadMovie (
inName:String, inURL:String, inMovieClip:MovieClip, inIsVisible:Boolean) : Boolean

Start loading the movie with path inSource.url into movieclip inSource.mc, and adds it to the list of movies under the name inSource.name
Parameters:
inName :
unique identifying name for the movie to be loaded
inURL :
url where the swf can be found
inMovieClip:
movieclip object in which the swf is to be loaded; must not be _level0, or your application will behave erratically.
inIsVisible:
true if the movie has to be made visible when loaded
Returns:
  • false if the loader cannot load the movie, or the movie could not be added to the list (usually because another or the same movie with the same name exists already), otherwise true

movieCreated

function movieCreated (
inCtrl:LocalController, inMC:MovieClip) : Void

Handles the event sent by local controllers to notify that the local controller that sends the event has been created.
Initializes the name of the controller by setting it to the name that the movie was loaded by.
If no data block was found for the input clip, a new data block is created, with the name of the movieclip as name
Parameters:
inCtrl:
the local controller of the movie clip that has been created

movieInitialized

function movieInitialized (
inCtrl:LocalController) : Void

Handles the event sent by local controllers to notify that the local controller that sends the event has initialized.
Parameters:
inCtrl:
LocalController, the local controller of the movie clip that has been initialized
Events broadcasted to listeners:

removeMovie

function removeMovie (
inMovie:Object, inShouldRemoveMovieClip:Boolean) : Boolean

Tries to find the movie with the specified identifier, empties the attached movieclip and removes the movie data from the list
after this action, a movie has to be loaded again using loadMovieInClip
it is not checked whether a movie is being loaded, has been loaded or has been started, so this is tricky when a movie is in the loader
Parameters:
inMovie :
either :String: the name used as identifier for the movie to be removed, or :MovieClip: the movieclip reference
inShouldRemoveMovieClip:
the movieclip holder will be removed too; but then this movieclip cannot be used again; default false
Returns:
  • false if the movie wasn't found, true otherwise

showMovie

function showMovie (
inName:String) : Boolean

Tries to find the movie with the specified name and shows it if it has loaded and started
the movie is approached through the LocalController of the movie, and not shown directly
Parameters:
inName:
the name used as identifier for the movie to be shown
Returns:
  • false if the movie wasn't found, loaded or started; true otherwise

toString

function toString (
) : String

Event handlers

onLoadDone

private function onLoadDone (
e:LoaderEvent) : Void

Handles the event sent by the loader to notify that the movie has been loaded (100%)
if the movie with the specified name is found, the movie is set to "loaded"
Parameters:
e:
event object with members: .name, .type, .target
Events broadcasted to listeners:

onLoadError

private function onLoadError (
e:LoaderEvent) : Void

Handles the event sent by the loader to notify that there was an error loading the file
Parameters:
e:
event object with members: .name, .type, .target