@awayjs/scene 0.13.324 → 0.13.325

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 (263) hide show
  1. package/.eslintrc +100 -100
  2. package/README.md +61 -61
  3. package/bundle/awayjs-scene.umd.js +1 -1
  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.js +285 -285
  10. package/dist/lib/Settings.d.ts +16 -16
  11. package/dist/lib/Settings.js +60 -60
  12. package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
  13. package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
  14. package/dist/lib/adapters/IFilter.d.ts +24 -24
  15. package/dist/lib/adapters/IFilter.js +1 -1
  16. package/dist/lib/adapters/IMovieClipAdapter.d.ts +15 -15
  17. package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
  18. package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
  19. package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
  20. package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
  21. package/dist/lib/base/IBitmapDrawable.js +1 -1
  22. package/dist/lib/base/IFrameLabel.d.ts +4 -4
  23. package/dist/lib/base/IFrameLabel.js +1 -1
  24. package/dist/lib/base/IFrameScript.d.ts +5 -5
  25. package/dist/lib/base/IFrameScript.js +1 -1
  26. package/dist/lib/base/MouseButtons.d.ts +26 -26
  27. package/dist/lib/base/MouseButtons.js +1 -1
  28. package/dist/lib/base/Timeline.d.ts +147 -147
  29. package/dist/lib/base/Timeline.js +525 -525
  30. package/dist/lib/base/TimelineActionType.d.ts +18 -18
  31. package/dist/lib/base/TimelineActionType.js +1 -1
  32. package/dist/lib/controllers/ControllerBase.d.ts +14 -14
  33. package/dist/lib/controllers/ControllerBase.js +60 -60
  34. package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
  35. package/dist/lib/controllers/FirstPersonController.js +228 -228
  36. package/dist/lib/controllers/FollowController.d.ts +12 -12
  37. package/dist/lib/controllers/FollowController.js +27 -27
  38. package/dist/lib/controllers/HoverController.d.ts +105 -105
  39. package/dist/lib/controllers/HoverController.js +302 -302
  40. package/dist/lib/controllers/LookAtController.d.ts +14 -14
  41. package/dist/lib/controllers/LookAtController.js +68 -68
  42. package/dist/lib/controllers/SpringController.d.ts +38 -38
  43. package/dist/lib/controllers/SpringController.js +59 -59
  44. package/dist/lib/display/Billboard.d.ts +132 -132
  45. package/dist/lib/display/Billboard.js +397 -397
  46. package/dist/lib/display/Camera.d.ts +31 -31
  47. package/dist/lib/display/Camera.js +72 -72
  48. package/dist/lib/display/DisplayObject.d.ts +921 -921
  49. package/dist/lib/display/DisplayObject.js +1595 -1595
  50. package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
  51. package/dist/lib/display/DisplayObjectContainer.js +486 -486
  52. package/dist/lib/display/LineSegment.d.ts +69 -69
  53. package/dist/lib/display/LineSegment.js +203 -203
  54. package/dist/lib/display/LoaderContainer.d.ts +504 -504
  55. package/dist/lib/display/LoaderContainer.js +603 -603
  56. package/dist/lib/display/MorphSprite.d.ts +20 -20
  57. package/dist/lib/display/MorphSprite.js +246 -246
  58. package/dist/lib/display/MovieClip.d.ts +149 -149
  59. package/dist/lib/display/MovieClip.js +733 -733
  60. package/dist/lib/display/SimpleButton.d.ts +158 -158
  61. package/dist/lib/display/SimpleButton.js +228 -228
  62. package/dist/lib/display/Skybox.d.ts +144 -144
  63. package/dist/lib/display/Skybox.js +288 -288
  64. package/dist/lib/display/Sprite.d.ts +65 -65
  65. package/dist/lib/display/Sprite.js +134 -134
  66. package/dist/lib/display/TextField.d.ts +1104 -1104
  67. package/dist/lib/display/TextField.d.ts.map +1 -1
  68. package/dist/lib/display/TextField.js +3019 -3018
  69. package/dist/lib/display/TextSprite.d.ts +16 -16
  70. package/dist/lib/display/TextSprite.js +36 -36
  71. package/dist/lib/elements/SkyboxElements.d.ts +29 -29
  72. package/dist/lib/elements/SkyboxElements.js +127 -127
  73. package/dist/lib/errors/CastError.d.ts +4 -4
  74. package/dist/lib/errors/CastError.js +10 -10
  75. package/dist/lib/events/CameraEvent.d.ts +16 -16
  76. package/dist/lib/events/CameraEvent.js +30 -30
  77. package/dist/lib/events/FocusEvent.d.ts +42 -42
  78. package/dist/lib/events/FocusEvent.js +43 -43
  79. package/dist/lib/events/KeyboardEvent.d.ts +21 -21
  80. package/dist/lib/events/KeyboardEvent.js +43 -43
  81. package/dist/lib/events/MouseEvent.d.ts +91 -91
  82. package/dist/lib/events/MouseEvent.js +122 -122
  83. package/dist/lib/events/PointerEvent.d.ts +93 -93
  84. package/dist/lib/events/PointerEvent.js +73 -73
  85. package/dist/lib/events/ResizeEvent.d.ts +15 -15
  86. package/dist/lib/events/ResizeEvent.js +38 -38
  87. package/dist/lib/events/TextfieldEvent.d.ts +19 -19
  88. package/dist/lib/events/TextfieldEvent.js +28 -28
  89. package/dist/lib/events/TouchEvent.d.ts +54 -54
  90. package/dist/lib/events/TouchEvent.js +89 -89
  91. package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +27 -27
  92. package/dist/lib/factories/DefaultSceneGraphFactory.js +55 -55
  93. package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
  94. package/dist/lib/factories/ISceneGraphFactory.js +1 -1
  95. package/dist/lib/image/SceneImage2D.d.ts +220 -220
  96. package/dist/lib/image/SceneImage2D.js +610 -610
  97. package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
  98. package/dist/lib/managers/DefaultFontManager.js +101 -101
  99. package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
  100. package/dist/lib/managers/DeviceFontManager.js +44 -44
  101. package/dist/lib/managers/FrameScriptManager.d.ts +37 -37
  102. package/dist/lib/managers/FrameScriptManager.js +386 -386
  103. package/dist/lib/managers/IInputRecorder.d.ts +3 -3
  104. package/dist/lib/managers/IInputRecorder.js +1 -1
  105. package/dist/lib/managers/MouseManager.d.ts +74 -74
  106. package/dist/lib/managers/MouseManager.js +803 -803
  107. package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
  108. package/dist/lib/prefabs/PrefabBase.js +42 -42
  109. package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
  110. package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
  111. package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
  112. package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
  113. package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
  114. package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
  115. package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
  116. package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
  117. package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
  118. package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
  119. package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
  120. package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
  121. package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
  122. package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
  123. package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
  124. package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
  125. package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
  126. package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
  127. package/dist/lib/text/AntiAliasType.d.ts +24 -24
  128. package/dist/lib/text/AntiAliasType.js +28 -28
  129. package/dist/lib/text/BitmapFontChar.d.ts +39 -39
  130. package/dist/lib/text/BitmapFontChar.js +42 -42
  131. package/dist/lib/text/BitmapFontTable.d.ts +73 -73
  132. package/dist/lib/text/BitmapFontTable.js +183 -183
  133. package/dist/lib/text/FNTGenerator.d.ts +10 -10
  134. package/dist/lib/text/FNTGenerator.js +74 -74
  135. package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
  136. package/dist/lib/text/FNTGeneratorCanvas.js +211 -211
  137. package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
  138. package/dist/lib/text/FNTGeneratrorBase.js +7 -7
  139. package/dist/lib/text/Font.d.ts +38 -38
  140. package/dist/lib/text/Font.js +109 -109
  141. package/dist/lib/text/FontLookUpMode.d.ts +5 -5
  142. package/dist/lib/text/FontLookUpMode.js +7 -7
  143. package/dist/lib/text/FontStyleName.d.ts +6 -6
  144. package/dist/lib/text/FontStyleName.js +7 -7
  145. package/dist/lib/text/GridFitType.d.ts +31 -31
  146. package/dist/lib/text/GridFitType.js +35 -35
  147. package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
  148. package/dist/lib/text/HTMLTextProcessor.js +426 -426
  149. package/dist/lib/text/IFontTable.d.ts +16 -16
  150. package/dist/lib/text/IFontTable.js +1 -1
  151. package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
  152. package/dist/lib/text/TesselatedFontChar.js +66 -66
  153. package/dist/lib/text/TesselatedFontTable.d.ts +88 -88
  154. package/dist/lib/text/TesselatedFontTable.js +963 -963
  155. package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
  156. package/dist/lib/text/TextFieldAutoSize.js +32 -32
  157. package/dist/lib/text/TextFieldType.d.ts +20 -20
  158. package/dist/lib/text/TextFieldType.js +24 -24
  159. package/dist/lib/text/TextFormat.d.ts +273 -273
  160. package/dist/lib/text/TextFormat.js +449 -449
  161. package/dist/lib/text/TextFormatAlign.d.ts +26 -26
  162. package/dist/lib/text/TextFormatAlign.js +30 -30
  163. package/dist/lib/text/TextInteractionMode.d.ts +21 -21
  164. package/dist/lib/text/TextInteractionMode.js +25 -25
  165. package/dist/lib/text/TextLineMetrics.d.ts +61 -61
  166. package/dist/lib/text/TextLineMetrics.js +42 -42
  167. package/dist/lib/text/TextShape.d.ts +22 -22
  168. package/dist/lib/text/TextShape.js +75 -75
  169. package/dist/lib/tools/Merge.d.ts +81 -81
  170. package/dist/lib/tools/Merge.js +266 -266
  171. package/dist/lib/utils/Cast.d.ts +20 -20
  172. package/dist/lib/utils/Cast.js +271 -271
  173. package/index.ts +92 -92
  174. package/lib/Scene.ts +339 -339
  175. package/lib/Settings.ts +83 -83
  176. package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
  177. package/lib/adapters/IFilter.ts +25 -25
  178. package/lib/adapters/IMovieClipAdapter.ts +26 -26
  179. package/lib/adapters/ITextfieldAdapter.ts +6 -6
  180. package/lib/base/IBitmapDrawable.ts +13 -13
  181. package/lib/base/IFrameLabel.ts +3 -3
  182. package/lib/base/IFrameScript.ts +4 -4
  183. package/lib/base/MouseButtons.ts +31 -31
  184. package/lib/base/Timeline.ts +715 -715
  185. package/lib/base/TimelineActionType.ts +18 -18
  186. package/lib/controllers/ControllerBase.ts +66 -66
  187. package/lib/controllers/FirstPersonController.ts +241 -241
  188. package/lib/controllers/FollowController.ts +22 -22
  189. package/lib/controllers/HoverController.ts +304 -304
  190. package/lib/controllers/LookAtController.ts +75 -75
  191. package/lib/controllers/SpringController.ts +91 -91
  192. package/lib/display/Billboard.ts +468 -468
  193. package/lib/display/Camera.ts +75 -75
  194. package/lib/display/DisplayObject.ts +1829 -1829
  195. package/lib/display/DisplayObjectContainer.ts +546 -546
  196. package/lib/display/LineSegment.ts +229 -229
  197. package/lib/display/LoaderContainer.ts +651 -651
  198. package/lib/display/MorphSprite.ts +339 -339
  199. package/lib/display/MovieClip.ts +870 -870
  200. package/lib/display/SimpleButton.ts +224 -224
  201. package/lib/display/Skybox.ts +352 -352
  202. package/lib/display/Sprite.ts +154 -154
  203. package/lib/display/TextField.ts +3876 -3875
  204. package/lib/display/TextSprite.ts +34 -34
  205. package/lib/elements/SkyboxElements.ts +141 -141
  206. package/lib/errors/CastError.ts +6 -6
  207. package/lib/events/CameraEvent.ts +29 -29
  208. package/lib/events/FocusEvent.ts +69 -69
  209. package/lib/events/KeyboardEvent.ts +40 -40
  210. package/lib/events/MouseEvent.ts +144 -144
  211. package/lib/events/PointerEvent.ts +145 -145
  212. package/lib/events/ResizeEvent.ts +31 -31
  213. package/lib/events/TextfieldEvent.ts +28 -28
  214. package/lib/events/TouchEvent.ts +103 -103
  215. package/lib/factories/DefaultSceneGraphFactory.ts +58 -58
  216. package/lib/factories/ISceneGraphFactory.ts +28 -28
  217. package/lib/image/SceneImage2D.ts +912 -912
  218. package/lib/managers/DefaultFontManager.ts +124 -124
  219. package/lib/managers/DeviceFontManager.ts +55 -55
  220. package/lib/managers/FrameScriptManager.ts +440 -440
  221. package/lib/managers/IInputRecorder.ts +2 -2
  222. package/lib/managers/MouseManager.ts +942 -942
  223. package/lib/prefabs/PrefabBase.ts +47 -47
  224. package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
  225. package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
  226. package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
  227. package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
  228. package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
  229. package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
  230. package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
  231. package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
  232. package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
  233. package/lib/text/AntiAliasType.ts +24 -24
  234. package/lib/text/BitmapFontChar.ts +53 -53
  235. package/lib/text/BitmapFontTable.ts +213 -213
  236. package/lib/text/FNTGenerator.ts +100 -100
  237. package/lib/text/FNTGeneratorCanvas.ts +292 -292
  238. package/lib/text/FNTGeneratrorBase.ts +10 -10
  239. package/lib/text/Font.ts +114 -114
  240. package/lib/text/FontLookUpMode.ts +5 -5
  241. package/lib/text/FontStyleName.ts +6 -6
  242. package/lib/text/GridFitType.ts +32 -32
  243. package/lib/text/HTMLTextProcessor.ts +421 -421
  244. package/lib/text/IFontTable.ts +17 -17
  245. package/lib/text/TesselatedFontChar.ts +80 -80
  246. package/lib/text/TesselatedFontTable.ts +1181 -1181
  247. package/lib/text/TextFieldAutoSize.ts +30 -30
  248. package/lib/text/TextFieldType.ts +21 -21
  249. package/lib/text/TextFormat.ts +603 -603
  250. package/lib/text/TextFormatAlign.ts +28 -28
  251. package/lib/text/TextInteractionMode.ts +21 -21
  252. package/lib/text/TextLineMetrics.ts +74 -74
  253. package/lib/text/TextShape.ts +91 -91
  254. package/lib/tools/Merge.ts +311 -311
  255. package/lib/utils/Cast.ts +304 -304
  256. package/package.json +74 -74
  257. package/rollup.config.js +33 -33
  258. package/scripts/build.sh +2 -2
  259. package/scripts/gendocs.sh +14 -14
  260. package/scripts/genexamples.sh +14 -14
  261. package/scripts/genfull.sh +14 -14
  262. package/system.config.js +51 -51
  263. package/tsconfig.json +18 -18
@@ -1,652 +1,652 @@
1
- import { AssetLibraryBundle, Loader, LoaderContext, URLRequest, AssetEvent,
2
- URLLoaderEvent, LoaderEvent, ParserEvent, ParserBase, EventBase } from '@awayjs/core';
3
-
4
- import { DisplayObjectContainer } from './DisplayObjectContainer';
5
- import { DisplayObject } from './DisplayObject';
6
-
7
- /**
8
- * The LoaderContainer class is used to load SWF files or image(JPG, PNG, or GIF)
9
- * files. Use the <code>load()</code> method to initiate loading. The loaded
10
- * display object is added as a child of the LoaderContainer object.
11
- *
12
- * <p>Use the URLLoader class to load text or binary data.</p>
13
- *
14
- * <p>The LoaderContainer class overrides the following methods that it inherits,
15
- * because a LoaderContainer object can only have one child display object - the
16
- * display object that it loads. Calling the following methods throws an
17
- * exception: <code>addChild()</code>, <code>addChildAt()</code>,
18
- * <code>removeChild()</code>, <code>removeChildAt()</code>, and
19
- * <code>setChildIndex()</code>. To remove a loaded display object, you must
20
- * remove the <i>LoaderContainer</i> object from its parent DisplayObjectContainer
21
- * child array. </p>
22
- *
23
- * <p><b>Note:</b> The ActionScript 2.0 MovieClipLoader and LoadVars classes
24
- * are not used in ActionScript 3.0. The LoaderContainer and URLLoader classes replace
25
- * them.</p>
26
- *
27
- * <p>When you use the LoaderContainer class, consider the Flash Player and Adobe AIR
28
- * security model: </p>
29
- *
30
- * <ul>
31
- * <li>You can load content from any accessible source. </li>
32
- * <li>Loading is not allowed if the calling SWF file is in a network
33
- * sandbox and the file to be loaded is local. </li>
34
- * <li>If the loaded content is a SWF file written with ActionScript 3.0, it
35
- * cannot be cross-scripted by a SWF file in another security sandbox unless
36
- * that cross-scripting arrangement was approved through a call to the
37
- * <code>System.allowDomain()</code> or the
38
- * <code>System.allowInsecureDomain()</code> method in the loaded content
39
- * file.</li>
40
- * <li>If the loaded content is an AVM1 SWF file(written using ActionScript
41
- * 1.0 or 2.0), it cannot be cross-scripted by an AVM2 SWF file(written using
42
- * ActionScript 3.0). However, you can communicate between the two SWF files
43
- * by using the LocalConnection class.</li>
44
- * <li>If the loaded content is an image, its data cannot be accessed by a
45
- * SWF file outside of the security sandbox, unless the domain of that SWF
46
- * file was included in a URL policy file at the origin domain of the
47
- * image.</li>
48
- * <li>Movie clips in the local-with-file-system sandbox cannot script movie
49
- * clips in the local-with-networking sandbox, and the reverse is also
50
- * prevented. </li>
51
- * <li>You cannot connect to commonly reserved ports. For a complete list of
52
- * blocked ports, see "Restricting Networking APIs" in the <i>ActionScript 3.0
53
- * Developer's Guide</i>. </li>
54
- * </ul>
55
- *
56
- * <p>However, in AIR, content in the <code>application</code> security
57
- * sandbox(content installed with the AIR application) are not restricted by
58
- * these security limitations.</p>
59
- *
60
- * <p>For more information related to security, see the Flash Player Developer
61
- * Center Topic: <a href="http://www.adobe.com/go/devnet_security_en"
62
- * scope="external">Security</a>.</p>
63
- *
64
- * <p>When loading a SWF file from an untrusted source(such as a domain other
65
- * than that of the LoaderContainer object's root SWF file), you may want to define a
66
- * mask for the LoaderContainer object, to prevent the loaded content(which is a child
67
- * of the LoaderContainer object) from drawing to portions of the Stage outside of that
68
- * mask, as shown in the following code:</p>
69
- */
70
- export class LoaderContainer extends DisplayObjectContainer {
71
- /**
72
- * Dispatched when any asset finishes parsing. Also see specific events for each
73
- * individual asset type (sprites, materials et c.)
74
- *
75
- * @eventType AssetEvent
76
- */
77
- //[Event(name="assetComplete", type="AssetEvent")]
78
-
79
- /**
80
- * Dispatched when a full resource (including dependencies) finishes loading.
81
- *
82
- * @eventType LoaderEvent
83
- */
84
- //[Event(name="resourceComplete", type="LoaderEvent")]
85
-
86
- private _contentLoader: Loader;
87
- private _useAssetLib: boolean;
88
- private _assetLibId: string;
89
- private _onLoaderStartDelegate: (event: LoaderEvent) => void;
90
- private _onLoadProgressDelegate: (event: URLLoaderEvent) => void;
91
- private _onLoadCompleteDelegate: (event: URLLoaderEvent) => void;
92
- private _onAssetCompleteDelegate: (event: AssetEvent) => void;
93
- private _onLoaderCompleteDelegate: (event: LoaderEvent) => void;
94
- private _onLoadErrorDelegate: (event: URLLoaderEvent) => void;
95
- private _onParseErrorDelegate: (event: ParserEvent) => void;
96
- private _errorDelegateSelector: {[index: string]: ((event: EventBase) => void)};
97
-
98
- private _content: DisplayObject;
99
-
100
- /**
101
- * Contains the root display object of the SWF file or image(JPG, PNG, or
102
- * GIF) file that was loaded by using the <code>load()</code> or
103
- * <code>loadBytes()</code> methods.
104
- *
105
- * @throws SecurityError The loaded SWF file or image file belongs to a
106
- * security sandbox to which you do not have access.
107
- * For a loaded SWF file, you can avoid this situation
108
- * by having the file call the
109
- * <code>Security.allowDomain()</code> method or by
110
- * having the loading file specify a
111
- * <code>loaderContext</code> parameter with its
112
- * <code>securityDomain</code> property set to
113
- * <code>SecurityDomain.currentDomain</code> when you
114
- * call the <code>load()</code> or
115
- * <code>loadBytes()</code> method.
116
- */
117
- public get content(): DisplayObject {
118
- return this._content;
119
- }
120
-
121
- /**
122
- *
123
- */
124
- public get contentLoader(): Loader {
125
- return this._contentLoader;
126
- }
127
-
128
- /**
129
- * Creates a Loader object that you can use to load files, such as SWF, JPEG,
130
- * GIF, or PNG files. Call the <code>load()</code> method to load the asset
131
- * as a child of the Loader instance. You can then add the Loader object to
132
- * the display list(for instance, by using the <code>addChild()</code>
133
- * method of a DisplayObjectContainer instance). The asset appears on the
134
- * Stage as it loads.
135
- *
136
- * <p>You can also use a Loader instance "offlist," that is without adding it
137
- * to a display object container on the display list. In this mode, the
138
- * Loader instance might be used to load a SWF file that contains additional
139
- * modules of an application. </p>
140
- *
141
- * <p>To detect when the SWF file is finished loading, you can use the events
142
- * of the LoaderInfo object associated with the
143
- * <code>contentLoaderInfo</code> property of the Loader object. At that
144
- * point, the code in the module SWF file can be executed to initialize and
145
- * start the module. In the offlist mode, a Loader instance might also be
146
- * used to load a SWF file that contains components or media assets. Again,
147
- * you can use the LoaderInfo object event notifications to detect when the
148
- * components are finished loading. At that point, the application can start
149
- * using the components and media assets in the library of the SWF file by
150
- * instantiating the ActionScript 3.0 classes that represent those components
151
- * and assets.</p>
152
- *
153
- * <p>To determine the status of a Loader object, monitor the following
154
- * events that the LoaderInfo object associated with the
155
- * <code>contentLoaderInfo</code> property of the Loader object:</p>
156
- *
157
- * <ul>
158
- * <li>The <code>open</code> event is dispatched when loading begins.</li>
159
- * <li>The <code>ioError</code> or <code>securityError</code> event is
160
- * dispatched if the file cannot be loaded or if an error occured during the
161
- * load process. </li>
162
- * <li>The <code>progress</code> event fires continuously while the file is
163
- * being loaded.</li>
164
- * <li>The <code>complete</code> event is dispatched when a file completes
165
- * downloading, but before the loaded movie clip's methods and properties are
166
- * available. </li>
167
- * <li>The <code>init</code> event is dispatched after the properties and
168
- * methods of the loaded SWF file are accessible, so you can begin
169
- * manipulating the loaded SWF file. This event is dispatched before the
170
- * <code>complete</code> handler. In streaming SWF files, the
171
- * <code>init</code> event can occur significantly earlier than the
172
- * <code>complete</code> event. For most purposes, use the <code>init</code>
173
- * handler.</li>
174
- * </ul>
175
- */
176
- constructor(useAssetLibrary: boolean = true, assetLibraryId: string = null) {
177
- super();
178
-
179
- this._useAssetLib = useAssetLibrary;
180
- this._assetLibId = assetLibraryId;
181
-
182
- this._onLoaderStartDelegate = (event: LoaderEvent) => this._onLoaderStart(event);
183
- this._onLoadProgressDelegate = (event: URLLoaderEvent) => this._onLoadProgress(event);
184
- this._onLoadCompleteDelegate = (event: URLLoaderEvent) => this._onLoadComplete(event);
185
- this._onAssetCompleteDelegate = (event: AssetEvent) => this._onAssetComplete(event);
186
- this._onLoaderCompleteDelegate = (event: LoaderEvent) => this._onLoaderComplete(event);
187
- this._onLoadErrorDelegate = (event: URLLoaderEvent) => this._onLoadError(event);
188
- this._onParseErrorDelegate = (event: ParserEvent) => this._onParseError(event);
189
-
190
- this._errorDelegateSelector = {
191
- [URLLoaderEvent.LOAD_ERROR]: this._onLoadErrorDelegate,
192
- [ParserEvent.PARSE_ERROR]: this._onParseErrorDelegate
193
- };
194
- }
195
-
196
- /**
197
- * Special addEventListener case for <code>
198
- * URLLoaderEvent.LOAD_ERROR</code> and <code>ype == ParserEvent.PARSE_ERROR</code>
199
- *
200
- * @param type
201
- * @param listener
202
- */
203
- public addEventListener(type: string, listener: (event: EventBase) => void): void {
204
- if (this._contentLoader && type == URLLoaderEvent.LOAD_ERROR || type == ParserEvent.PARSE_ERROR)
205
- this._contentLoader.addEventListener(type, this._errorDelegateSelector[type]);
206
-
207
- super.addEventListener(type, listener);
208
- }
209
-
210
- /**
211
- * Special removeEventListener case for <code>
212
- * URLLoaderEvent.LOAD_ERROR</code> and <code>ype == ParserEvent.PARSE_ERROR</code>
213
- *
214
- * @param type
215
- * @param listener
216
- */
217
-
218
- public removeEventListener(type: string, listener: (event: EventBase) => void): void {
219
- if (this._contentLoader && type == URLLoaderEvent.LOAD_ERROR || type == ParserEvent.PARSE_ERROR)
220
- this._contentLoader.removeEventListener(type, this._errorDelegateSelector[type]);
221
-
222
- super.removeEventListener(type, listener);
223
- }
224
-
225
- /**
226
- * Cancels a <code>load()</code> method operation that is currently in
227
- * progress for the Loader instance.
228
- *
229
- */
230
- public close(): void {
231
- if (!this._contentLoader)
232
- return;
233
-
234
- if (this._useAssetLib)
235
- AssetLibraryBundle.getInstance(this._assetLibId).stopLoader(this._contentLoader);
236
-
237
- this._disposeLoader();
238
- }
239
-
240
- /**
241
- * Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into an
242
- * object that is a child of this Loader object. If you load an animated GIF
243
- * file, only the first frame is displayed. As the Loader object can contain
244
- * only a single child, issuing a subsequent <code>load()</code> request
245
- * terminates the previous request, if still pending, and commences a new
246
- * load.
247
- *
248
- * <p><b>Note</b>: In AIR 1.5 and Flash Player 10, the maximum size for a
249
- * loaded image is 8,191 pixels in width or height, and the total number of
250
- * pixels cannot exceed 16,777,215 pixels.(So, if an loaded image is 8,191
251
- * pixels wide, it can only be 2,048 pixels high.) In Flash Player 9 and
252
- * earlier and AIR 1.1 and earlier, the limitation is 2,880 pixels in height
253
- * and 2,880 pixels in width.</p>
254
- *
255
- * <p>A SWF file or image loaded into a Loader object inherits the position,
256
- * rotation, and scale properties of the parent display objects of the Loader
257
- * object. </p>
258
- *
259
- * <p>Use the <code>unload()</code> method to remove movies or images loaded
260
- * with this method, or to cancel a load operation that is in progress.</p>
261
- *
262
- * <p>You can prevent a SWF file from using this method by setting the
263
- * <code>allowNetworking</code> parameter of the the <code>object</code> and
264
- * <code>embed</code> tags in the HTML page that contains the SWF
265
- * content.</p>
266
- *
267
- * <p>When you use this method, consider the Flash Player security model,
268
- * which is described in the Loader class description. </p>
269
- *
270
- * <p> In Flash Player 10 and later, if you use a multipart Content-Type(for
271
- * example "multipart/form-data") that contains an upload(indicated by a
272
- * "filename" parameter in a "content-disposition" header within the POST
273
- * body), the POST operation is subject to the security rules applied to
274
- * uploads:</p>
275
- *
276
- * <ul>
277
- * <li>The POST operation must be performed in response to a user-initiated
278
- * action, such as a mouse click or key press.</li>
279
- * <li>If the POST operation is cross-domain(the POST target is not on the
280
- * same server as the SWF file that is sending the POST request), the target
281
- * server must provide a URL policy file that permits cross-domain
282
- * access.</li>
283
- * </ul>
284
- *
285
- * <p>Also, for any multipart Content-Type, the syntax must be valid
286
- * (according to the RFC2046 standard). If the syntax appears to be invalid,
287
- * the POST operation is subject to the security rules applied to
288
- * uploads.</p>
289
- *
290
- * <p>For more information related to security, see the Flash Player
291
- * Developer Center Topic: <a
292
- * href="http://www.adobe.com/go/devnet_security_en"
293
- * scope="external">Security</a>.</p>
294
- *
295
- * @param request The absolute or relative URL of the SWF, JPEG, GIF, or PNG
296
- * file to be loaded. A relative path must be relative to the
297
- * main SWF file. Absolute URLs must include the protocol
298
- * reference, such as http:// or file:///. Filenames cannot
299
- * include disk drive specifications.
300
- * @param context A LoaderContext object, which has properties that define
301
- * the following:
302
- * <ul>
303
- * <li>Whether or not to check for the existence of a policy
304
- * file upon loading the object</li>
305
- * <li>The ApplicationDomain for the loaded object</li>
306
- * <li>The SecurityDomain for the loaded object</li>
307
- * <li>The ImageDecodingPolicy for the loaded image
308
- * object</li>
309
- * </ul>
310
- *
311
- * <p>If the <code>context</code> parameter is not specified
312
- * or refers to a null object, the loaded content remains in
313
- * its own security domain.</p>
314
- *
315
- * <p>For complete details, see the description of the
316
- * properties in the <a
317
- * href="../system/LoaderContext.html">LoaderContext</a>
318
- * class.</p>
319
- * @param ns An optional namespace string under which the file is to be
320
- * loaded, allowing the differentiation of two resources with
321
- * identical assets.
322
- * @param parser An optional parser object for translating the loaded data
323
- * into a usable resource. If not provided, Loader will
324
- * attempt to auto-detect the file type.
325
- * @throws IOError The <code>digest</code> property of the
326
- * <code>request</code> object is not
327
- * <code>null</code>. You should only set the
328
- * <code>digest</code> property of a URLRequest
329
- * object when calling the
330
- * <code>URLLoader.load()</code> method when
331
- * loading a SWZ file(an Adobe platform
332
- * component).
333
- * @throws IllegalOperationError If the <code>requestedContentParent</code>
334
- * property of the <code>context</code>
335
- * parameter is a <code>Loader</code>.
336
- * @throws IllegalOperationError If the <code>LoaderContext.parameters</code>
337
- * parameter is set to non-null and has some
338
- * values which are not Strings.
339
- * @throws SecurityError The value of
340
- * <code>LoaderContext.securityDomain</code>
341
- * must be either <code>null</code> or
342
- * <code>SecurityDomain.currentDomain</code>.
343
- * This reflects the fact that you can only
344
- * place the loaded media in its natural
345
- * security sandbox or your own(the latter
346
- * requires a policy file).
347
- * @throws SecurityError Local SWF files may not set
348
- * LoaderContext.securityDomain to anything
349
- * other than <code>null</code>. It is not
350
- * permitted to import non-local media into a
351
- * local sandbox, or to place other local media
352
- * in anything other than its natural sandbox.
353
- * @throws SecurityError You cannot connect to commonly reserved
354
- * ports. For a complete list of blocked ports,
355
- * see "Restricting Networking APIs" in the
356
- * <i>ActionScript 3.0 Developer's Guide</i>.
357
- * @throws SecurityError If the <code>applicationDomain</code> or
358
- * <code>securityDomain</code> properties of
359
- * the <code>context</code> parameter are from
360
- * a disallowed domain.
361
- * @throws SecurityError If a local SWF file is attempting to use the
362
- * <code>securityDomain</code> property of the
363
- * <code>context</code> parameter.
364
- * @event asyncError Dispatched by the <code>contentLoaderInfo</code>
365
- * object if the
366
- * <code>LoaderContext.requestedContentParent</code>
367
- * property has been specified and it is not possible to
368
- * add the loaded content as a child to the specified
369
- * DisplayObjectContainer. This could happen if the
370
- * loaded content is a
371
- * <code>flash.display.AVM1Movie</code> or if the
372
- * <code>addChild()</code> call to the
373
- * requestedContentParent throws an error.
374
- * @event complete Dispatched by the <code>contentLoaderInfo</code>
375
- * object when the file has completed loading. The
376
- * <code>complete</code> event is always dispatched
377
- * after the <code>init</code> event.
378
- * @event httpStatus Dispatched by the <code>contentLoaderInfo</code>
379
- * object when a network request is made over HTTP and
380
- * Flash Player can detect the HTTP status code.
381
- * @event init Dispatched by the <code>contentLoaderInfo</code>
382
- * object when the properties and methods of the loaded
383
- * SWF file are accessible. The <code>init</code> event
384
- * always precedes the <code>complete</code> event.
385
- * @event ioError Dispatched by the <code>contentLoaderInfo</code>
386
- * object when an input or output error occurs that
387
- * causes a load operation to fail.
388
- * @event open Dispatched by the <code>contentLoaderInfo</code>
389
- * object when the loading operation starts.
390
- * @event progress Dispatched by the <code>contentLoaderInfo</code>
391
- * object as data is received while load operation
392
- * progresses.
393
- * @event securityError Dispatched by the <code>contentLoaderInfo</code>
394
- * object if a SWF file in the local-with-filesystem
395
- * sandbox attempts to load content in the
396
- * local-with-networking sandbox, or vice versa.
397
- * @event securityError Dispatched by the <code>contentLoaderInfo</code>
398
- * object if the
399
- * <code>LoaderContext.requestedContentParent</code>
400
- * property has been specified and the security sandbox
401
- * of the
402
- * <code>LoaderContext.requestedContentParent</code>
403
- * does not have access to the loaded SWF.
404
- * @event unload Dispatched by the <code>contentLoaderInfo</code>
405
- * object when a loaded object is removed.
406
- */
407
- public load(request: URLRequest, context: LoaderContext = null,
408
- ns: string = null, parser: ParserBase = null): void {
409
- this._getLoader().load(request, context, ns, parser);
410
- }
411
-
412
- /**
413
- * Loads from binary data stored in a ByteArray object.
414
- *
415
- * <p>The <code>loadBytes()</code> method is asynchronous. You must wait for
416
- * the "init" event before accessing the properties of a loaded object.</p>
417
- *
418
- * <p>When you use this method, consider the Flash Player security model,
419
- * which is described in the Loader class description. </p>
420
- *
421
- * @param bytes A ByteArray object. The contents of the ByteArray can be
422
- * any of the file formats supported by the Loader class: SWF,
423
- * GIF, JPEG, or PNG.
424
- * @param context A LoaderContext object. Only the
425
- * <code>applicationDomain</code> property of the
426
- * LoaderContext object applies; the
427
- * <code>checkPolicyFile</code> and
428
- * <code>securityDomain</code> properties of the LoaderContext
429
- * object do not apply.
430
- *
431
- * <p>If the <code>context</code> parameter is not specified
432
- * or refers to a null object, the content is loaded into the
433
- * current security domain - a process referred to as "import
434
- * loading" in Flash Player security documentation.
435
- * Specifically, if the loading SWF file trusts the remote SWF
436
- * by incorporating the remote SWF into its code, then the
437
- * loading SWF can import it directly into its own security
438
- * domain.</p>
439
- *
440
- * <p>For more information related to security, see the Flash
441
- * Player Developer Center Topic: <a
442
- * href="http://www.adobe.com/go/devnet_security_en"
443
- * scope="external">Security</a>.</p>
444
- * @throws ArgumentError If the <code>length</code> property of the
445
- * ByteArray object is not greater than 0.
446
- * @throws IllegalOperationError If the <code>checkPolicyFile</code> or
447
- * <code>securityDomain</code> property of the
448
- * <code>context</code> parameter are non-null.
449
- * @throws IllegalOperationError If the <code>requestedContentParent</code>
450
- * property of the <code>context</code>
451
- * parameter is a <code>Loader</code>.
452
- * @throws IllegalOperationError If the <code>LoaderContext.parameters</code>
453
- * parameter is set to non-null and has some
454
- * values which are not Strings.
455
- * @throws SecurityError If the provided
456
- * <code>applicationDomain</code> property of
457
- * the <code>context</code> property is from a
458
- * disallowed domain.
459
- * @throws SecurityError You cannot connect to commonly reserved
460
- * ports. For a complete list of blocked ports,
461
- * see "Restricting Networking APIs" in the
462
- * <i>ActionScript 3.0 Developer's Guide</i>.
463
- * @event asyncError Dispatched by the <code>contentLoaderInfo</code>
464
- * object if the
465
- * <code>LoaderContext.requestedContentParent</code>
466
- * property has been specified and it is not possible to
467
- * add the loaded content as a child to the specified
468
- * DisplayObjectContainer. This could happen if the
469
- * loaded content is a
470
- * <code>flash.display.AVM1Movie</code> or if the
471
- * <code>addChild()</code> call to the
472
- * requestedContentParent throws an error.
473
- * @event complete Dispatched by the <code>contentLoaderInfo</code>
474
- * object when the operation is complete. The
475
- * <code>complete</code> event is always dispatched
476
- * after the <code>init</code> event.
477
- * @event init Dispatched by the <code>contentLoaderInfo</code>
478
- * object when the properties and methods of the loaded
479
- * data are accessible. The <code>init</code> event
480
- * always precedes the <code>complete</code> event.
481
- * @event ioError Dispatched by the <code>contentLoaderInfo</code>
482
- * object when the runtime cannot parse the data in the
483
- * byte array.
484
- * @event open Dispatched by the <code>contentLoaderInfo</code>
485
- * object when the operation starts.
486
- * @event progress Dispatched by the <code>contentLoaderInfo</code>
487
- * object as data is transfered in memory.
488
- * @event securityError Dispatched by the <code>contentLoaderInfo</code>
489
- * object if the
490
- * <code>LoaderContext.requestedContentParent</code>
491
- * property has been specified and the security sandbox
492
- * of the
493
- * <code>LoaderContext.requestedContentParent</code>
494
- * does not have access to the loaded SWF.
495
- * @event unload Dispatched by the <code>contentLoaderInfo</code>
496
- * object when a loaded object is removed.
497
- */
498
- public loadData(data: any, context: LoaderContext = null, ns: string = null, parser: ParserBase = null): void {
499
- this._getLoader().loadData(data, '', context, ns, parser);
500
- }
501
-
502
- private _getLoader(): Loader {
503
- if (this._contentLoader)
504
- this.close();
505
-
506
- this._contentLoader =
507
- (this._useAssetLib) ? AssetLibraryBundle.getInstance(this._assetLibId).getLoader() : new Loader();
508
-
509
- this._contentLoader.addEventListener(LoaderEvent.LOADER_START, this._onLoaderStartDelegate);
510
- this._contentLoader.addEventListener(URLLoaderEvent.LOAD_PROGRESS, this._onLoadProgressDelegate);
511
- this._contentLoader.addEventListener(URLLoaderEvent.LOAD_COMPLETE, this._onLoadCompleteDelegate);
512
- this._contentLoader.addEventListener(AssetEvent.ASSET_COMPLETE, this._onAssetCompleteDelegate);
513
- this._contentLoader.addEventListener(LoaderEvent.LOADER_COMPLETE, this._onLoaderCompleteDelegate);
514
-
515
- if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR))
516
- this._contentLoader.addEventListener(URLLoaderEvent.LOAD_ERROR, this._onLoadErrorDelegate);
517
-
518
- if (this.hasEventListener(ParserEvent.PARSE_ERROR))
519
- this._contentLoader.addEventListener(ParserEvent.PARSE_ERROR, this._onParseErrorDelegate);
520
-
521
- return this._contentLoader;
522
- }
523
-
524
- private _disposeLoader(): void {
525
- this._contentLoader.removeEventListener(LoaderEvent.LOADER_START, this._onLoaderStartDelegate);
526
- this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_PROGRESS, this._onLoadProgressDelegate);
527
- this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_COMPLETE, this._onLoadCompleteDelegate);
528
- this._contentLoader.removeEventListener(AssetEvent.ASSET_COMPLETE, this._onAssetCompleteDelegate);
529
- this._contentLoader.removeEventListener(LoaderEvent.LOADER_COMPLETE, this._onLoaderCompleteDelegate);
530
-
531
- if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR))
532
- this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_ERROR, this._onLoadErrorDelegate);
533
-
534
- if (this.hasEventListener(ParserEvent.PARSE_ERROR))
535
- this._contentLoader.removeEventListener(ParserEvent.PARSE_ERROR, this._onParseErrorDelegate);
536
-
537
- if (!this._useAssetLib)
538
- this._contentLoader.stop();
539
-
540
- this._contentLoader = null;
541
- }
542
-
543
- /**
544
- * Removes a child of this Loader object that was loaded by using the
545
- * <code>load()</code> method. The <code>property</code> of the associated
546
- * LoaderInfo object is reset to <code>null</code>. The child is not
547
- * necessarily destroyed because other objects might have references to it;
548
- * however, it is no longer a child of the Loader object.
549
- *
550
- * <p>As a best practice, before you unload a child SWF file, you should
551
- * explicitly close any streams in the child SWF file's objects, such as
552
- * LocalConnection, NetConnection, NetStream, and Sound objects. Otherwise,
553
- * audio in the child SWF file might continue to play, even though the child
554
- * SWF file was unloaded. To close streams in the child SWF file, add an
555
- * event listener to the child that listens for the <code>unload</code>
556
- * event. When the parent calls <code>Loader.unload()</code>, the
557
- * <code>unload</code> event is dispatched to the child. The following code
558
- * shows how you might do this:</p>
559
- * <pre xml:space="preserve"> public closeAllStreams(evt:Event) {
560
- * myNetStream.close(); mySound.close(); myNetConnection.close();
561
- * myLocalConnection.close(); }
562
- * myMovieClip.loaderInfo.addEventListener(Event.UNLOAD,
563
- * closeAllStreams);</pre>
564
- *
565
- */
566
- public unload(): void {
567
- //TODO
568
- }
569
-
570
- /**
571
- * Enables a specific parser.
572
- * When no specific parser is set for a loading/parsing opperation,
573
- * loader3d can autoselect the correct parser to use.
574
- * A parser must have been enabled, to be considered when autoselecting the parser.
575
- *
576
- * @param parserClass The parser class to enable.
577
- * @see away.parsers.Parsers
578
- */
579
- public static enableParser(parserClass: Object): void {
580
- Loader.enableParser(parserClass);
581
- }
582
-
583
- /**
584
- * Enables a list of parsers.
585
- * When no specific parser is set for a loading/parsing opperation,
586
- * loader3d can autoselect the correct parser to use.
587
- * A parser must have been enabled, to be considered when autoselecting the parser.
588
- *
589
- * @param parserClasses A Vector of parser classes to enable.
590
- * @see away.parsers.Parsers
591
- */
592
- public static enableParsers(parserClasses: Array<Object>): void {
593
- Loader.enableParsers(parserClasses);
594
- }
595
-
596
- /**
597
- * .
598
- */
599
- private _onLoaderStart(event: LoaderEvent): void {
600
- this.dispatchEvent(event);
601
- }
602
-
603
- private _onLoadProgress(event: URLLoaderEvent): void {
604
- this.dispatchEvent(event);
605
- }
606
-
607
- private _onLoadComplete(event: URLLoaderEvent): void {
608
- this.dispatchEvent(event);
609
- }
610
-
611
- private _onAssetComplete(event: AssetEvent): void {
612
- this.dispatchEvent(event);
613
- }
614
-
615
- /**
616
- * Called when an error occurs during loading
617
- */
618
- private _onLoadError(event: URLLoaderEvent): boolean {
619
- if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR)) {
620
- this.dispatchEvent(event);
621
- return true;
622
- } else {
623
- return false;
624
- }
625
- }
626
-
627
- /**
628
- * Called when a an error occurs during parsing
629
- */
630
- private _onParseError(event: ParserEvent): boolean {
631
- if (this.hasEventListener(ParserEvent.PARSE_ERROR)) {
632
- this.dispatchEvent(event);
633
- return true;
634
- } else {
635
- return false;
636
- }
637
- }
638
-
639
- /**
640
- * Called when the resource and all of its dependencies was retrieved.
641
- */
642
- private _onLoaderComplete(event: LoaderEvent): void {
643
- this._content = <DisplayObject> event.content;
644
-
645
- if (this._content)
646
- this.addChild(this._content);
647
-
648
- this.dispatchEvent(event);
649
-
650
- this._disposeLoader();
651
- }
1
+ import { AssetLibraryBundle, Loader, LoaderContext, URLRequest, AssetEvent,
2
+ URLLoaderEvent, LoaderEvent, ParserEvent, ParserBase, EventBase } from '@awayjs/core';
3
+
4
+ import { DisplayObjectContainer } from './DisplayObjectContainer';
5
+ import { DisplayObject } from './DisplayObject';
6
+
7
+ /**
8
+ * The LoaderContainer class is used to load SWF files or image(JPG, PNG, or GIF)
9
+ * files. Use the <code>load()</code> method to initiate loading. The loaded
10
+ * display object is added as a child of the LoaderContainer object.
11
+ *
12
+ * <p>Use the URLLoader class to load text or binary data.</p>
13
+ *
14
+ * <p>The LoaderContainer class overrides the following methods that it inherits,
15
+ * because a LoaderContainer object can only have one child display object - the
16
+ * display object that it loads. Calling the following methods throws an
17
+ * exception: <code>addChild()</code>, <code>addChildAt()</code>,
18
+ * <code>removeChild()</code>, <code>removeChildAt()</code>, and
19
+ * <code>setChildIndex()</code>. To remove a loaded display object, you must
20
+ * remove the <i>LoaderContainer</i> object from its parent DisplayObjectContainer
21
+ * child array. </p>
22
+ *
23
+ * <p><b>Note:</b> The ActionScript 2.0 MovieClipLoader and LoadVars classes
24
+ * are not used in ActionScript 3.0. The LoaderContainer and URLLoader classes replace
25
+ * them.</p>
26
+ *
27
+ * <p>When you use the LoaderContainer class, consider the Flash Player and Adobe AIR
28
+ * security model: </p>
29
+ *
30
+ * <ul>
31
+ * <li>You can load content from any accessible source. </li>
32
+ * <li>Loading is not allowed if the calling SWF file is in a network
33
+ * sandbox and the file to be loaded is local. </li>
34
+ * <li>If the loaded content is a SWF file written with ActionScript 3.0, it
35
+ * cannot be cross-scripted by a SWF file in another security sandbox unless
36
+ * that cross-scripting arrangement was approved through a call to the
37
+ * <code>System.allowDomain()</code> or the
38
+ * <code>System.allowInsecureDomain()</code> method in the loaded content
39
+ * file.</li>
40
+ * <li>If the loaded content is an AVM1 SWF file(written using ActionScript
41
+ * 1.0 or 2.0), it cannot be cross-scripted by an AVM2 SWF file(written using
42
+ * ActionScript 3.0). However, you can communicate between the two SWF files
43
+ * by using the LocalConnection class.</li>
44
+ * <li>If the loaded content is an image, its data cannot be accessed by a
45
+ * SWF file outside of the security sandbox, unless the domain of that SWF
46
+ * file was included in a URL policy file at the origin domain of the
47
+ * image.</li>
48
+ * <li>Movie clips in the local-with-file-system sandbox cannot script movie
49
+ * clips in the local-with-networking sandbox, and the reverse is also
50
+ * prevented. </li>
51
+ * <li>You cannot connect to commonly reserved ports. For a complete list of
52
+ * blocked ports, see "Restricting Networking APIs" in the <i>ActionScript 3.0
53
+ * Developer's Guide</i>. </li>
54
+ * </ul>
55
+ *
56
+ * <p>However, in AIR, content in the <code>application</code> security
57
+ * sandbox(content installed with the AIR application) are not restricted by
58
+ * these security limitations.</p>
59
+ *
60
+ * <p>For more information related to security, see the Flash Player Developer
61
+ * Center Topic: <a href="http://www.adobe.com/go/devnet_security_en"
62
+ * scope="external">Security</a>.</p>
63
+ *
64
+ * <p>When loading a SWF file from an untrusted source(such as a domain other
65
+ * than that of the LoaderContainer object's root SWF file), you may want to define a
66
+ * mask for the LoaderContainer object, to prevent the loaded content(which is a child
67
+ * of the LoaderContainer object) from drawing to portions of the Stage outside of that
68
+ * mask, as shown in the following code:</p>
69
+ */
70
+ export class LoaderContainer extends DisplayObjectContainer {
71
+ /**
72
+ * Dispatched when any asset finishes parsing. Also see specific events for each
73
+ * individual asset type (sprites, materials et c.)
74
+ *
75
+ * @eventType AssetEvent
76
+ */
77
+ //[Event(name="assetComplete", type="AssetEvent")]
78
+
79
+ /**
80
+ * Dispatched when a full resource (including dependencies) finishes loading.
81
+ *
82
+ * @eventType LoaderEvent
83
+ */
84
+ //[Event(name="resourceComplete", type="LoaderEvent")]
85
+
86
+ private _contentLoader: Loader;
87
+ private _useAssetLib: boolean;
88
+ private _assetLibId: string;
89
+ private _onLoaderStartDelegate: (event: LoaderEvent) => void;
90
+ private _onLoadProgressDelegate: (event: URLLoaderEvent) => void;
91
+ private _onLoadCompleteDelegate: (event: URLLoaderEvent) => void;
92
+ private _onAssetCompleteDelegate: (event: AssetEvent) => void;
93
+ private _onLoaderCompleteDelegate: (event: LoaderEvent) => void;
94
+ private _onLoadErrorDelegate: (event: URLLoaderEvent) => void;
95
+ private _onParseErrorDelegate: (event: ParserEvent) => void;
96
+ private _errorDelegateSelector: {[index: string]: ((event: EventBase) => void)};
97
+
98
+ private _content: DisplayObject;
99
+
100
+ /**
101
+ * Contains the root display object of the SWF file or image(JPG, PNG, or
102
+ * GIF) file that was loaded by using the <code>load()</code> or
103
+ * <code>loadBytes()</code> methods.
104
+ *
105
+ * @throws SecurityError The loaded SWF file or image file belongs to a
106
+ * security sandbox to which you do not have access.
107
+ * For a loaded SWF file, you can avoid this situation
108
+ * by having the file call the
109
+ * <code>Security.allowDomain()</code> method or by
110
+ * having the loading file specify a
111
+ * <code>loaderContext</code> parameter with its
112
+ * <code>securityDomain</code> property set to
113
+ * <code>SecurityDomain.currentDomain</code> when you
114
+ * call the <code>load()</code> or
115
+ * <code>loadBytes()</code> method.
116
+ */
117
+ public get content(): DisplayObject {
118
+ return this._content;
119
+ }
120
+
121
+ /**
122
+ *
123
+ */
124
+ public get contentLoader(): Loader {
125
+ return this._contentLoader;
126
+ }
127
+
128
+ /**
129
+ * Creates a Loader object that you can use to load files, such as SWF, JPEG,
130
+ * GIF, or PNG files. Call the <code>load()</code> method to load the asset
131
+ * as a child of the Loader instance. You can then add the Loader object to
132
+ * the display list(for instance, by using the <code>addChild()</code>
133
+ * method of a DisplayObjectContainer instance). The asset appears on the
134
+ * Stage as it loads.
135
+ *
136
+ * <p>You can also use a Loader instance "offlist," that is without adding it
137
+ * to a display object container on the display list. In this mode, the
138
+ * Loader instance might be used to load a SWF file that contains additional
139
+ * modules of an application. </p>
140
+ *
141
+ * <p>To detect when the SWF file is finished loading, you can use the events
142
+ * of the LoaderInfo object associated with the
143
+ * <code>contentLoaderInfo</code> property of the Loader object. At that
144
+ * point, the code in the module SWF file can be executed to initialize and
145
+ * start the module. In the offlist mode, a Loader instance might also be
146
+ * used to load a SWF file that contains components or media assets. Again,
147
+ * you can use the LoaderInfo object event notifications to detect when the
148
+ * components are finished loading. At that point, the application can start
149
+ * using the components and media assets in the library of the SWF file by
150
+ * instantiating the ActionScript 3.0 classes that represent those components
151
+ * and assets.</p>
152
+ *
153
+ * <p>To determine the status of a Loader object, monitor the following
154
+ * events that the LoaderInfo object associated with the
155
+ * <code>contentLoaderInfo</code> property of the Loader object:</p>
156
+ *
157
+ * <ul>
158
+ * <li>The <code>open</code> event is dispatched when loading begins.</li>
159
+ * <li>The <code>ioError</code> or <code>securityError</code> event is
160
+ * dispatched if the file cannot be loaded or if an error occured during the
161
+ * load process. </li>
162
+ * <li>The <code>progress</code> event fires continuously while the file is
163
+ * being loaded.</li>
164
+ * <li>The <code>complete</code> event is dispatched when a file completes
165
+ * downloading, but before the loaded movie clip's methods and properties are
166
+ * available. </li>
167
+ * <li>The <code>init</code> event is dispatched after the properties and
168
+ * methods of the loaded SWF file are accessible, so you can begin
169
+ * manipulating the loaded SWF file. This event is dispatched before the
170
+ * <code>complete</code> handler. In streaming SWF files, the
171
+ * <code>init</code> event can occur significantly earlier than the
172
+ * <code>complete</code> event. For most purposes, use the <code>init</code>
173
+ * handler.</li>
174
+ * </ul>
175
+ */
176
+ constructor(useAssetLibrary: boolean = true, assetLibraryId: string = null) {
177
+ super();
178
+
179
+ this._useAssetLib = useAssetLibrary;
180
+ this._assetLibId = assetLibraryId;
181
+
182
+ this._onLoaderStartDelegate = (event: LoaderEvent) => this._onLoaderStart(event);
183
+ this._onLoadProgressDelegate = (event: URLLoaderEvent) => this._onLoadProgress(event);
184
+ this._onLoadCompleteDelegate = (event: URLLoaderEvent) => this._onLoadComplete(event);
185
+ this._onAssetCompleteDelegate = (event: AssetEvent) => this._onAssetComplete(event);
186
+ this._onLoaderCompleteDelegate = (event: LoaderEvent) => this._onLoaderComplete(event);
187
+ this._onLoadErrorDelegate = (event: URLLoaderEvent) => this._onLoadError(event);
188
+ this._onParseErrorDelegate = (event: ParserEvent) => this._onParseError(event);
189
+
190
+ this._errorDelegateSelector = {
191
+ [URLLoaderEvent.LOAD_ERROR]: this._onLoadErrorDelegate,
192
+ [ParserEvent.PARSE_ERROR]: this._onParseErrorDelegate
193
+ };
194
+ }
195
+
196
+ /**
197
+ * Special addEventListener case for <code>
198
+ * URLLoaderEvent.LOAD_ERROR</code> and <code>ype == ParserEvent.PARSE_ERROR</code>
199
+ *
200
+ * @param type
201
+ * @param listener
202
+ */
203
+ public addEventListener(type: string, listener: (event: EventBase) => void): void {
204
+ if (this._contentLoader && type == URLLoaderEvent.LOAD_ERROR || type == ParserEvent.PARSE_ERROR)
205
+ this._contentLoader.addEventListener(type, this._errorDelegateSelector[type]);
206
+
207
+ super.addEventListener(type, listener);
208
+ }
209
+
210
+ /**
211
+ * Special removeEventListener case for <code>
212
+ * URLLoaderEvent.LOAD_ERROR</code> and <code>ype == ParserEvent.PARSE_ERROR</code>
213
+ *
214
+ * @param type
215
+ * @param listener
216
+ */
217
+
218
+ public removeEventListener(type: string, listener: (event: EventBase) => void): void {
219
+ if (this._contentLoader && type == URLLoaderEvent.LOAD_ERROR || type == ParserEvent.PARSE_ERROR)
220
+ this._contentLoader.removeEventListener(type, this._errorDelegateSelector[type]);
221
+
222
+ super.removeEventListener(type, listener);
223
+ }
224
+
225
+ /**
226
+ * Cancels a <code>load()</code> method operation that is currently in
227
+ * progress for the Loader instance.
228
+ *
229
+ */
230
+ public close(): void {
231
+ if (!this._contentLoader)
232
+ return;
233
+
234
+ if (this._useAssetLib)
235
+ AssetLibraryBundle.getInstance(this._assetLibId).stopLoader(this._contentLoader);
236
+
237
+ this._disposeLoader();
238
+ }
239
+
240
+ /**
241
+ * Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into an
242
+ * object that is a child of this Loader object. If you load an animated GIF
243
+ * file, only the first frame is displayed. As the Loader object can contain
244
+ * only a single child, issuing a subsequent <code>load()</code> request
245
+ * terminates the previous request, if still pending, and commences a new
246
+ * load.
247
+ *
248
+ * <p><b>Note</b>: In AIR 1.5 and Flash Player 10, the maximum size for a
249
+ * loaded image is 8,191 pixels in width or height, and the total number of
250
+ * pixels cannot exceed 16,777,215 pixels.(So, if an loaded image is 8,191
251
+ * pixels wide, it can only be 2,048 pixels high.) In Flash Player 9 and
252
+ * earlier and AIR 1.1 and earlier, the limitation is 2,880 pixels in height
253
+ * and 2,880 pixels in width.</p>
254
+ *
255
+ * <p>A SWF file or image loaded into a Loader object inherits the position,
256
+ * rotation, and scale properties of the parent display objects of the Loader
257
+ * object. </p>
258
+ *
259
+ * <p>Use the <code>unload()</code> method to remove movies or images loaded
260
+ * with this method, or to cancel a load operation that is in progress.</p>
261
+ *
262
+ * <p>You can prevent a SWF file from using this method by setting the
263
+ * <code>allowNetworking</code> parameter of the the <code>object</code> and
264
+ * <code>embed</code> tags in the HTML page that contains the SWF
265
+ * content.</p>
266
+ *
267
+ * <p>When you use this method, consider the Flash Player security model,
268
+ * which is described in the Loader class description. </p>
269
+ *
270
+ * <p> In Flash Player 10 and later, if you use a multipart Content-Type(for
271
+ * example "multipart/form-data") that contains an upload(indicated by a
272
+ * "filename" parameter in a "content-disposition" header within the POST
273
+ * body), the POST operation is subject to the security rules applied to
274
+ * uploads:</p>
275
+ *
276
+ * <ul>
277
+ * <li>The POST operation must be performed in response to a user-initiated
278
+ * action, such as a mouse click or key press.</li>
279
+ * <li>If the POST operation is cross-domain(the POST target is not on the
280
+ * same server as the SWF file that is sending the POST request), the target
281
+ * server must provide a URL policy file that permits cross-domain
282
+ * access.</li>
283
+ * </ul>
284
+ *
285
+ * <p>Also, for any multipart Content-Type, the syntax must be valid
286
+ * (according to the RFC2046 standard). If the syntax appears to be invalid,
287
+ * the POST operation is subject to the security rules applied to
288
+ * uploads.</p>
289
+ *
290
+ * <p>For more information related to security, see the Flash Player
291
+ * Developer Center Topic: <a
292
+ * href="http://www.adobe.com/go/devnet_security_en"
293
+ * scope="external">Security</a>.</p>
294
+ *
295
+ * @param request The absolute or relative URL of the SWF, JPEG, GIF, or PNG
296
+ * file to be loaded. A relative path must be relative to the
297
+ * main SWF file. Absolute URLs must include the protocol
298
+ * reference, such as http:// or file:///. Filenames cannot
299
+ * include disk drive specifications.
300
+ * @param context A LoaderContext object, which has properties that define
301
+ * the following:
302
+ * <ul>
303
+ * <li>Whether or not to check for the existence of a policy
304
+ * file upon loading the object</li>
305
+ * <li>The ApplicationDomain for the loaded object</li>
306
+ * <li>The SecurityDomain for the loaded object</li>
307
+ * <li>The ImageDecodingPolicy for the loaded image
308
+ * object</li>
309
+ * </ul>
310
+ *
311
+ * <p>If the <code>context</code> parameter is not specified
312
+ * or refers to a null object, the loaded content remains in
313
+ * its own security domain.</p>
314
+ *
315
+ * <p>For complete details, see the description of the
316
+ * properties in the <a
317
+ * href="../system/LoaderContext.html">LoaderContext</a>
318
+ * class.</p>
319
+ * @param ns An optional namespace string under which the file is to be
320
+ * loaded, allowing the differentiation of two resources with
321
+ * identical assets.
322
+ * @param parser An optional parser object for translating the loaded data
323
+ * into a usable resource. If not provided, Loader will
324
+ * attempt to auto-detect the file type.
325
+ * @throws IOError The <code>digest</code> property of the
326
+ * <code>request</code> object is not
327
+ * <code>null</code>. You should only set the
328
+ * <code>digest</code> property of a URLRequest
329
+ * object when calling the
330
+ * <code>URLLoader.load()</code> method when
331
+ * loading a SWZ file(an Adobe platform
332
+ * component).
333
+ * @throws IllegalOperationError If the <code>requestedContentParent</code>
334
+ * property of the <code>context</code>
335
+ * parameter is a <code>Loader</code>.
336
+ * @throws IllegalOperationError If the <code>LoaderContext.parameters</code>
337
+ * parameter is set to non-null and has some
338
+ * values which are not Strings.
339
+ * @throws SecurityError The value of
340
+ * <code>LoaderContext.securityDomain</code>
341
+ * must be either <code>null</code> or
342
+ * <code>SecurityDomain.currentDomain</code>.
343
+ * This reflects the fact that you can only
344
+ * place the loaded media in its natural
345
+ * security sandbox or your own(the latter
346
+ * requires a policy file).
347
+ * @throws SecurityError Local SWF files may not set
348
+ * LoaderContext.securityDomain to anything
349
+ * other than <code>null</code>. It is not
350
+ * permitted to import non-local media into a
351
+ * local sandbox, or to place other local media
352
+ * in anything other than its natural sandbox.
353
+ * @throws SecurityError You cannot connect to commonly reserved
354
+ * ports. For a complete list of blocked ports,
355
+ * see "Restricting Networking APIs" in the
356
+ * <i>ActionScript 3.0 Developer's Guide</i>.
357
+ * @throws SecurityError If the <code>applicationDomain</code> or
358
+ * <code>securityDomain</code> properties of
359
+ * the <code>context</code> parameter are from
360
+ * a disallowed domain.
361
+ * @throws SecurityError If a local SWF file is attempting to use the
362
+ * <code>securityDomain</code> property of the
363
+ * <code>context</code> parameter.
364
+ * @event asyncError Dispatched by the <code>contentLoaderInfo</code>
365
+ * object if the
366
+ * <code>LoaderContext.requestedContentParent</code>
367
+ * property has been specified and it is not possible to
368
+ * add the loaded content as a child to the specified
369
+ * DisplayObjectContainer. This could happen if the
370
+ * loaded content is a
371
+ * <code>flash.display.AVM1Movie</code> or if the
372
+ * <code>addChild()</code> call to the
373
+ * requestedContentParent throws an error.
374
+ * @event complete Dispatched by the <code>contentLoaderInfo</code>
375
+ * object when the file has completed loading. The
376
+ * <code>complete</code> event is always dispatched
377
+ * after the <code>init</code> event.
378
+ * @event httpStatus Dispatched by the <code>contentLoaderInfo</code>
379
+ * object when a network request is made over HTTP and
380
+ * Flash Player can detect the HTTP status code.
381
+ * @event init Dispatched by the <code>contentLoaderInfo</code>
382
+ * object when the properties and methods of the loaded
383
+ * SWF file are accessible. The <code>init</code> event
384
+ * always precedes the <code>complete</code> event.
385
+ * @event ioError Dispatched by the <code>contentLoaderInfo</code>
386
+ * object when an input or output error occurs that
387
+ * causes a load operation to fail.
388
+ * @event open Dispatched by the <code>contentLoaderInfo</code>
389
+ * object when the loading operation starts.
390
+ * @event progress Dispatched by the <code>contentLoaderInfo</code>
391
+ * object as data is received while load operation
392
+ * progresses.
393
+ * @event securityError Dispatched by the <code>contentLoaderInfo</code>
394
+ * object if a SWF file in the local-with-filesystem
395
+ * sandbox attempts to load content in the
396
+ * local-with-networking sandbox, or vice versa.
397
+ * @event securityError Dispatched by the <code>contentLoaderInfo</code>
398
+ * object if the
399
+ * <code>LoaderContext.requestedContentParent</code>
400
+ * property has been specified and the security sandbox
401
+ * of the
402
+ * <code>LoaderContext.requestedContentParent</code>
403
+ * does not have access to the loaded SWF.
404
+ * @event unload Dispatched by the <code>contentLoaderInfo</code>
405
+ * object when a loaded object is removed.
406
+ */
407
+ public load(request: URLRequest, context: LoaderContext = null,
408
+ ns: string = null, parser: ParserBase = null): void {
409
+ this._getLoader().load(request, context, ns, parser);
410
+ }
411
+
412
+ /**
413
+ * Loads from binary data stored in a ByteArray object.
414
+ *
415
+ * <p>The <code>loadBytes()</code> method is asynchronous. You must wait for
416
+ * the "init" event before accessing the properties of a loaded object.</p>
417
+ *
418
+ * <p>When you use this method, consider the Flash Player security model,
419
+ * which is described in the Loader class description. </p>
420
+ *
421
+ * @param bytes A ByteArray object. The contents of the ByteArray can be
422
+ * any of the file formats supported by the Loader class: SWF,
423
+ * GIF, JPEG, or PNG.
424
+ * @param context A LoaderContext object. Only the
425
+ * <code>applicationDomain</code> property of the
426
+ * LoaderContext object applies; the
427
+ * <code>checkPolicyFile</code> and
428
+ * <code>securityDomain</code> properties of the LoaderContext
429
+ * object do not apply.
430
+ *
431
+ * <p>If the <code>context</code> parameter is not specified
432
+ * or refers to a null object, the content is loaded into the
433
+ * current security domain - a process referred to as "import
434
+ * loading" in Flash Player security documentation.
435
+ * Specifically, if the loading SWF file trusts the remote SWF
436
+ * by incorporating the remote SWF into its code, then the
437
+ * loading SWF can import it directly into its own security
438
+ * domain.</p>
439
+ *
440
+ * <p>For more information related to security, see the Flash
441
+ * Player Developer Center Topic: <a
442
+ * href="http://www.adobe.com/go/devnet_security_en"
443
+ * scope="external">Security</a>.</p>
444
+ * @throws ArgumentError If the <code>length</code> property of the
445
+ * ByteArray object is not greater than 0.
446
+ * @throws IllegalOperationError If the <code>checkPolicyFile</code> or
447
+ * <code>securityDomain</code> property of the
448
+ * <code>context</code> parameter are non-null.
449
+ * @throws IllegalOperationError If the <code>requestedContentParent</code>
450
+ * property of the <code>context</code>
451
+ * parameter is a <code>Loader</code>.
452
+ * @throws IllegalOperationError If the <code>LoaderContext.parameters</code>
453
+ * parameter is set to non-null and has some
454
+ * values which are not Strings.
455
+ * @throws SecurityError If the provided
456
+ * <code>applicationDomain</code> property of
457
+ * the <code>context</code> property is from a
458
+ * disallowed domain.
459
+ * @throws SecurityError You cannot connect to commonly reserved
460
+ * ports. For a complete list of blocked ports,
461
+ * see "Restricting Networking APIs" in the
462
+ * <i>ActionScript 3.0 Developer's Guide</i>.
463
+ * @event asyncError Dispatched by the <code>contentLoaderInfo</code>
464
+ * object if the
465
+ * <code>LoaderContext.requestedContentParent</code>
466
+ * property has been specified and it is not possible to
467
+ * add the loaded content as a child to the specified
468
+ * DisplayObjectContainer. This could happen if the
469
+ * loaded content is a
470
+ * <code>flash.display.AVM1Movie</code> or if the
471
+ * <code>addChild()</code> call to the
472
+ * requestedContentParent throws an error.
473
+ * @event complete Dispatched by the <code>contentLoaderInfo</code>
474
+ * object when the operation is complete. The
475
+ * <code>complete</code> event is always dispatched
476
+ * after the <code>init</code> event.
477
+ * @event init Dispatched by the <code>contentLoaderInfo</code>
478
+ * object when the properties and methods of the loaded
479
+ * data are accessible. The <code>init</code> event
480
+ * always precedes the <code>complete</code> event.
481
+ * @event ioError Dispatched by the <code>contentLoaderInfo</code>
482
+ * object when the runtime cannot parse the data in the
483
+ * byte array.
484
+ * @event open Dispatched by the <code>contentLoaderInfo</code>
485
+ * object when the operation starts.
486
+ * @event progress Dispatched by the <code>contentLoaderInfo</code>
487
+ * object as data is transfered in memory.
488
+ * @event securityError Dispatched by the <code>contentLoaderInfo</code>
489
+ * object if the
490
+ * <code>LoaderContext.requestedContentParent</code>
491
+ * property has been specified and the security sandbox
492
+ * of the
493
+ * <code>LoaderContext.requestedContentParent</code>
494
+ * does not have access to the loaded SWF.
495
+ * @event unload Dispatched by the <code>contentLoaderInfo</code>
496
+ * object when a loaded object is removed.
497
+ */
498
+ public loadData(data: any, context: LoaderContext = null, ns: string = null, parser: ParserBase = null): void {
499
+ this._getLoader().loadData(data, '', context, ns, parser);
500
+ }
501
+
502
+ private _getLoader(): Loader {
503
+ if (this._contentLoader)
504
+ this.close();
505
+
506
+ this._contentLoader =
507
+ (this._useAssetLib) ? AssetLibraryBundle.getInstance(this._assetLibId).getLoader() : new Loader();
508
+
509
+ this._contentLoader.addEventListener(LoaderEvent.LOADER_START, this._onLoaderStartDelegate);
510
+ this._contentLoader.addEventListener(URLLoaderEvent.LOAD_PROGRESS, this._onLoadProgressDelegate);
511
+ this._contentLoader.addEventListener(URLLoaderEvent.LOAD_COMPLETE, this._onLoadCompleteDelegate);
512
+ this._contentLoader.addEventListener(AssetEvent.ASSET_COMPLETE, this._onAssetCompleteDelegate);
513
+ this._contentLoader.addEventListener(LoaderEvent.LOADER_COMPLETE, this._onLoaderCompleteDelegate);
514
+
515
+ if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR))
516
+ this._contentLoader.addEventListener(URLLoaderEvent.LOAD_ERROR, this._onLoadErrorDelegate);
517
+
518
+ if (this.hasEventListener(ParserEvent.PARSE_ERROR))
519
+ this._contentLoader.addEventListener(ParserEvent.PARSE_ERROR, this._onParseErrorDelegate);
520
+
521
+ return this._contentLoader;
522
+ }
523
+
524
+ private _disposeLoader(): void {
525
+ this._contentLoader.removeEventListener(LoaderEvent.LOADER_START, this._onLoaderStartDelegate);
526
+ this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_PROGRESS, this._onLoadProgressDelegate);
527
+ this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_COMPLETE, this._onLoadCompleteDelegate);
528
+ this._contentLoader.removeEventListener(AssetEvent.ASSET_COMPLETE, this._onAssetCompleteDelegate);
529
+ this._contentLoader.removeEventListener(LoaderEvent.LOADER_COMPLETE, this._onLoaderCompleteDelegate);
530
+
531
+ if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR))
532
+ this._contentLoader.removeEventListener(URLLoaderEvent.LOAD_ERROR, this._onLoadErrorDelegate);
533
+
534
+ if (this.hasEventListener(ParserEvent.PARSE_ERROR))
535
+ this._contentLoader.removeEventListener(ParserEvent.PARSE_ERROR, this._onParseErrorDelegate);
536
+
537
+ if (!this._useAssetLib)
538
+ this._contentLoader.stop();
539
+
540
+ this._contentLoader = null;
541
+ }
542
+
543
+ /**
544
+ * Removes a child of this Loader object that was loaded by using the
545
+ * <code>load()</code> method. The <code>property</code> of the associated
546
+ * LoaderInfo object is reset to <code>null</code>. The child is not
547
+ * necessarily destroyed because other objects might have references to it;
548
+ * however, it is no longer a child of the Loader object.
549
+ *
550
+ * <p>As a best practice, before you unload a child SWF file, you should
551
+ * explicitly close any streams in the child SWF file's objects, such as
552
+ * LocalConnection, NetConnection, NetStream, and Sound objects. Otherwise,
553
+ * audio in the child SWF file might continue to play, even though the child
554
+ * SWF file was unloaded. To close streams in the child SWF file, add an
555
+ * event listener to the child that listens for the <code>unload</code>
556
+ * event. When the parent calls <code>Loader.unload()</code>, the
557
+ * <code>unload</code> event is dispatched to the child. The following code
558
+ * shows how you might do this:</p>
559
+ * <pre xml:space="preserve"> public closeAllStreams(evt:Event) {
560
+ * myNetStream.close(); mySound.close(); myNetConnection.close();
561
+ * myLocalConnection.close(); }
562
+ * myMovieClip.loaderInfo.addEventListener(Event.UNLOAD,
563
+ * closeAllStreams);</pre>
564
+ *
565
+ */
566
+ public unload(): void {
567
+ //TODO
568
+ }
569
+
570
+ /**
571
+ * Enables a specific parser.
572
+ * When no specific parser is set for a loading/parsing opperation,
573
+ * loader3d can autoselect the correct parser to use.
574
+ * A parser must have been enabled, to be considered when autoselecting the parser.
575
+ *
576
+ * @param parserClass The parser class to enable.
577
+ * @see away.parsers.Parsers
578
+ */
579
+ public static enableParser(parserClass: Object): void {
580
+ Loader.enableParser(parserClass);
581
+ }
582
+
583
+ /**
584
+ * Enables a list of parsers.
585
+ * When no specific parser is set for a loading/parsing opperation,
586
+ * loader3d can autoselect the correct parser to use.
587
+ * A parser must have been enabled, to be considered when autoselecting the parser.
588
+ *
589
+ * @param parserClasses A Vector of parser classes to enable.
590
+ * @see away.parsers.Parsers
591
+ */
592
+ public static enableParsers(parserClasses: Array<Object>): void {
593
+ Loader.enableParsers(parserClasses);
594
+ }
595
+
596
+ /**
597
+ * .
598
+ */
599
+ private _onLoaderStart(event: LoaderEvent): void {
600
+ this.dispatchEvent(event);
601
+ }
602
+
603
+ private _onLoadProgress(event: URLLoaderEvent): void {
604
+ this.dispatchEvent(event);
605
+ }
606
+
607
+ private _onLoadComplete(event: URLLoaderEvent): void {
608
+ this.dispatchEvent(event);
609
+ }
610
+
611
+ private _onAssetComplete(event: AssetEvent): void {
612
+ this.dispatchEvent(event);
613
+ }
614
+
615
+ /**
616
+ * Called when an error occurs during loading
617
+ */
618
+ private _onLoadError(event: URLLoaderEvent): boolean {
619
+ if (this.hasEventListener(URLLoaderEvent.LOAD_ERROR)) {
620
+ this.dispatchEvent(event);
621
+ return true;
622
+ } else {
623
+ return false;
624
+ }
625
+ }
626
+
627
+ /**
628
+ * Called when a an error occurs during parsing
629
+ */
630
+ private _onParseError(event: ParserEvent): boolean {
631
+ if (this.hasEventListener(ParserEvent.PARSE_ERROR)) {
632
+ this.dispatchEvent(event);
633
+ return true;
634
+ } else {
635
+ return false;
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Called when the resource and all of its dependencies was retrieved.
641
+ */
642
+ private _onLoaderComplete(event: LoaderEvent): void {
643
+ this._content = <DisplayObject> event.content;
644
+
645
+ if (this._content)
646
+ this.addChild(this._content);
647
+
648
+ this.dispatchEvent(event);
649
+
650
+ this._disposeLoader();
651
+ }
652
652
  }