@awayjs/scene 0.13.265 → 0.13.266

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/.eslintrc +100 -100
  2. package/README.md +61 -61
  3. package/bundle/awayjs-scene.umd.js +2 -2
  4. package/bundle/awayjs-scene.umd.js.map +1 -1
  5. package/copyVersionToIndex.js +23 -23
  6. package/dist/index.d.ts +76 -75
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +67 -66
  9. package/dist/lib/Scene.d.ts +84 -84
  10. package/dist/lib/Scene.js +288 -288
  11. package/dist/lib/Settings.d.ts +16 -16
  12. package/dist/lib/Settings.js +60 -60
  13. package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
  14. package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
  15. package/dist/lib/adapters/IFilter.d.ts +24 -24
  16. package/dist/lib/adapters/IFilter.js +1 -1
  17. package/dist/lib/adapters/IMovieClipAdapter.d.ts +14 -14
  18. package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
  19. package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
  20. package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
  21. package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
  22. package/dist/lib/base/IBitmapDrawable.js +1 -1
  23. package/dist/lib/base/IFrameLabel.d.ts +4 -4
  24. package/dist/lib/base/IFrameLabel.js +1 -1
  25. package/dist/lib/base/IFrameScript.d.ts +5 -5
  26. package/dist/lib/base/IFrameScript.js +1 -1
  27. package/dist/lib/base/MouseButtons.d.ts +26 -22
  28. package/dist/lib/base/MouseButtons.d.ts.map +1 -1
  29. package/dist/lib/base/MouseButtons.js +1 -1
  30. package/dist/lib/base/Timeline.d.ts +148 -148
  31. package/dist/lib/base/Timeline.js +535 -535
  32. package/dist/lib/base/TimelineActionType.d.ts +18 -18
  33. package/dist/lib/base/TimelineActionType.js +1 -1
  34. package/dist/lib/controllers/ControllerBase.d.ts +14 -14
  35. package/dist/lib/controllers/ControllerBase.js +60 -60
  36. package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
  37. package/dist/lib/controllers/FirstPersonController.js +228 -228
  38. package/dist/lib/controllers/FollowController.d.ts +12 -12
  39. package/dist/lib/controllers/FollowController.js +27 -27
  40. package/dist/lib/controllers/HoverController.d.ts +105 -105
  41. package/dist/lib/controllers/HoverController.js +302 -302
  42. package/dist/lib/controllers/LookAtController.d.ts +14 -14
  43. package/dist/lib/controllers/LookAtController.js +68 -68
  44. package/dist/lib/controllers/SpringController.d.ts +38 -38
  45. package/dist/lib/controllers/SpringController.js +59 -59
  46. package/dist/lib/display/Billboard.d.ts +147 -147
  47. package/dist/lib/display/Billboard.js +426 -426
  48. package/dist/lib/display/Camera.d.ts +40 -40
  49. package/dist/lib/display/Camera.js +90 -90
  50. package/dist/lib/display/DisplayObject.d.ts +938 -938
  51. package/dist/lib/display/DisplayObject.js +1641 -1641
  52. package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
  53. package/dist/lib/display/DisplayObjectContainer.js +480 -480
  54. package/dist/lib/display/LineSegment.d.ts +84 -84
  55. package/dist/lib/display/LineSegment.js +215 -215
  56. package/dist/lib/display/LoaderContainer.d.ts +504 -504
  57. package/dist/lib/display/LoaderContainer.js +603 -603
  58. package/dist/lib/display/MorphSprite.d.ts +20 -20
  59. package/dist/lib/display/MorphSprite.js +254 -254
  60. package/dist/lib/display/MovieClip.d.ts +152 -152
  61. package/dist/lib/display/MovieClip.js +735 -735
  62. package/dist/lib/display/SimpleButton.d.ts +158 -158
  63. package/dist/lib/display/SimpleButton.js +228 -228
  64. package/dist/lib/display/Skybox.d.ts +156 -156
  65. package/dist/lib/display/Skybox.js +309 -309
  66. package/dist/lib/display/Sprite.d.ts +70 -70
  67. package/dist/lib/display/Sprite.js +144 -144
  68. package/dist/lib/display/TextField.d.ts +1109 -1109
  69. package/dist/lib/display/TextField.js +3109 -3109
  70. package/dist/lib/display/TextSprite.d.ts +10 -10
  71. package/dist/lib/display/TextSprite.js +25 -25
  72. package/dist/lib/elements/SkyboxElements.d.ts +29 -29
  73. package/dist/lib/elements/SkyboxElements.js +127 -127
  74. package/dist/lib/errors/CastError.d.ts +4 -4
  75. package/dist/lib/errors/CastError.js +10 -10
  76. package/dist/lib/events/CameraEvent.d.ts +16 -16
  77. package/dist/lib/events/CameraEvent.js +30 -30
  78. package/dist/lib/events/FocusEvent.d.ts +42 -42
  79. package/dist/lib/events/FocusEvent.js +43 -43
  80. package/dist/lib/events/KeyboardEvent.d.ts +21 -21
  81. package/dist/lib/events/KeyboardEvent.js +43 -43
  82. package/dist/lib/events/MouseEvent.d.ts +91 -184
  83. package/dist/lib/events/MouseEvent.d.ts.map +1 -1
  84. package/dist/lib/events/MouseEvent.js +122 -191
  85. package/dist/lib/events/PointerEvent.d.ts +94 -0
  86. package/dist/lib/events/PointerEvent.d.ts.map +1 -0
  87. package/dist/lib/events/PointerEvent.js +73 -0
  88. package/dist/lib/events/ResizeEvent.d.ts +15 -15
  89. package/dist/lib/events/ResizeEvent.js +38 -38
  90. package/dist/lib/events/TextfieldEvent.d.ts +19 -19
  91. package/dist/lib/events/TextfieldEvent.js +28 -28
  92. package/dist/lib/events/TouchEvent.d.ts +51 -0
  93. package/dist/lib/events/TouchEvent.d.ts.map +1 -0
  94. package/dist/lib/events/TouchEvent.js +83 -0
  95. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +26 -26
  96. package/dist/lib/factories/DefaultSceneGraphFactory.js +54 -54
  97. package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
  98. package/dist/lib/factories/ISceneGraphFactory.js +1 -1
  99. package/dist/lib/image/SceneImage2D.d.ts +236 -236
  100. package/dist/lib/image/SceneImage2D.js +687 -687
  101. package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
  102. package/dist/lib/managers/DefaultFontManager.js +101 -101
  103. package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
  104. package/dist/lib/managers/DeviceFontManager.js +44 -44
  105. package/dist/lib/managers/FrameScriptManager.d.ts +36 -36
  106. package/dist/lib/managers/FrameScriptManager.js +377 -377
  107. package/dist/lib/managers/IInputRecorder.d.ts +3 -3
  108. package/dist/lib/managers/IInputRecorder.js +1 -1
  109. package/dist/lib/managers/MouseManager.d.ts +76 -89
  110. package/dist/lib/managers/MouseManager.d.ts.map +1 -1
  111. package/dist/lib/managers/MouseManager.js +809 -761
  112. package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
  113. package/dist/lib/prefabs/PrefabBase.js +42 -42
  114. package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
  115. package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
  116. package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
  117. package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
  118. package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
  119. package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
  120. package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
  121. package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
  122. package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
  123. package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
  124. package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
  125. package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
  126. package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
  127. package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
  128. package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
  129. package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
  130. package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
  131. package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
  132. package/dist/lib/text/AntiAliasType.d.ts +24 -24
  133. package/dist/lib/text/AntiAliasType.js +28 -28
  134. package/dist/lib/text/BitmapFontChar.d.ts +39 -39
  135. package/dist/lib/text/BitmapFontChar.js +42 -42
  136. package/dist/lib/text/BitmapFontTable.d.ts +80 -80
  137. package/dist/lib/text/BitmapFontTable.js +203 -203
  138. package/dist/lib/text/FNTGenerator.d.ts +10 -10
  139. package/dist/lib/text/FNTGenerator.js +74 -74
  140. package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
  141. package/dist/lib/text/FNTGeneratorCanvas.js +205 -205
  142. package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
  143. package/dist/lib/text/FNTGeneratrorBase.js +7 -7
  144. package/dist/lib/text/Font.d.ts +38 -38
  145. package/dist/lib/text/Font.js +109 -109
  146. package/dist/lib/text/FontLookUpMode.d.ts +5 -5
  147. package/dist/lib/text/FontLookUpMode.js +7 -7
  148. package/dist/lib/text/FontStyleName.d.ts +6 -6
  149. package/dist/lib/text/FontStyleName.js +7 -7
  150. package/dist/lib/text/GridFitType.d.ts +31 -31
  151. package/dist/lib/text/GridFitType.js +35 -35
  152. package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
  153. package/dist/lib/text/HTMLTextProcessor.js +423 -423
  154. package/dist/lib/text/IFontTable.d.ts +16 -16
  155. package/dist/lib/text/IFontTable.js +1 -1
  156. package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
  157. package/dist/lib/text/TesselatedFontChar.js +66 -66
  158. package/dist/lib/text/TesselatedFontTable.d.ts +95 -95
  159. package/dist/lib/text/TesselatedFontTable.js +992 -992
  160. package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
  161. package/dist/lib/text/TextFieldAutoSize.js +32 -32
  162. package/dist/lib/text/TextFieldType.d.ts +20 -20
  163. package/dist/lib/text/TextFieldType.js +24 -24
  164. package/dist/lib/text/TextFormat.d.ts +273 -273
  165. package/dist/lib/text/TextFormat.js +440 -440
  166. package/dist/lib/text/TextFormatAlign.d.ts +26 -26
  167. package/dist/lib/text/TextFormatAlign.js +30 -30
  168. package/dist/lib/text/TextInteractionMode.d.ts +21 -21
  169. package/dist/lib/text/TextInteractionMode.js +25 -25
  170. package/dist/lib/text/TextLineMetrics.d.ts +61 -61
  171. package/dist/lib/text/TextLineMetrics.js +42 -42
  172. package/dist/lib/text/TextShape.d.ts +20 -20
  173. package/dist/lib/text/TextShape.js +75 -75
  174. package/dist/lib/tools/Merge.d.ts +81 -81
  175. package/dist/lib/tools/Merge.js +266 -266
  176. package/dist/lib/utils/Cast.d.ts +20 -20
  177. package/dist/lib/utils/Cast.js +271 -271
  178. package/index.ts +92 -91
  179. package/lib/Scene.ts +343 -343
  180. package/lib/Settings.ts +83 -83
  181. package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
  182. package/lib/adapters/IFilter.ts +25 -25
  183. package/lib/adapters/IMovieClipAdapter.ts +24 -24
  184. package/lib/adapters/ITextfieldAdapter.ts +6 -6
  185. package/lib/base/IBitmapDrawable.ts +13 -13
  186. package/lib/base/IFrameLabel.ts +3 -3
  187. package/lib/base/IFrameScript.ts +4 -4
  188. package/lib/base/MouseButtons.ts +31 -26
  189. package/lib/base/Timeline.ts +727 -727
  190. package/lib/base/TimelineActionType.ts +18 -18
  191. package/lib/controllers/ControllerBase.ts +66 -66
  192. package/lib/controllers/FirstPersonController.ts +241 -241
  193. package/lib/controllers/FollowController.ts +22 -22
  194. package/lib/controllers/HoverController.ts +304 -304
  195. package/lib/controllers/LookAtController.ts +75 -75
  196. package/lib/controllers/SpringController.ts +91 -91
  197. package/lib/display/Billboard.ts +504 -504
  198. package/lib/display/Camera.ts +89 -89
  199. package/lib/display/DisplayObject.ts +1893 -1893
  200. package/lib/display/DisplayObjectContainer.ts +538 -538
  201. package/lib/display/LineSegment.ts +248 -248
  202. package/lib/display/LoaderContainer.ts +651 -651
  203. package/lib/display/MorphSprite.ts +347 -347
  204. package/lib/display/MovieClip.ts +879 -879
  205. package/lib/display/SimpleButton.ts +224 -224
  206. package/lib/display/Skybox.ts +379 -379
  207. package/lib/display/Sprite.ts +165 -165
  208. package/lib/display/TextField.ts +3958 -3958
  209. package/lib/display/TextSprite.ts +22 -22
  210. package/lib/elements/SkyboxElements.ts +141 -141
  211. package/lib/errors/CastError.ts +6 -6
  212. package/lib/events/CameraEvent.ts +29 -29
  213. package/lib/events/FocusEvent.ts +69 -69
  214. package/lib/events/KeyboardEvent.ts +40 -40
  215. package/lib/events/MouseEvent.ts +147 -287
  216. package/lib/events/PointerEvent.ts +146 -0
  217. package/lib/events/ResizeEvent.ts +31 -31
  218. package/lib/events/TextfieldEvent.ts +28 -28
  219. package/lib/events/TouchEvent.ts +101 -0
  220. package/lib/factories/DefaultSceneGraphFactory.ts +56 -56
  221. package/lib/factories/ISceneGraphFactory.ts +28 -28
  222. package/lib/image/SceneImage2D.ts +1020 -1020
  223. package/lib/managers/DefaultFontManager.ts +124 -124
  224. package/lib/managers/DeviceFontManager.ts +55 -55
  225. package/lib/managers/FrameScriptManager.ts +431 -431
  226. package/lib/managers/IInputRecorder.ts +2 -2
  227. package/lib/managers/MouseManager.ts +944 -884
  228. package/lib/prefabs/PrefabBase.ts +47 -47
  229. package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
  230. package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
  231. package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
  232. package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
  233. package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
  234. package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
  235. package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
  236. package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
  237. package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
  238. package/lib/text/AntiAliasType.ts +24 -24
  239. package/lib/text/BitmapFontChar.ts +53 -53
  240. package/lib/text/BitmapFontTable.ts +232 -232
  241. package/lib/text/FNTGenerator.ts +100 -100
  242. package/lib/text/FNTGeneratorCanvas.ts +287 -287
  243. package/lib/text/FNTGeneratrorBase.ts +10 -10
  244. package/lib/text/Font.ts +114 -114
  245. package/lib/text/FontLookUpMode.ts +5 -5
  246. package/lib/text/FontStyleName.ts +6 -6
  247. package/lib/text/GridFitType.ts +32 -32
  248. package/lib/text/HTMLTextProcessor.ts +418 -418
  249. package/lib/text/IFontTable.ts +17 -17
  250. package/lib/text/TesselatedFontChar.ts +80 -80
  251. package/lib/text/TesselatedFontTable.ts +1221 -1221
  252. package/lib/text/TextFieldAutoSize.ts +30 -30
  253. package/lib/text/TextFieldType.ts +21 -21
  254. package/lib/text/TextFormat.ts +601 -601
  255. package/lib/text/TextFormatAlign.ts +28 -28
  256. package/lib/text/TextInteractionMode.ts +21 -21
  257. package/lib/text/TextLineMetrics.ts +74 -74
  258. package/lib/text/TextShape.ts +90 -90
  259. package/lib/tools/Merge.ts +311 -311
  260. package/lib/utils/Cast.ts +304 -304
  261. package/package.json +74 -74
  262. package/rollup.config.js +33 -33
  263. package/scripts/build.sh +2 -2
  264. package/scripts/gendocs.sh +14 -14
  265. package/scripts/genexamples.sh +14 -14
  266. package/scripts/genfull.sh +14 -14
  267. package/system.config.js +51 -51
  268. package/tsconfig.json +18 -18
@@ -1,879 +1,879 @@
1
- import { WaveAudio, IAudioChannel, EventBase, BaseAudioChannel } from '@awayjs/core';
2
- import { PartitionBase, EntityNode } from '@awayjs/view';
3
- import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
4
- import { Timeline } from '../base/Timeline';
5
- import { MouseEvent } from '../events/MouseEvent';
6
- import { FrameScriptManager } from '../managers/FrameScriptManager';
7
- import { DisplayObject } from './DisplayObject';
8
- import { Sprite } from './Sprite';
9
- import { DisplayObjectContainer } from './DisplayObjectContainer';
10
- import { MouseButtons } from '../base/MouseButtons';
11
-
12
- interface IScene {
13
- offset: number;
14
- name: string;
15
- labels: ILabel[];
16
- numFrames: number;
17
- }
18
-
19
- interface ILabel {
20
- frame: number;
21
- name: string;
22
- }
23
- export class MovieClip extends Sprite {
24
- public static mcForConstructor: MovieClip;
25
- //todo: this 3 are no longer used (?)
26
- public static avm1ScriptQueue: MovieClip[] = [];
27
- public static avm1ScriptQueueScripts: any[] = [];
28
- public static avm1LoadedActions: any[] = [];
29
-
30
- public static movieClipSoundsManagerClass = null;
31
-
32
- private static _movieClips: Array<MovieClip> = new Array<MovieClip>();
33
- private static _activeSoundsOwners: Set<MovieClip> = new Set<MovieClip>();
34
-
35
- public static stopAllSounds() {
36
- MovieClip._activeSoundsOwners.forEach(e => e && e.stopSounds());
37
- MovieClip._activeSoundsOwners.clear();
38
- }
39
-
40
- public static assetType: string = '[asset MovieClip]';
41
-
42
- public static getNewMovieClip(timeline: Timeline): MovieClip {
43
- if (MovieClip._movieClips.length) {
44
- const movieClip: MovieClip = MovieClip._movieClips.pop();
45
- movieClip.timeline = timeline;
46
- return movieClip;
47
- }
48
-
49
- return new MovieClip(timeline);
50
- }
51
-
52
- public static clearPool() {
53
- MovieClip._movieClips = [];
54
- }
55
-
56
- public symbolID: number = 0;
57
- public preventScript: boolean = false;
58
- private _timeline: Timeline;
59
-
60
- private _scenes: IScene[] = [];
61
- // buttonMode specifies if the mc has any mouse-listeners attached that should trigger showing the hand-cursor
62
- // if this is set once to true; it will never get set back to false again.
63
- private _buttonMode: boolean = false;
64
-
65
- // isButton specifies if the mc-timeline is actually considered a button-timeline
66
- private _isButton: boolean = false;
67
-
68
- private _onMouseOver: (event: MouseEvent) => void;
69
- private _onMouseOut: (event: MouseEvent) => void;
70
- private _onMouseDown: (event: MouseEvent) => void;
71
- private _onMouseUp: (event: MouseEvent) => void;
72
- private _onMouseUpOutside: (event: MouseEvent) => void;
73
-
74
- private _time: number = 0;// the current time inside the animation
75
-
76
- private _currentFrameIndex: number = -1;// the current frame
77
-
78
- private _isPlaying: boolean = true;// false if paused or stopped
79
-
80
- private _currentSceneIndex: number = 0;
81
- private _sceneDirty: boolean = false;
82
-
83
- private _skipAdvance: boolean;
84
-
85
- private _isInit: boolean = true;
86
-
87
- public _sessionID_childs: NumberMap<DisplayObject> = {};
88
-
89
- private _sounds: Record<number, WaveAudio> = {};
90
- private _activeSounds: Record<number, IAudioChannel[]> = {};
91
-
92
- public _useHandCursor: boolean;
93
-
94
- private _soundVolume: number;
95
-
96
- private _skipFramesForStream: number = 0;
97
-
98
- private _soundStreams: any;
99
-
100
- /**
101
- * Mark that operation provided by timeline except a script, some operation not allowed from script
102
- * `removeChild` should not remove a child name
103
- * @private
104
- */
105
- private _isTimelinePass = false;
106
-
107
- /**
108
- * Some symbols can be a sprite. This means that when we spawn it, we should track only first frame.
109
- * @private
110
- */
111
- private _isSprite: boolean = false;
112
- public get isSprite() {
113
- return this._isSprite;
114
- }
115
-
116
- public buttonEnabled: boolean = true;
117
-
118
- public initSoundStream(streamInfo: any, maxFrameNum: number) {
119
- if (!this._soundStreams) {
120
- this._soundStreams = new MovieClip.movieClipSoundsManagerClass(this);
121
- }
122
- this._soundStreams.initSoundStream(streamInfo, maxFrameNum);
123
- }
124
-
125
- public addSoundStreamBlock(frameNum: number, streamBlock: any) {
126
- if (!this._soundStreams) {
127
- this._soundStreams = new MovieClip.movieClipSoundsManagerClass(this);
128
- }
129
- this._soundStreams.addSoundStreamBlock(frameNum, streamBlock);
130
- }
131
-
132
- private stopCurrentStream(frameNum: number) {
133
- if (this._soundStreams) {
134
- //console.log("sync sounds for mc: ", this.numFrames);
135
- return this._soundStreams.stopStream(frameNum);
136
- }
137
- }
138
-
139
- private resetStreamStopped() {
140
- if (this._soundStreams) {
141
- //console.log("sync sounds for mc: ", this.numFrames);
142
- this._soundStreams.resetStreamStopped();
143
- }
144
- }
145
-
146
- private _syncSounds(frameNum: number): number {
147
- if (this._soundStreams) {
148
- //console.log("sync sounds for mc: ", this.numFrames);
149
- return this._soundStreams.syncSounds(frameNum, this._isPlaying, this.parent);
150
- }
151
- return 0;
152
- }
153
-
154
- constructor(timeline: Timeline, spriteMode = false) {
155
- super();
156
-
157
- this._soundVolume = 1;
158
- this._isButton = false;
159
- this._buttonMode = false;
160
- this._useHandCursor = true;
161
-
162
- this.doingSwap = false;
163
- this.cursorType = 'pointer';
164
- //this.debugVisible=true;
165
-
166
- this._onMouseOver = (_event: MouseEvent) => {
167
- if (this.buttonEnabled)
168
- this.currentFrameIndex = (_event.buttons & MouseButtons.PRIMARY_BUTTON) ? this.currentFrameIndex == 0 ? 0 : 2 : 1;
169
- else
170
- this.currentFrameIndex = 0;
171
- };
172
-
173
- this._onMouseOut = (_event: MouseEvent) => {
174
- this.currentFrameIndex = (_event.buttons & MouseButtons.PRIMARY_BUTTON && this.currentFrameIndex != 0) ? 1 : 0;
175
- };
176
-
177
- this._onMouseDown = (_event: MouseEvent) => {
178
- if (this.buttonEnabled)
179
- this.currentFrameIndex = 2;
180
- else
181
- this.currentFrameIndex = 0;
182
- };
183
-
184
- this._onMouseUp = (_event: MouseEvent) => {
185
- this.currentFrameIndex = 1;
186
- };
187
-
188
- this._onMouseUpOutside = (_event: MouseEvent) => {
189
- this.currentFrameIndex = 0;
190
- };
191
-
192
- this._timeline = timeline;
193
-
194
- if (spriteMode) {
195
- this.transformToSprite();
196
- }
197
-
198
- this.onSoundCompleteInternal = this.onSoundCompleteInternal.bind(this);
199
- }
200
-
201
- /**
202
- * Reduce frames of timeline to sprite mode.
203
- * Used for UIComponents, where timeline store more that 1 frame
204
- */
205
- public transformToSprite() {
206
- if (this._isSprite) {
207
- return;
208
- }
209
-
210
- this._isSprite = true;
211
-
212
- const timeline = this._timeline;
213
-
214
- // regular MC or frames already is not more 1
215
- if (timeline.numFrames <= 1) {
216
- return;
217
- }
218
-
219
- timeline.frame_command_indices = <any>[timeline.frame_command_indices[0]];
220
- timeline.frame_recipe = <any>[timeline.frame_recipe[0]];
221
- timeline.keyframe_constructframes = [timeline.keyframe_constructframes[0]];
222
- timeline.keyframe_durations = <any>[timeline.keyframe_durations[0]];
223
- timeline.keyframe_firstframes = [timeline.keyframe_firstframes[0]];
224
- timeline.keyframe_indices = [timeline.keyframe_indices[0]];
225
- }
226
-
227
- public startSound(
228
- sound: WaveAudio,
229
- loopsToPlay: number,
230
- onSoundComplete?: (event: EventBase) => void
231
- ) {
232
-
233
- const channel: IAudioChannel = sound.play(0, loopsToPlay);
234
-
235
- channel.volume = this._soundVolume;
236
-
237
- if (onSoundComplete)
238
- channel.addEventListener(BaseAudioChannel.COMPLETE, onSoundComplete);
239
-
240
- //internal listener to clear
241
- channel.addEventListener(BaseAudioChannel.COMPLETE, this.onSoundCompleteInternal);
242
-
243
- this._sounds[sound.id] = sound;
244
-
245
- if (!this._activeSounds[sound.id]) {
246
- this._activeSounds[sound.id] = [];
247
- }
248
-
249
- // store channels, stop it instead of sounds
250
- this._activeSounds[sound.id].push(channel);
251
- MovieClip._activeSoundsOwners.add(this);
252
- }
253
-
254
- public stopSounds(sound: WaveAudio = null) {
255
- if (sound) {
256
- this.stopSound(sound);
257
- } else {
258
- for (const key in this._sounds)
259
- this.stopSound(this._sounds[key]);
260
- }
261
-
262
- if (Object.getOwnPropertyNames(this._sounds).length === 0) {
263
- MovieClip._activeSoundsOwners.delete(this);
264
- }
265
-
266
- const len: number = this._children.length;
267
- let child: DisplayObject;
268
- for (let i: number = 0; i < len; ++i) {
269
- child = this._children[i];
270
- if (child.isAsset(MovieClip))
271
- (<MovieClip>child).stopSounds(sound);
272
- }
273
-
274
- this.stopCurrentStream(this._currentFrameIndex);
275
-
276
- if (this._soundStreams)
277
- this._soundStreams.syncSounds(0, false, this.parent);
278
- }
279
-
280
- /**
281
- * Compute scene index by global frame index
282
- * @param frameIndex
283
- * @private
284
- */
285
- private getSceneIndexByFrame(frameIndex: number): number {
286
- const scenes = this.scenes;
287
-
288
- if (scenes.length <= 1) {
289
- return 0;
290
- }
291
-
292
- for (let i = 0; i < scenes.length; i++) {
293
- if (scenes[i].offset > frameIndex) {
294
- return i - 1;
295
- }
296
- }
297
-
298
- return scenes.length - 1;
299
- }
300
-
301
- private getSceneIndex(scene: string) {
302
- const scenes = this.scenes;
303
-
304
- for (let i = 0; i < scenes.length && scene; i++) {
305
- if (scenes[i].name === scene) {
306
- return i;
307
- }
308
- }
309
-
310
- return 0;
311
- }
312
-
313
- public set currentSceneName(scene: string) {
314
- const index = this.getSceneIndex(scene);
315
-
316
- this._sceneDirty = this._currentSceneIndex !== index;
317
- this._currentSceneIndex = index;
318
- this._currentFrameIndex = this._scenes[index].offset;
319
- }
320
-
321
- public get currentSceneName(): string {
322
- return this.scenes[this._currentSceneIndex].name;
323
- }
324
-
325
- public get currentScene(): IScene {
326
- const currentScene = this.scenes[this._currentSceneIndex];
327
-
328
- if (currentScene.numFrames === -1) {
329
- currentScene.numFrames = this.timeline.numFrames - currentScene.offset;
330
- }
331
-
332
- return currentScene;
333
- }
334
-
335
- public get scenes(): IScene[] {
336
- if (this._scenes.length === 0) {
337
- this._scenes[0] = {
338
- name: 'Scene1',
339
- offset: 0,
340
- labels: [],
341
- numFrames: this.timeline.numFrames,
342
- };
343
- }
344
-
345
- return this._scenes;
346
- }
347
-
348
- public set scenes(value: IScene[]) {
349
- this._scenes = value;
350
- }
351
-
352
- public get isPlaying(): boolean {
353
- return this._isPlaying;
354
- }
355
-
356
- public get soundVolume(): number {
357
- return this._soundVolume;
358
- }
359
-
360
- public set soundVolume(value: number) {
361
- if (this._soundVolume == value)
362
- return;
363
-
364
- this._soundVolume = value;
365
-
366
- let channels: IAudioChannel[];
367
- for (const key in this._activeSounds)
368
- if ((channels = this._activeSounds[key]))
369
- for (const c of channels) c.volume = value;
370
- }
371
-
372
- public stopSound(sound: WaveAudio) {
373
- if (this._sounds[sound.id]) {
374
- this._sounds[sound.id].stop();
375
- delete this._sounds[sound.id];
376
-
377
- if (Object.getOwnPropertyNames(this._sounds).length === 0) {
378
- MovieClip._activeSoundsOwners.delete(this);
379
- }
380
-
381
- const channels = this._activeSounds[sound.id];
382
- if (channels) {
383
- for (const c of channels) c.stop();
384
-
385
- delete this._activeSounds[sound.id];
386
- }
387
- }
388
- }
389
-
390
- public buttonReset() {
391
- if (this._isButton && !this.buttonEnabled) {
392
- this.currentFrameIndex = 0;
393
- }
394
- }
395
-
396
- public getMouseCursor(): string {
397
- if (this.name == 'scene')
398
- return 'initial';
399
- if (this._useHandCursor && this.buttonMode) {
400
- return this.cursorType;
401
- }
402
- return 'initial';
403
- /*
404
- var cursorName:string;
405
- var parent:DisplayObject=this.parent;
406
- while(parent){
407
- if(parent.isAsset(MovieClip)){
408
- cursorName=(<MovieClip>parent).getMouseCursor();
409
- if(cursorName!="initial"){
410
- return cursorName;
411
- }
412
- }
413
- parent=parent.parent;
414
- if(parent && parent.name=="scene"){
415
- return "initial";
416
- }
417
- }
418
- return "initial";
419
- */
420
- }
421
-
422
- public queueFrameScripts(timeline: Timeline, frame_idx: number, scriptPass1: boolean) {
423
- console.warn('[MovieClip] - queueFrameScripts should only be called on AVM-Adapters');
424
- }
425
-
426
- public registerScriptObject(child: DisplayObject): void {
427
- this[child.name] = child;
428
-
429
- if (child.isAsset(MovieClip))
430
- (<MovieClip>child).removeButtonListeners();
431
- }
432
-
433
- public unregisterScriptObject(child: DisplayObject): void {
434
- delete this[child.name];
435
-
436
- if (child.isAsset(MovieClip))
437
- (<MovieClip>child).removeButtonListeners();
438
- }
439
-
440
- public dispose(): void {
441
- this.disposeValues();
442
-
443
- MovieClip._movieClips.push(this);
444
- }
445
-
446
- public disposeValues(): void {
447
- super.disposeValues();
448
-
449
- this._sessionID_childs = {};
450
-
451
- this._timeline = null;
452
- }
453
-
454
- public get useHandCursor(): boolean {
455
- return this._useHandCursor;
456
- }
457
-
458
- public set useHandCursor(value: boolean) {
459
- this._useHandCursor = value;
460
- }
461
-
462
- public get buttonMode(): boolean {
463
- return this._buttonMode;
464
- }
465
-
466
- public set buttonMode(value: boolean) {
467
- this._buttonMode = value;
468
- }
469
-
470
- public get isButton(): boolean {
471
- return this._isButton;
472
- }
473
-
474
- public set isButton(value: boolean) {
475
- this._isButton = value;
476
- }
477
-
478
- public get isInit(): boolean {
479
- return this._isInit;
480
- }
481
-
482
- public set isInit(value: boolean) {
483
- this._isInit = value;
484
- }
485
-
486
- public get timeline(): Timeline {
487
- return this._timeline;
488
- }
489
-
490
- public set timeline(value: Timeline) {
491
- if (this._timeline == value)
492
- return;
493
-
494
- this._timeline = value;
495
-
496
- this.reset(false, false);
497
- }
498
-
499
- /**
500
- *
501
- */
502
- public loop: boolean = true;
503
-
504
- public get numFrames(): number {
505
- return this._timeline.numFrames;
506
- }
507
-
508
- public jumpToLabel(label: string, offset: number = 0): boolean {
509
- // the timeline.jumpTolabel will set currentFrameIndex
510
- const index = this._currentFrameIndex;
511
-
512
- this._timeline.jumpToLabel(this, label, offset);
513
-
514
- return index !== this._currentFrameIndex;
515
- }
516
-
517
- /**
518
- * the current index of the current active frame
519
- */
520
- public constructedKeyFrameIndex: number = -1;
521
-
522
- public reset(fireScripts: boolean = true, resetSelf: boolean = true): void {
523
- this._isTimelinePass = true;
524
-
525
- if (resetSelf)
526
- super.reset();
527
-
528
- if (this.id == 4115)
529
- console.warn('reset', this.id);
530
-
531
- this.resetStreamStopped();
532
-
533
- // time only is relevant for the root mc, as it is the only one that executes the update function
534
- this._time = 0;
535
- //this.stopSounds();
536
-
537
- if (resetSelf && this._adapter)
538
- (<IMovieClipAdapter> this.adapter).freeFromScript();
539
-
540
- this.constructedKeyFrameIndex = -1;
541
- for (let i: number = this.numChildren - 1; i >= 0; i--)
542
- this.removeChildAt(i);
543
-
544
- if (this._graphics)
545
- this._graphics.clear();
546
-
547
- if (fireScripts) {
548
- const numFrames: number = this._timeline.keyframe_indices.length;
549
- this._isPlaying = Boolean(numFrames > 1);
550
- this._currentSceneIndex = 0;
551
-
552
- if (numFrames) {
553
- this._currentFrameIndex = 0;
554
- // contruct the timeline and queue the script.
555
- //if(fireScripts){
556
- this._timeline.constructNextFrame(this, fireScripts && !this.doingSwap && !this.preventScript, true);
557
- //}
558
- } else {
559
- this._currentFrameIndex = -1;
560
- }
561
- }
562
- // prevents the playhead to get moved in the advance frame again:
563
- this._skipAdvance = true;
564
- this._isTimelinePass = false;
565
- }
566
-
567
- public set currentFrameIndex(value: number) {
568
- this.jumpToIndex(value);
569
- }
570
-
571
- public get currentFrameIndex() {
572
- return this._currentFrameIndex;
573
- }
574
-
575
- /*
576
- * Setting the currentFrameIndex will move the playhead for this movieclip to the new position
577
- */
578
- public get currentFrameIndexRelative(): number {
579
- return this._currentFrameIndex - this.currentScene.offset;
580
- }
581
-
582
- public set currentFrameIndexRelative(value: number) {
583
- this.jumpToIndex(value, this._currentSceneIndex);
584
- }
585
-
586
- public jumpToIndex(value: number, sceneIndex?: string | number): boolean {
587
- let queue_script: boolean = true;
588
-
589
- let offset: number = 0;
590
- let numFrames: number = this._timeline.keyframe_indices.length;
591
-
592
- this.resetStreamStopped();
593
- if (!numFrames)
594
- return false;
595
-
596
- const scenes = this.scenes;
597
-
598
- // scene not presented - global navigation
599
- // we should compute scene index and shift frame
600
- if (typeof sceneIndex === 'undefined') {
601
-
602
- sceneIndex = this.getSceneIndexByFrame(value);
603
-
604
- } else {
605
- sceneIndex = typeof sceneIndex === 'string' ? this.getSceneIndex(sceneIndex) : sceneIndex;
606
-
607
- const scene = scenes[sceneIndex];
608
-
609
- // fix negative frames size on latest scene.
610
- // this is because we don't know how many frames in instance time
611
- if (scene.numFrames === -1) {
612
- scene.numFrames = numFrames - scene.offset;
613
- }
614
-
615
- offset = scene.offset;
616
- numFrames = scene.numFrames;
617
- }
618
-
619
- this._currentSceneIndex = sceneIndex;
620
-
621
- if (value < 0) {
622
- value = 0;
623
- } else if (value >= numFrames) {
624
- // if value is greater than the available number of
625
- // frames, the playhead is moved to the last frame in the timeline.
626
- // In this case the frame specified is not considered a keyframe,
627
- // no scripts should be executed in this case
628
- value = numFrames - 1;
629
- queue_script = false;
630
- }
631
-
632
- value += offset;
633
-
634
- this._skipAdvance = false;
635
- if (this._currentFrameIndex === value && !this._sceneDirty)
636
- return false;
637
-
638
- this._sceneDirty = false;
639
- this._currentFrameIndex = value;
640
-
641
- //console.log("_currentFrameIndex ", this.name, this._currentFrameIndex);
642
- //changing current frame will ignore advance command for that
643
- //update's advanceFrame function, unless advanceFrame has
644
- //already been executed
645
-
646
- this._timeline.gotoFrame(this, value, queue_script, false, false);
647
-
648
- return true;
649
- }
650
-
651
- public addButtonListeners(): void {
652
- this._isButton = true;
653
-
654
- this.stop();
655
-
656
- this.addEventListener(MouseEvent.MOUSE_OVER, this._onMouseOver);
657
- this.addEventListener(MouseEvent.MOUSE_OUT, this._onMouseOut);
658
- this.addEventListener(MouseEvent.MOUSE_DOWN, this._onMouseDown);
659
- this.addEventListener(MouseEvent.MOUSE_UP, this._onMouseUp);
660
- this.addEventListener(MouseEvent.MOUSE_UP_OUTSIDE, this._onMouseUpOutside);
661
-
662
- this.mouseChildren = false;
663
- }
664
-
665
- public removeButtonListeners(): void {
666
- this.removeEventListener(MouseEvent.MOUSE_OVER, this._onMouseOver);
667
- this.removeEventListener(MouseEvent.MOUSE_OUT, this._onMouseOut);
668
- this.removeEventListener(MouseEvent.MOUSE_DOWN, this._onMouseDown);
669
- this.removeEventListener(MouseEvent.MOUSE_UP, this._onMouseUp);
670
- this.removeEventListener(MouseEvent.MOUSE_UP_OUTSIDE, this._onMouseUpOutside);
671
- }
672
-
673
- public getTimelineChildAtSessionID(sessionID: number): DisplayObject {
674
- return this._sessionID_childs[sessionID];
675
- }
676
-
677
- // should only be called from timeline when navigating frames
678
- public constructFrame(timeline: Timeline, start_construct_idx: number,
679
- target_keyframe_idx: number, jump_forward: boolean,
680
- frame_idx: number, queue_pass2: boolean, queue_script: boolean) {
681
- console.warn('[scene/MovieClip] - constructFrame not implemented');
682
- }
683
-
684
- public addTimelineChildAtDepth(child: DisplayObject, depth: number, sessionID: number): DisplayObject {
685
- console.warn('[scene/MovieClip] - addTimelineChildAtDepth not implemented');
686
- return null;
687
- }
688
-
689
- public removeTimelineChildAtDepth(depth: number): void {
690
- console.warn('[scene/MovieClip] - removeTimelineChildAtDepth not implemented');
691
- }
692
-
693
- public removeChildAtInternal(index: number): DisplayObject {
694
- const child: DisplayObject = this._children[index];
695
-
696
- if (child._adapter)
697
- (<IMovieClipAdapter>child.adapter).freeFromScript();
698
-
699
- // only timeline can do this
700
- if (this._isTimelinePass) {
701
-
702
- (<IMovieClipAdapter> this.adapter).unregisterScriptObject(child);
703
- }
704
-
705
- delete this._sessionID_childs[child._sessionID];
706
-
707
- child._sessionID = -1;
708
-
709
- if (child.adapter && (<any>child.adapter).dispatchStaticEvent) {
710
- (<any>child.adapter).dispatchStaticEvent('removed', child.adapter);
711
- }
712
- if (this.isOnDisplayList() && (<any>child.adapter).dispatch_REMOVED_FROM_STAGE) {
713
- (<any>child.adapter).dispatch_REMOVED_FROM_STAGE(<DisplayObjectContainer>child);
714
- }
715
-
716
- return super.removeChildAtInternal(index);
717
- }
718
-
719
- public get assetType(): string {
720
- return MovieClip.assetType;
721
- }
722
-
723
- /**
724
- * Starts playback of animation from current position
725
- */
726
- public play(): void {
727
- if (this._timeline.keyframe_indices.length > 1)
728
- this._isPlaying = true;
729
- }
730
-
731
- /**
732
- * Stop playback of animation and hold current position
733
- */
734
- public stop(): void {
735
- //this.stopSounds();
736
- this.resetStreamStopped();
737
- this._isPlaying = false;
738
- }
739
-
740
- public clone(): MovieClip {
741
- const newInstance: MovieClip = MovieClip.getNewMovieClip(this._timeline);
742
-
743
- this.copyTo(newInstance);
744
-
745
- return newInstance;
746
- }
747
-
748
- public copyTo(movieClip: MovieClip): void {
749
- super.copyTo(movieClip);
750
-
751
- movieClip.buttonMode = this.buttonMode;
752
- movieClip.symbolID = this.symbolID;
753
- movieClip.loop = this.loop;
754
- movieClip._soundStreams = this._soundStreams;
755
- movieClip._scenes = this._scenes;
756
-
757
- // move to sprite mode too
758
- if (this._isSprite) {
759
- movieClip.transformToSprite();
760
- }
761
- }
762
-
763
- public advanceFrameInternal(): void {
764
- // if this._skipadvance is true, the mc has already been moving on its timeline this frame
765
- // this happens for objects that have been newly added to parent
766
- // they still need to queue their scripts
767
-
768
- //if(this._timeline && this._timeline.numFrames>0)
769
- if (this._timeline && this._timeline.numFrames > 0 && this._isPlaying && !this._skipAdvance) {
770
-
771
- if (this._currentFrameIndex === this._timeline.numFrames - 1) {
772
- if (this.loop) {
773
- if (this._currentFrameIndex !== 0) {
774
- this._currentFrameIndex = 0;
775
- this._currentSceneIndex = 0;
776
-
777
- this.resetStreamStopped();
778
- this._timeline.gotoFrame(this, 0, true, true, true);
779
- }
780
- // end of loop - jump to first frame.
781
- } else //end of timeline, stop playing
782
- this._isPlaying = false;
783
- } else { // not end - construct next frame
784
- this._currentFrameIndex++;
785
- this._currentSceneIndex = this.getSceneIndexByFrame(this._currentFrameIndex);
786
-
787
- this._timeline.constructNextFrame(this);
788
- }
789
- //console.log("advancedFrame ", this.name, this._currentFrameIndex);
790
- }
791
-
792
- super.advanceFrame();
793
- this._skipAdvance = false;
794
- }
795
-
796
- public advanceFrame(): void {
797
- this._isTimelinePass = true;
798
- if (this._skipFramesForStream == 0) {
799
- this.advanceFrameInternal();
800
- }
801
- /*if(this._skipFramesForStream<0){
802
- console.log("wait for audio to catch up");
803
- }*/
804
- this._skipFramesForStream = this._syncSounds(this._currentFrameIndex);
805
- while (this._skipFramesForStream > 0) {
806
- //console.log("skip frame for keeping audio stream synced");
807
- FrameScriptManager.execute_queue();
808
- this.advanceFrameInternal();
809
- this._skipFramesForStream = this._syncSounds(this._currentFrameIndex);
810
- }
811
-
812
- this._isTimelinePass = false;
813
- }
814
-
815
- // DEBUG CODE:
816
- logHierarchy(depth: number = 0): void {
817
- this.printHierarchyName(depth, this);
818
-
819
- const len = this._children.length;
820
- let child: DisplayObject;
821
- for (let i: number = 0; i < len; i++) {
822
- child = this._children[i];
823
-
824
- if (child.isAsset(MovieClip))
825
- (<MovieClip>child).logHierarchy(depth + 1);
826
- else
827
- this.printHierarchyName(depth + 1, child);
828
- }
829
- }
830
-
831
- printHierarchyName(depth: number, target: DisplayObject): void {
832
- let str = '';
833
- for (let i = 0; i < depth; ++i)
834
- str += '--';
835
-
836
- str += ' ' + target.name + ' = ' + target.id;
837
- console.log(str);
838
- }
839
-
840
- public clear(): void {
841
- //clear out potential instances
842
- this.resetStreamStopped();
843
- /* check memory disposal with new approach of child-instancing
844
- for (var key in this._potentialInstances) {
845
- var instance: IAsset = this._potentialInstances[key];
846
-
847
- //only dispose instances that are not used in script ie. do not have an instance name
848
- if (instance && !instance.name) {
849
- if (!instance.isAsset(Sprite)) {
850
- FrameScriptManager.add_child_to_dispose(<DisplayObject>instance);
851
-
852
- }
853
- delete this._potentialInstances[key];
854
- }
855
- }
856
- */
857
-
858
- super.clear();
859
- }
860
-
861
- private onSoundCompleteInternal(event: EventBase): void {
862
- const channel: IAudioChannel = event.target;
863
- const sound = channel.owner;
864
- const channels = this._activeSounds[sound.id];
865
- const index = channels.indexOf(channel);
866
-
867
- if (index != -1) {
868
- channels.splice(index, 1);
869
- }
870
-
871
- if (channels.length === 0)
872
- delete this._sounds[sound.id];
873
-
874
- if (Object.getOwnPropertyNames(this._sounds).length === 0)
875
- MovieClip._activeSoundsOwners.delete(this);
876
- }
877
- }
878
-
879
- PartitionBase.registerAbstraction(EntityNode, MovieClip);
1
+ import { WaveAudio, IAudioChannel, EventBase, BaseAudioChannel } from '@awayjs/core';
2
+ import { PartitionBase, EntityNode } from '@awayjs/view';
3
+ import { IMovieClipAdapter } from '../adapters/IMovieClipAdapter';
4
+ import { Timeline } from '../base/Timeline';
5
+ import { MouseEvent } from '../events/MouseEvent';
6
+ import { FrameScriptManager } from '../managers/FrameScriptManager';
7
+ import { DisplayObject } from './DisplayObject';
8
+ import { Sprite } from './Sprite';
9
+ import { DisplayObjectContainer } from './DisplayObjectContainer';
10
+ import { MouseButtons } from '../base/MouseButtons';
11
+
12
+ interface IScene {
13
+ offset: number;
14
+ name: string;
15
+ labels: ILabel[];
16
+ numFrames: number;
17
+ }
18
+
19
+ interface ILabel {
20
+ frame: number;
21
+ name: string;
22
+ }
23
+ export class MovieClip extends Sprite {
24
+ public static mcForConstructor: MovieClip;
25
+ //todo: this 3 are no longer used (?)
26
+ public static avm1ScriptQueue: MovieClip[] = [];
27
+ public static avm1ScriptQueueScripts: any[] = [];
28
+ public static avm1LoadedActions: any[] = [];
29
+
30
+ public static movieClipSoundsManagerClass = null;
31
+
32
+ private static _movieClips: Array<MovieClip> = new Array<MovieClip>();
33
+ private static _activeSoundsOwners: Set<MovieClip> = new Set<MovieClip>();
34
+
35
+ public static stopAllSounds() {
36
+ MovieClip._activeSoundsOwners.forEach(e => e && e.stopSounds());
37
+ MovieClip._activeSoundsOwners.clear();
38
+ }
39
+
40
+ public static assetType: string = '[asset MovieClip]';
41
+
42
+ public static getNewMovieClip(timeline: Timeline): MovieClip {
43
+ if (MovieClip._movieClips.length) {
44
+ const movieClip: MovieClip = MovieClip._movieClips.pop();
45
+ movieClip.timeline = timeline;
46
+ return movieClip;
47
+ }
48
+
49
+ return new MovieClip(timeline);
50
+ }
51
+
52
+ public static clearPool() {
53
+ MovieClip._movieClips = [];
54
+ }
55
+
56
+ public symbolID: number = 0;
57
+ public preventScript: boolean = false;
58
+ private _timeline: Timeline;
59
+
60
+ private _scenes: IScene[] = [];
61
+ // buttonMode specifies if the mc has any mouse-listeners attached that should trigger showing the hand-cursor
62
+ // if this is set once to true; it will never get set back to false again.
63
+ private _buttonMode: boolean = false;
64
+
65
+ // isButton specifies if the mc-timeline is actually considered a button-timeline
66
+ private _isButton: boolean = false;
67
+
68
+ private _onMouseOver: (event: MouseEvent) => void;
69
+ private _onMouseOut: (event: MouseEvent) => void;
70
+ private _onMouseDown: (event: MouseEvent) => void;
71
+ private _onMouseUp: (event: MouseEvent) => void;
72
+ private _onMouseUpOutside: (event: MouseEvent) => void;
73
+
74
+ private _time: number = 0;// the current time inside the animation
75
+
76
+ private _currentFrameIndex: number = -1;// the current frame
77
+
78
+ private _isPlaying: boolean = true;// false if paused or stopped
79
+
80
+ private _currentSceneIndex: number = 0;
81
+ private _sceneDirty: boolean = false;
82
+
83
+ private _skipAdvance: boolean;
84
+
85
+ private _isInit: boolean = true;
86
+
87
+ public _sessionID_childs: NumberMap<DisplayObject> = {};
88
+
89
+ private _sounds: Record<number, WaveAudio> = {};
90
+ private _activeSounds: Record<number, IAudioChannel[]> = {};
91
+
92
+ public _useHandCursor: boolean;
93
+
94
+ private _soundVolume: number;
95
+
96
+ private _skipFramesForStream: number = 0;
97
+
98
+ private _soundStreams: any;
99
+
100
+ /**
101
+ * Mark that operation provided by timeline except a script, some operation not allowed from script
102
+ * `removeChild` should not remove a child name
103
+ * @private
104
+ */
105
+ private _isTimelinePass = false;
106
+
107
+ /**
108
+ * Some symbols can be a sprite. This means that when we spawn it, we should track only first frame.
109
+ * @private
110
+ */
111
+ private _isSprite: boolean = false;
112
+ public get isSprite() {
113
+ return this._isSprite;
114
+ }
115
+
116
+ public buttonEnabled: boolean = true;
117
+
118
+ public initSoundStream(streamInfo: any, maxFrameNum: number) {
119
+ if (!this._soundStreams) {
120
+ this._soundStreams = new MovieClip.movieClipSoundsManagerClass(this);
121
+ }
122
+ this._soundStreams.initSoundStream(streamInfo, maxFrameNum);
123
+ }
124
+
125
+ public addSoundStreamBlock(frameNum: number, streamBlock: any) {
126
+ if (!this._soundStreams) {
127
+ this._soundStreams = new MovieClip.movieClipSoundsManagerClass(this);
128
+ }
129
+ this._soundStreams.addSoundStreamBlock(frameNum, streamBlock);
130
+ }
131
+
132
+ private stopCurrentStream(frameNum: number) {
133
+ if (this._soundStreams) {
134
+ //console.log("sync sounds for mc: ", this.numFrames);
135
+ return this._soundStreams.stopStream(frameNum);
136
+ }
137
+ }
138
+
139
+ private resetStreamStopped() {
140
+ if (this._soundStreams) {
141
+ //console.log("sync sounds for mc: ", this.numFrames);
142
+ this._soundStreams.resetStreamStopped();
143
+ }
144
+ }
145
+
146
+ private _syncSounds(frameNum: number): number {
147
+ if (this._soundStreams) {
148
+ //console.log("sync sounds for mc: ", this.numFrames);
149
+ return this._soundStreams.syncSounds(frameNum, this._isPlaying, this.parent);
150
+ }
151
+ return 0;
152
+ }
153
+
154
+ constructor(timeline: Timeline, spriteMode = false) {
155
+ super();
156
+
157
+ this._soundVolume = 1;
158
+ this._isButton = false;
159
+ this._buttonMode = false;
160
+ this._useHandCursor = true;
161
+
162
+ this.doingSwap = false;
163
+ this.cursorType = 'pointer';
164
+ //this.debugVisible=true;
165
+
166
+ this._onMouseOver = (_event: MouseEvent) => {
167
+ if (this.buttonEnabled)
168
+ this.currentFrameIndex = (_event.buttons & MouseButtons.PRIMARY_BUTTON) ? this.currentFrameIndex == 0 ? 0 : 2 : 1;
169
+ else
170
+ this.currentFrameIndex = 0;
171
+ };
172
+
173
+ this._onMouseOut = (_event: MouseEvent) => {
174
+ this.currentFrameIndex = (_event.buttons & MouseButtons.PRIMARY_BUTTON && this.currentFrameIndex != 0) ? 1 : 0;
175
+ };
176
+
177
+ this._onMouseDown = (_event: MouseEvent) => {
178
+ if (this.buttonEnabled)
179
+ this.currentFrameIndex = 2;
180
+ else
181
+ this.currentFrameIndex = 0;
182
+ };
183
+
184
+ this._onMouseUp = (_event: MouseEvent) => {
185
+ this.currentFrameIndex = 1;
186
+ };
187
+
188
+ this._onMouseUpOutside = (_event: MouseEvent) => {
189
+ this.currentFrameIndex = 0;
190
+ };
191
+
192
+ this._timeline = timeline;
193
+
194
+ if (spriteMode) {
195
+ this.transformToSprite();
196
+ }
197
+
198
+ this.onSoundCompleteInternal = this.onSoundCompleteInternal.bind(this);
199
+ }
200
+
201
+ /**
202
+ * Reduce frames of timeline to sprite mode.
203
+ * Used for UIComponents, where timeline store more that 1 frame
204
+ */
205
+ public transformToSprite() {
206
+ if (this._isSprite) {
207
+ return;
208
+ }
209
+
210
+ this._isSprite = true;
211
+
212
+ const timeline = this._timeline;
213
+
214
+ // regular MC or frames already is not more 1
215
+ if (timeline.numFrames <= 1) {
216
+ return;
217
+ }
218
+
219
+ timeline.frame_command_indices = <any>[timeline.frame_command_indices[0]];
220
+ timeline.frame_recipe = <any>[timeline.frame_recipe[0]];
221
+ timeline.keyframe_constructframes = [timeline.keyframe_constructframes[0]];
222
+ timeline.keyframe_durations = <any>[timeline.keyframe_durations[0]];
223
+ timeline.keyframe_firstframes = [timeline.keyframe_firstframes[0]];
224
+ timeline.keyframe_indices = [timeline.keyframe_indices[0]];
225
+ }
226
+
227
+ public startSound(
228
+ sound: WaveAudio,
229
+ loopsToPlay: number,
230
+ onSoundComplete?: (event: EventBase) => void
231
+ ) {
232
+
233
+ const channel: IAudioChannel = sound.play(0, loopsToPlay);
234
+
235
+ channel.volume = this._soundVolume;
236
+
237
+ if (onSoundComplete)
238
+ channel.addEventListener(BaseAudioChannel.COMPLETE, onSoundComplete);
239
+
240
+ //internal listener to clear
241
+ channel.addEventListener(BaseAudioChannel.COMPLETE, this.onSoundCompleteInternal);
242
+
243
+ this._sounds[sound.id] = sound;
244
+
245
+ if (!this._activeSounds[sound.id]) {
246
+ this._activeSounds[sound.id] = [];
247
+ }
248
+
249
+ // store channels, stop it instead of sounds
250
+ this._activeSounds[sound.id].push(channel);
251
+ MovieClip._activeSoundsOwners.add(this);
252
+ }
253
+
254
+ public stopSounds(sound: WaveAudio = null) {
255
+ if (sound) {
256
+ this.stopSound(sound);
257
+ } else {
258
+ for (const key in this._sounds)
259
+ this.stopSound(this._sounds[key]);
260
+ }
261
+
262
+ if (Object.getOwnPropertyNames(this._sounds).length === 0) {
263
+ MovieClip._activeSoundsOwners.delete(this);
264
+ }
265
+
266
+ const len: number = this._children.length;
267
+ let child: DisplayObject;
268
+ for (let i: number = 0; i < len; ++i) {
269
+ child = this._children[i];
270
+ if (child.isAsset(MovieClip))
271
+ (<MovieClip>child).stopSounds(sound);
272
+ }
273
+
274
+ this.stopCurrentStream(this._currentFrameIndex);
275
+
276
+ if (this._soundStreams)
277
+ this._soundStreams.syncSounds(0, false, this.parent);
278
+ }
279
+
280
+ /**
281
+ * Compute scene index by global frame index
282
+ * @param frameIndex
283
+ * @private
284
+ */
285
+ private getSceneIndexByFrame(frameIndex: number): number {
286
+ const scenes = this.scenes;
287
+
288
+ if (scenes.length <= 1) {
289
+ return 0;
290
+ }
291
+
292
+ for (let i = 0; i < scenes.length; i++) {
293
+ if (scenes[i].offset > frameIndex) {
294
+ return i - 1;
295
+ }
296
+ }
297
+
298
+ return scenes.length - 1;
299
+ }
300
+
301
+ private getSceneIndex(scene: string) {
302
+ const scenes = this.scenes;
303
+
304
+ for (let i = 0; i < scenes.length && scene; i++) {
305
+ if (scenes[i].name === scene) {
306
+ return i;
307
+ }
308
+ }
309
+
310
+ return 0;
311
+ }
312
+
313
+ public set currentSceneName(scene: string) {
314
+ const index = this.getSceneIndex(scene);
315
+
316
+ this._sceneDirty = this._currentSceneIndex !== index;
317
+ this._currentSceneIndex = index;
318
+ this._currentFrameIndex = this._scenes[index].offset;
319
+ }
320
+
321
+ public get currentSceneName(): string {
322
+ return this.scenes[this._currentSceneIndex].name;
323
+ }
324
+
325
+ public get currentScene(): IScene {
326
+ const currentScene = this.scenes[this._currentSceneIndex];
327
+
328
+ if (currentScene.numFrames === -1) {
329
+ currentScene.numFrames = this.timeline.numFrames - currentScene.offset;
330
+ }
331
+
332
+ return currentScene;
333
+ }
334
+
335
+ public get scenes(): IScene[] {
336
+ if (this._scenes.length === 0) {
337
+ this._scenes[0] = {
338
+ name: 'Scene1',
339
+ offset: 0,
340
+ labels: [],
341
+ numFrames: this.timeline.numFrames,
342
+ };
343
+ }
344
+
345
+ return this._scenes;
346
+ }
347
+
348
+ public set scenes(value: IScene[]) {
349
+ this._scenes = value;
350
+ }
351
+
352
+ public get isPlaying(): boolean {
353
+ return this._isPlaying;
354
+ }
355
+
356
+ public get soundVolume(): number {
357
+ return this._soundVolume;
358
+ }
359
+
360
+ public set soundVolume(value: number) {
361
+ if (this._soundVolume == value)
362
+ return;
363
+
364
+ this._soundVolume = value;
365
+
366
+ let channels: IAudioChannel[];
367
+ for (const key in this._activeSounds)
368
+ if ((channels = this._activeSounds[key]))
369
+ for (const c of channels) c.volume = value;
370
+ }
371
+
372
+ public stopSound(sound: WaveAudio) {
373
+ if (this._sounds[sound.id]) {
374
+ this._sounds[sound.id].stop();
375
+ delete this._sounds[sound.id];
376
+
377
+ if (Object.getOwnPropertyNames(this._sounds).length === 0) {
378
+ MovieClip._activeSoundsOwners.delete(this);
379
+ }
380
+
381
+ const channels = this._activeSounds[sound.id];
382
+ if (channels) {
383
+ for (const c of channels) c.stop();
384
+
385
+ delete this._activeSounds[sound.id];
386
+ }
387
+ }
388
+ }
389
+
390
+ public buttonReset() {
391
+ if (this._isButton && !this.buttonEnabled) {
392
+ this.currentFrameIndex = 0;
393
+ }
394
+ }
395
+
396
+ public getMouseCursor(): string {
397
+ if (this.name == 'scene')
398
+ return 'initial';
399
+ if (this._useHandCursor && this.buttonMode) {
400
+ return this.cursorType;
401
+ }
402
+ return 'initial';
403
+ /*
404
+ var cursorName:string;
405
+ var parent:DisplayObject=this.parent;
406
+ while(parent){
407
+ if(parent.isAsset(MovieClip)){
408
+ cursorName=(<MovieClip>parent).getMouseCursor();
409
+ if(cursorName!="initial"){
410
+ return cursorName;
411
+ }
412
+ }
413
+ parent=parent.parent;
414
+ if(parent && parent.name=="scene"){
415
+ return "initial";
416
+ }
417
+ }
418
+ return "initial";
419
+ */
420
+ }
421
+
422
+ public queueFrameScripts(timeline: Timeline, frame_idx: number, scriptPass1: boolean) {
423
+ console.warn('[MovieClip] - queueFrameScripts should only be called on AVM-Adapters');
424
+ }
425
+
426
+ public registerScriptObject(child: DisplayObject): void {
427
+ this[child.name] = child;
428
+
429
+ if (child.isAsset(MovieClip))
430
+ (<MovieClip>child).removeButtonListeners();
431
+ }
432
+
433
+ public unregisterScriptObject(child: DisplayObject): void {
434
+ delete this[child.name];
435
+
436
+ if (child.isAsset(MovieClip))
437
+ (<MovieClip>child).removeButtonListeners();
438
+ }
439
+
440
+ public dispose(): void {
441
+ this.disposeValues();
442
+
443
+ MovieClip._movieClips.push(this);
444
+ }
445
+
446
+ public disposeValues(): void {
447
+ super.disposeValues();
448
+
449
+ this._sessionID_childs = {};
450
+
451
+ this._timeline = null;
452
+ }
453
+
454
+ public get useHandCursor(): boolean {
455
+ return this._useHandCursor;
456
+ }
457
+
458
+ public set useHandCursor(value: boolean) {
459
+ this._useHandCursor = value;
460
+ }
461
+
462
+ public get buttonMode(): boolean {
463
+ return this._buttonMode;
464
+ }
465
+
466
+ public set buttonMode(value: boolean) {
467
+ this._buttonMode = value;
468
+ }
469
+
470
+ public get isButton(): boolean {
471
+ return this._isButton;
472
+ }
473
+
474
+ public set isButton(value: boolean) {
475
+ this._isButton = value;
476
+ }
477
+
478
+ public get isInit(): boolean {
479
+ return this._isInit;
480
+ }
481
+
482
+ public set isInit(value: boolean) {
483
+ this._isInit = value;
484
+ }
485
+
486
+ public get timeline(): Timeline {
487
+ return this._timeline;
488
+ }
489
+
490
+ public set timeline(value: Timeline) {
491
+ if (this._timeline == value)
492
+ return;
493
+
494
+ this._timeline = value;
495
+
496
+ this.reset(false, false);
497
+ }
498
+
499
+ /**
500
+ *
501
+ */
502
+ public loop: boolean = true;
503
+
504
+ public get numFrames(): number {
505
+ return this._timeline.numFrames;
506
+ }
507
+
508
+ public jumpToLabel(label: string, offset: number = 0): boolean {
509
+ // the timeline.jumpTolabel will set currentFrameIndex
510
+ const index = this._currentFrameIndex;
511
+
512
+ this._timeline.jumpToLabel(this, label, offset);
513
+
514
+ return index !== this._currentFrameIndex;
515
+ }
516
+
517
+ /**
518
+ * the current index of the current active frame
519
+ */
520
+ public constructedKeyFrameIndex: number = -1;
521
+
522
+ public reset(fireScripts: boolean = true, resetSelf: boolean = true): void {
523
+ this._isTimelinePass = true;
524
+
525
+ if (resetSelf)
526
+ super.reset();
527
+
528
+ if (this.id == 4115)
529
+ console.warn('reset', this.id);
530
+
531
+ this.resetStreamStopped();
532
+
533
+ // time only is relevant for the root mc, as it is the only one that executes the update function
534
+ this._time = 0;
535
+ //this.stopSounds();
536
+
537
+ if (resetSelf && this._adapter)
538
+ (<IMovieClipAdapter> this.adapter).freeFromScript();
539
+
540
+ this.constructedKeyFrameIndex = -1;
541
+ for (let i: number = this.numChildren - 1; i >= 0; i--)
542
+ this.removeChildAt(i);
543
+
544
+ if (this._graphics)
545
+ this._graphics.clear();
546
+
547
+ if (fireScripts) {
548
+ const numFrames: number = this._timeline.keyframe_indices.length;
549
+ this._isPlaying = Boolean(numFrames > 1);
550
+ this._currentSceneIndex = 0;
551
+
552
+ if (numFrames) {
553
+ this._currentFrameIndex = 0;
554
+ // contruct the timeline and queue the script.
555
+ //if(fireScripts){
556
+ this._timeline.constructNextFrame(this, fireScripts && !this.doingSwap && !this.preventScript, true);
557
+ //}
558
+ } else {
559
+ this._currentFrameIndex = -1;
560
+ }
561
+ }
562
+ // prevents the playhead to get moved in the advance frame again:
563
+ this._skipAdvance = true;
564
+ this._isTimelinePass = false;
565
+ }
566
+
567
+ public set currentFrameIndex(value: number) {
568
+ this.jumpToIndex(value);
569
+ }
570
+
571
+ public get currentFrameIndex() {
572
+ return this._currentFrameIndex;
573
+ }
574
+
575
+ /*
576
+ * Setting the currentFrameIndex will move the playhead for this movieclip to the new position
577
+ */
578
+ public get currentFrameIndexRelative(): number {
579
+ return this._currentFrameIndex - this.currentScene.offset;
580
+ }
581
+
582
+ public set currentFrameIndexRelative(value: number) {
583
+ this.jumpToIndex(value, this._currentSceneIndex);
584
+ }
585
+
586
+ public jumpToIndex(value: number, sceneIndex?: string | number): boolean {
587
+ let queue_script: boolean = true;
588
+
589
+ let offset: number = 0;
590
+ let numFrames: number = this._timeline.keyframe_indices.length;
591
+
592
+ this.resetStreamStopped();
593
+ if (!numFrames)
594
+ return false;
595
+
596
+ const scenes = this.scenes;
597
+
598
+ // scene not presented - global navigation
599
+ // we should compute scene index and shift frame
600
+ if (typeof sceneIndex === 'undefined') {
601
+
602
+ sceneIndex = this.getSceneIndexByFrame(value);
603
+
604
+ } else {
605
+ sceneIndex = typeof sceneIndex === 'string' ? this.getSceneIndex(sceneIndex) : sceneIndex;
606
+
607
+ const scene = scenes[sceneIndex];
608
+
609
+ // fix negative frames size on latest scene.
610
+ // this is because we don't know how many frames in instance time
611
+ if (scene.numFrames === -1) {
612
+ scene.numFrames = numFrames - scene.offset;
613
+ }
614
+
615
+ offset = scene.offset;
616
+ numFrames = scene.numFrames;
617
+ }
618
+
619
+ this._currentSceneIndex = sceneIndex;
620
+
621
+ if (value < 0) {
622
+ value = 0;
623
+ } else if (value >= numFrames) {
624
+ // if value is greater than the available number of
625
+ // frames, the playhead is moved to the last frame in the timeline.
626
+ // In this case the frame specified is not considered a keyframe,
627
+ // no scripts should be executed in this case
628
+ value = numFrames - 1;
629
+ queue_script = false;
630
+ }
631
+
632
+ value += offset;
633
+
634
+ this._skipAdvance = false;
635
+ if (this._currentFrameIndex === value && !this._sceneDirty)
636
+ return false;
637
+
638
+ this._sceneDirty = false;
639
+ this._currentFrameIndex = value;
640
+
641
+ //console.log("_currentFrameIndex ", this.name, this._currentFrameIndex);
642
+ //changing current frame will ignore advance command for that
643
+ //update's advanceFrame function, unless advanceFrame has
644
+ //already been executed
645
+
646
+ this._timeline.gotoFrame(this, value, queue_script, false, false);
647
+
648
+ return true;
649
+ }
650
+
651
+ public addButtonListeners(): void {
652
+ this._isButton = true;
653
+
654
+ this.stop();
655
+
656
+ this.addEventListener(MouseEvent.MOUSE_OVER, this._onMouseOver);
657
+ this.addEventListener(MouseEvent.MOUSE_OUT, this._onMouseOut);
658
+ this.addEventListener(MouseEvent.MOUSE_DOWN, this._onMouseDown);
659
+ this.addEventListener(MouseEvent.MOUSE_UP, this._onMouseUp);
660
+ this.addEventListener(MouseEvent.MOUSE_UP_OUTSIDE, this._onMouseUpOutside);
661
+
662
+ this.mouseChildren = false;
663
+ }
664
+
665
+ public removeButtonListeners(): void {
666
+ this.removeEventListener(MouseEvent.MOUSE_OVER, this._onMouseOver);
667
+ this.removeEventListener(MouseEvent.MOUSE_OUT, this._onMouseOut);
668
+ this.removeEventListener(MouseEvent.MOUSE_DOWN, this._onMouseDown);
669
+ this.removeEventListener(MouseEvent.MOUSE_UP, this._onMouseUp);
670
+ this.removeEventListener(MouseEvent.MOUSE_UP_OUTSIDE, this._onMouseUpOutside);
671
+ }
672
+
673
+ public getTimelineChildAtSessionID(sessionID: number): DisplayObject {
674
+ return this._sessionID_childs[sessionID];
675
+ }
676
+
677
+ // should only be called from timeline when navigating frames
678
+ public constructFrame(timeline: Timeline, start_construct_idx: number,
679
+ target_keyframe_idx: number, jump_forward: boolean,
680
+ frame_idx: number, queue_pass2: boolean, queue_script: boolean) {
681
+ console.warn('[scene/MovieClip] - constructFrame not implemented');
682
+ }
683
+
684
+ public addTimelineChildAtDepth(child: DisplayObject, depth: number, sessionID: number): DisplayObject {
685
+ console.warn('[scene/MovieClip] - addTimelineChildAtDepth not implemented');
686
+ return null;
687
+ }
688
+
689
+ public removeTimelineChildAtDepth(depth: number): void {
690
+ console.warn('[scene/MovieClip] - removeTimelineChildAtDepth not implemented');
691
+ }
692
+
693
+ public removeChildAtInternal(index: number): DisplayObject {
694
+ const child: DisplayObject = this._children[index];
695
+
696
+ if (child._adapter)
697
+ (<IMovieClipAdapter>child.adapter).freeFromScript();
698
+
699
+ // only timeline can do this
700
+ if (this._isTimelinePass) {
701
+
702
+ (<IMovieClipAdapter> this.adapter).unregisterScriptObject(child);
703
+ }
704
+
705
+ delete this._sessionID_childs[child._sessionID];
706
+
707
+ child._sessionID = -1;
708
+
709
+ if (child.adapter && (<any>child.adapter).dispatchStaticEvent) {
710
+ (<any>child.adapter).dispatchStaticEvent('removed', child.adapter);
711
+ }
712
+ if (this.isOnDisplayList() && (<any>child.adapter).dispatch_REMOVED_FROM_STAGE) {
713
+ (<any>child.adapter).dispatch_REMOVED_FROM_STAGE(<DisplayObjectContainer>child);
714
+ }
715
+
716
+ return super.removeChildAtInternal(index);
717
+ }
718
+
719
+ public get assetType(): string {
720
+ return MovieClip.assetType;
721
+ }
722
+
723
+ /**
724
+ * Starts playback of animation from current position
725
+ */
726
+ public play(): void {
727
+ if (this._timeline.keyframe_indices.length > 1)
728
+ this._isPlaying = true;
729
+ }
730
+
731
+ /**
732
+ * Stop playback of animation and hold current position
733
+ */
734
+ public stop(): void {
735
+ //this.stopSounds();
736
+ this.resetStreamStopped();
737
+ this._isPlaying = false;
738
+ }
739
+
740
+ public clone(): MovieClip {
741
+ const newInstance: MovieClip = MovieClip.getNewMovieClip(this._timeline);
742
+
743
+ this.copyTo(newInstance);
744
+
745
+ return newInstance;
746
+ }
747
+
748
+ public copyTo(movieClip: MovieClip): void {
749
+ super.copyTo(movieClip);
750
+
751
+ movieClip.buttonMode = this.buttonMode;
752
+ movieClip.symbolID = this.symbolID;
753
+ movieClip.loop = this.loop;
754
+ movieClip._soundStreams = this._soundStreams;
755
+ movieClip._scenes = this._scenes;
756
+
757
+ // move to sprite mode too
758
+ if (this._isSprite) {
759
+ movieClip.transformToSprite();
760
+ }
761
+ }
762
+
763
+ public advanceFrameInternal(): void {
764
+ // if this._skipadvance is true, the mc has already been moving on its timeline this frame
765
+ // this happens for objects that have been newly added to parent
766
+ // they still need to queue their scripts
767
+
768
+ //if(this._timeline && this._timeline.numFrames>0)
769
+ if (this._timeline && this._timeline.numFrames > 0 && this._isPlaying && !this._skipAdvance) {
770
+
771
+ if (this._currentFrameIndex === this._timeline.numFrames - 1) {
772
+ if (this.loop) {
773
+ if (this._currentFrameIndex !== 0) {
774
+ this._currentFrameIndex = 0;
775
+ this._currentSceneIndex = 0;
776
+
777
+ this.resetStreamStopped();
778
+ this._timeline.gotoFrame(this, 0, true, true, true);
779
+ }
780
+ // end of loop - jump to first frame.
781
+ } else //end of timeline, stop playing
782
+ this._isPlaying = false;
783
+ } else { // not end - construct next frame
784
+ this._currentFrameIndex++;
785
+ this._currentSceneIndex = this.getSceneIndexByFrame(this._currentFrameIndex);
786
+
787
+ this._timeline.constructNextFrame(this);
788
+ }
789
+ //console.log("advancedFrame ", this.name, this._currentFrameIndex);
790
+ }
791
+
792
+ super.advanceFrame();
793
+ this._skipAdvance = false;
794
+ }
795
+
796
+ public advanceFrame(): void {
797
+ this._isTimelinePass = true;
798
+ if (this._skipFramesForStream == 0) {
799
+ this.advanceFrameInternal();
800
+ }
801
+ /*if(this._skipFramesForStream<0){
802
+ console.log("wait for audio to catch up");
803
+ }*/
804
+ this._skipFramesForStream = this._syncSounds(this._currentFrameIndex);
805
+ while (this._skipFramesForStream > 0) {
806
+ //console.log("skip frame for keeping audio stream synced");
807
+ FrameScriptManager.execute_queue();
808
+ this.advanceFrameInternal();
809
+ this._skipFramesForStream = this._syncSounds(this._currentFrameIndex);
810
+ }
811
+
812
+ this._isTimelinePass = false;
813
+ }
814
+
815
+ // DEBUG CODE:
816
+ logHierarchy(depth: number = 0): void {
817
+ this.printHierarchyName(depth, this);
818
+
819
+ const len = this._children.length;
820
+ let child: DisplayObject;
821
+ for (let i: number = 0; i < len; i++) {
822
+ child = this._children[i];
823
+
824
+ if (child.isAsset(MovieClip))
825
+ (<MovieClip>child).logHierarchy(depth + 1);
826
+ else
827
+ this.printHierarchyName(depth + 1, child);
828
+ }
829
+ }
830
+
831
+ printHierarchyName(depth: number, target: DisplayObject): void {
832
+ let str = '';
833
+ for (let i = 0; i < depth; ++i)
834
+ str += '--';
835
+
836
+ str += ' ' + target.name + ' = ' + target.id;
837
+ console.log(str);
838
+ }
839
+
840
+ public clear(): void {
841
+ //clear out potential instances
842
+ this.resetStreamStopped();
843
+ /* check memory disposal with new approach of child-instancing
844
+ for (var key in this._potentialInstances) {
845
+ var instance: IAsset = this._potentialInstances[key];
846
+
847
+ //only dispose instances that are not used in script ie. do not have an instance name
848
+ if (instance && !instance.name) {
849
+ if (!instance.isAsset(Sprite)) {
850
+ FrameScriptManager.add_child_to_dispose(<DisplayObject>instance);
851
+
852
+ }
853
+ delete this._potentialInstances[key];
854
+ }
855
+ }
856
+ */
857
+
858
+ super.clear();
859
+ }
860
+
861
+ private onSoundCompleteInternal(event: EventBase): void {
862
+ const channel: IAudioChannel = event.target;
863
+ const sound = channel.owner;
864
+ const channels = this._activeSounds[sound.id];
865
+ const index = channels.indexOf(channel);
866
+
867
+ if (index != -1) {
868
+ channels.splice(index, 1);
869
+ }
870
+
871
+ if (channels.length === 0)
872
+ delete this._sounds[sound.id];
873
+
874
+ if (Object.getOwnPropertyNames(this._sounds).length === 0)
875
+ MovieClip._activeSoundsOwners.delete(this);
876
+ }
877
+ }
878
+
879
+ PartitionBase.registerAbstraction(EntityNode, MovieClip);