@awayjs/scene 0.13.326 → 0.13.328

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