PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/com/lele/Manager/ActivityManager.as

https://gitlab.com/Treeky-NULL/LezaiNiubi
ActionScript | 222 lines | 188 code | 23 blank | 11 comment | 21 complexity | d1dae109b27d121a505664070800c0cc MD5 | raw file
  1. package com.lele.Manager
  2. {
  3. import com.lele.Activity.Interface.*;
  4. import com.lele.Activity.ActivityData.*;
  5. import com.lele.Container.ActivityContainer;
  6. import com.lele.Container.ContainerBase;
  7. import com.lele.Data.GloableData;
  8. import com.lele.Manager.Events.APIEvent;
  9. import com.lele.Manager.Interface.*;
  10. import flash.display.*;
  11. import flash.events.*;
  12. import flash.net.URLRequest;
  13. public class ActivityManager extends Object implements IReport,IActivityManagerFuncer
  14. {
  15. private var _movUnits:Array;
  16. private var _report:IReport;
  17. private var _resourceLoader:IResourceLoader;
  18. private var _activityUnits:Array;
  19. private var _movContainer:ActivityContainer;//同时装载Movie和对话框
  20. private var _backGroundSp:Sprite;
  21. private var _styleBarSp:Sprite;
  22. private var _misDialogSp:Sprite;
  23. private var _styleBar:Sprite;
  24. private var _bgLoader:Loader;
  25. private var _misDialogClass:Class;
  26. private var _misDialog:INpcDialog;
  27. private var _bloodBarClass:Class;
  28. //关于,水战活动,blood <0时,表示不显示血条,即没有进入水战模式,那么,服务器端初始值为-1,玩家加入时,多加一个信息段 blood
  29. public function ActivityManager(loader:IResourceLoader, repoter:IReport,highMovContainer:ActivityContainer)//暂时不给Lezaisp 加载调用资源文件直接的权限
  30. {
  31. _movContainer = highMovContainer;
  32. _backGroundSp = _movContainer.GetContainer();
  33. _styleBarSp = _movContainer.GetContainer();
  34. _styleBar = new Sprite();
  35. _styleBar.graphics.beginFill(0x000000);
  36. _styleBar.graphics.drawRect(0, 0, 960, 60);
  37. _styleBar.graphics.drawRect(0, 480, 960, 60);
  38. _styleBar.graphics.endFill();
  39. _misDialogSp = _movContainer.GetContainer();
  40. _bgLoader = new Loader();
  41. _activityUnits = new Array();
  42. _movUnits = new Array();
  43. _resourceLoader = loader;
  44. _report = repoter;
  45. //load dialog
  46. var temploader:Loader = new Loader();
  47. temploader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnMisDialogLoaded);
  48. var request:URLRequest = new URLRequest("Activity/Res/MissionDialog_app.swf");
  49. temploader.load(request);
  50. //load blood bar
  51. var bloodBarLoader:Loader = new Loader();
  52. bloodBarLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnBloodBarLoaded);
  53. var bloodBarReq:URLRequest = new URLRequest("Activity/Res/BloodBar_app.swf");
  54. bloodBarLoader.load(bloodBarReq);
  55. }
  56. private function OnMisDialogLoaded(evt:Event)
  57. {
  58. (evt.target as LoaderInfo).removeEventListener(Event.COMPLETE, OnMisDialogLoaded);
  59. _misDialogClass = (evt.target as LoaderInfo).applicationDomain.getDefinition("MisDialog") as Class;
  60. _misDialog = new _misDialogClass();
  61. _misDialog.Container = _misDialogSp;
  62. }
  63. private function OnBloodBarLoaded(evt:Event)
  64. {
  65. (evt.target as LoaderInfo).removeEventListener(Event.COMPLETE, OnBloodBarLoaded);
  66. _bloodBarClass = (evt.target as LoaderInfo).applicationDomain.getDefinition("Bar") as Class;
  67. }
  68. ///接口方法
  69. public function CleanThis(unit:ActivityUnit)
  70. {
  71. for (var a:int = 0; a < _activityUnits.length; a++ )
  72. {
  73. if (_activityUnits[a] == unit)
  74. {
  75. _activityUnits.splice(a, 1);
  76. return;
  77. }
  78. }
  79. }
  80. public function ShowBg(url:String)
  81. {
  82. _bgLoader.unloadAndStop();
  83. _bgLoader = new Loader();
  84. var request:URLRequest = new URLRequest(url);
  85. var comp:Function=function(evt:Event)
  86. {
  87. while (_backGroundSp.numChildren > 0) { _backGroundSp.removeChildAt(0); }
  88. _backGroundSp.addChild(evt.target.content);
  89. _bgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, comp);
  90. }
  91. _bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, comp);
  92. _bgLoader.load(request);
  93. }
  94. public function HideBg()
  95. {
  96. while (_backGroundSp.numChildren > 0) { _backGroundSp.removeChildAt(0); }
  97. _bgLoader.unloadAndStop();
  98. _bgLoader = new Loader();
  99. }
  100. public function ShowStyleBar()
  101. {
  102. while (_styleBarSp.numChildren > 0) { _styleBarSp.removeChildAt(0); }
  103. _styleBarSp.addChild(_styleBar);
  104. }
  105. public function HideStyleBar()
  106. {
  107. while (_styleBarSp.numChildren > 0) { _styleBarSp.removeChildAt(0); }
  108. }
  109. //加载并播放视频
  110. public function LoadPlayMovie(url:String, useUI:Boolean = false, UIType:String = "NULL", onFinish:Function = null)
  111. {
  112. var movu:MovieUnit = new MovieUnit(_resourceLoader, onFinish, url, _movContainer.GetContainer(), useUI, UIType);
  113. _movUnits.push(movu);
  114. }
  115. public function OnReport(event:Event) : void
  116. {
  117. return;
  118. }
  119. //加载并开始活动
  120. public function LoadStartActivity(url:String)
  121. {
  122. var actUnit:ActivityUnit = new ActivityUnit(_resourceLoader, this);
  123. if (_misDialogClass != null)
  124. {
  125. actUnit._IMisDialog = _misDialog;
  126. }
  127. actUnit.LoadStart(url);
  128. }
  129. //initMisDialog
  130. public function InitMisDialog(icoUrl:Array,place:Array, name:String, msg:String,msgCallBack:Function, options:Array, callBacks:Array)//icoUrl:Array,place:Array, name:String, msg:Array, options:Array, callBacks:Array
  131. {
  132. if (_misDialog == null) { return; }
  133. _misDialog.Init(icoUrl, place, name, msg,msgCallBack, options, callBacks);
  134. }
  135. //showMisDialog
  136. public function ShowMisDialog()
  137. {
  138. if (_misDialog != null) { _misDialog.Show(); }
  139. }
  140. //hideMisDialog
  141. public function HideMisDialog()
  142. {
  143. if (_misDialog != null) { _misDialog.Hide(); }
  144. }
  145. //dispose
  146. public function DisposeMisDialog()
  147. {
  148. if (_misDialog != null) { _misDialog.Dispose();}
  149. }
  150. //水战活动部分
  151. public function GetBloodBar(x:Number=0, y:Number=0):Object
  152. {
  153. if (_bloodBarClass != null)
  154. {
  155. var bar = new _bloodBarClass();
  156. bar.x = x;
  157. bar.y = y;
  158. return bar;
  159. }
  160. return null;
  161. }
  162. }
  163. }
  164. import flash.events.Event;
  165. import flash.display.Sprite;
  166. import flash.display.MovieClip;
  167. import com.lele.Manager.Interface.IResourceLoader
  168. class MovieUnit extends Object
  169. {
  170. private var _resourceLoader:IResourceLoader;
  171. private var _onFinish:Function;
  172. private var _container:Sprite;
  173. private var _unitUrl:String;
  174. private var _mov:MovieClip;
  175. function MovieUnit(loader:IResourceLoader, onFinish:Function, url:String, container:Sprite, useUI:Boolean, UIType:String)
  176. {
  177. _container = container;
  178. _onFinish = onFinish;
  179. _unitUrl = url;
  180. _resourceLoader = loader;
  181. _resourceLoader.LoadResource("ActivityManager", url, OnComplete, useUI, UIType);
  182. }
  183. private function OnComplete(event:Event)
  184. {
  185. var evt:Event = event;
  186. _mov = evt.target.content as MovieClip;
  187. _container.addChild(_mov);
  188. _mov.addFrameScript((_mov.totalFrames - 1), function ()
  189. {
  190. _mov.stop();
  191. _container.removeChild(_mov);
  192. if (_onFinish != null)
  193. {
  194. _onFinish();
  195. }
  196. _resourceLoader.UnLoadResource("ActivityManager", _unitUrl);
  197. });
  198. }
  199. }