PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DiegoRay/actionscripts/org/asapframework/management/movie/LocalController.as

https://github.com/joemaffia/flash-junk
ActionScript | 181 lines | 50 code | 22 blank | 109 comment | 3 complexity | 912df60ccf98799d6525ed748a28f35f MD5 | raw file
  1. /*
  2. Copyright 2005-2006 by the authors of asapframework, http://asapframework.org
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // ASAP classes
  14. import org.asapframework.events.Dispatcher;
  15. import org.asapframework.management.movie.ILocalController;
  16. import org.asapframework.management.movie.MovieManager;
  17. import org.asapframework.util.debug.Log;
  18. /**
  19. (Virtual) base class for controlling movies locally, either independently or embedded.
  20. Extend this class for each separate movie in your project that requires certain complex controlled functionality.
  21. The base class takes care of communication with the MovieManager, so the movie is known to other movies.
  22. The LocalController functions as controller for everything that happens locally.
  23. For other movies, it functions as a Facade, hiding implementation of details.
  24. The preferred mode of communication with the LocalController is through events, to avoid having to know the actual specific interface.
  25. */
  26. class org.asapframework.management.movie.LocalController extends Dispatcher implements ILocalController {
  27. /** Name identifier. */
  28. private var mName:String;
  29. /** Movieclip that is controlled by the LocalController. */
  30. private var mTimeline:MovieClip;
  31. /**
  32. Constructor, performs basic initialization, and notifies the MovieManager that the movie has been created.
  33. Gets its name from the MovieManager.
  34. @param inTimeline : movieclip that is controlled by the LocalController, usually the timeline reference from where the LocalController is created
  35. @example
  36. On the timeline:
  37. <code>
  38. HistoryController.main(this);
  39. </code>
  40. Inside the class HistoryController:
  41. <code>
  42. class HistoryController extends LocalController {
  43. public function HistoryController (inTimeline:MovieClip) {
  44. super(inTimeline);
  45. // let MovieManager know initialization is done
  46. notifyMovieInitialized();
  47. }
  48. // the main entry point of the application
  49. public static function main (inTimeline:MovieClip) : Void {
  50. var controller:HistoryController = new HistoryController(inTimeline);
  51. }
  52. public function toString() {
  53. return ";HistoryController";
  54. }
  55. }
  56. </code>
  57. */
  58. public function LocalController (inTimeline:MovieClip) {
  59. super();
  60. // block out the empty constructor call
  61. if (inTimeline == undefined) {
  62. Log.error("Constructor: Specify timeline to be controlled", toString());
  63. return;
  64. }
  65. mTimeline = inTimeline;
  66. // notify the MovieManager of creation; the name of this controller is set by the MovieManager
  67. MovieManager.getInstance().movieCreated(this, mTimeline);
  68. }
  69. /**
  70. Let the MovieManager know that the movie is done initializing.
  71. In specific circumstances you may need to wait at least one enterFrame before calling this (for example using {@link FrameDelay}).
  72. */
  73. public function notifyMovieInitialized () : Void {
  74. MovieManager.getInstance().movieInitialized(this);
  75. }
  76. /**
  77. Method to perform cleaning up before the LocalController gets deleted.
  78. Default implementation does nothing.
  79. Specific behaviour may be implemented in subclasses.
  80. */
  81. public function kill () : Void {
  82. }
  83. /**
  84. Start the movie. Usually called from the container when onMovieReady event has been received,
  85. Basic behaviour just shows the movie.
  86. Specific behaviour may be implemented in subclasses.
  87. */
  88. public function start () : Void {
  89. show();
  90. }
  91. /**
  92. Stop the movie. Usually called from the container to tell the movie to go away.
  93. Basic behaviour just hides the movie.
  94. Specific behaviour may be implemented in subclasses.
  95. */
  96. public function stop () : Void {
  97. hide();
  98. }
  99. /**
  100. Show the movie.
  101. Basic behaviour sets visibility of the root movieclip to true.
  102. Specific behaviour may be implemented in subclasses.
  103. */
  104. public function show () : Void {
  105. mTimeline._visible = true;
  106. }
  107. /**
  108. Hide the movie.
  109. Basic behaviour sets the visibility of the root movieclip to false.
  110. Specific behaviour may be implemented in subclasses.
  111. */
  112. public function hide () : Void {
  113. mTimeline._visible = false;
  114. }
  115. /**
  116. Gets the name of the LocalController by which it is uniquely identified.
  117. @return The name identifier.
  118. */
  119. public function getName () : String {
  120. return mName;
  121. }
  122. /**
  123. Sets the name of the LocalController by which it is uniquely identified.
  124. @param inName : name
  125. */
  126. public function setName (inName:String) : Void {
  127. mName = inName;
  128. MovieManager.getInstance().handleControllerNameChanged(this, inName);
  129. }
  130. /**
  131. Gets the movieclip that this controller controls.
  132. @return Movieclip
  133. */
  134. public function getTimeline () : MovieClip {
  135. return mTimeline;
  136. }
  137. /**
  138. Return whether the movie that the controller controls, is running embedded or standalone.
  139. @return True: the movie is running standalone; false: the movie is running embedded.
  140. */
  141. public function isStandalone () : Boolean {
  142. return (mTimeline == _level0);
  143. }
  144. /**
  145. */
  146. public function toString () : String {
  147. return ";org.asapframework.management.movie.LocalController : name = '" + mName + "'";
  148. }
  149. }