MovieManager
| Kind of class: | class |
|---|---|
| Inherits from: | Dispatcher |
| Classpath: | org.asapframework.management.movie.MovieManager |
| File last modified: | Monday, 06 November 2006, 08:09:15 |
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
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 broadcast to listeners:
MovieManagerEvent with type:
MovieManagerEvent with type:
MovieManagerEvent with type:
ON_MOVIE_INITIALIZED MovieManagerEvent with type:
ON_MOVIE_READY MovieManagerEvent with type:
ON_MOVIE_LOADED Summary
Instance properties
Instance properties inherited from Dispatcher
Class methods
Instance properties
loader
loader:Loader
(read,write)
The org.asapframework.util.loader.Loader loader class used by MovieManager.
Class methods
getInstance
static function getInstance (
) : MovieManager
Access point for the one instance of the MovieManager
Instance methods
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
getNearestLocalController
function getNearestLocalController (
inSender:Object) : LocalController
Retrieve a local controller from the scope of an object.
Finds the first local controller
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
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
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.
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
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 broadcast to listeners:
MovieManagerEvent with type:
ON_MOVIE_INITIALIZED 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
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
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