PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/jangaroo/lsystem/joo/classes/flash/display/DisplayObjectContainer.js

https://github.com/mohlendo/mohlendo.github.com
JavaScript | 800 lines | 169 code | 28 blank | 603 comment | 25 complexity | bb7bd836e8e2947f849eab4a3ebf2a27 MD5 | raw file
  1. joo.classLoader.prepare("package flash.display",/* {
  2. import flash.events.Event;
  3. import flash.geom.Point;
  4. import flash.text.TextSnapshot;
  5. import js.Element;
  6. import js.HTMLElement;*/
  7. /**
  8. * The DisplayObjectContainer class is the base class for all objects that can serve as display object containers on the display list. The display list manages all objects displayed in the Flash runtimes. Use the DisplayObjectContainer class to arrange the display objects in the display list. Each DisplayObjectContainer object has its own child list for organizing the z-order of the objects. The z-order is the front-to-back order that determines which object is drawn in front, which is behind, and so on.
  9. * <p>DisplayObject is an abstract base class; therefore, you cannot call DisplayObject directly. Invoking <code>new DisplayObject()</code> throws an <code>ArgumentError</code> exception.</p>The DisplayObjectContainer class is an abstract base class for all objects that can contain child objects. It cannot be instantiated directly; calling the <code>new DisplayObjectContainer()</code> constructor throws an <code>ArgumentError</code> exception.
  10. * <p>For more information, see the "Display Programming" chapter of the <i>ActionScript 3.0 Developer's Guide</i>.</p>
  11. * <p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#includeExamplesSummary">View the examples</a></p>
  12. * @see DisplayObject
  13. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3c.html Core display classes
  14. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3d.html Working with display objects
  15. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e36.html Working with display object containers
  16. *
  17. */
  18. "public class DisplayObjectContainer extends flash.display.InteractiveObject",4,function($$private){var as=joo.as,assert=joo.assert;return[function(){joo.classLoader.init(flash.events.Event);},
  19. /**
  20. * Determines whether or not the children of the object are mouse, or user input device, enabled. If an object is enabled, a user can interact with it by using a mouse or user input device. The default is <code>true</code>.
  21. * <p>This property is useful when you create a button with an instance of the Sprite class (instead of using the SimpleButton class). When you use a Sprite instance to create a button, you can choose to decorate the button by using the <code>addChild()</code> method to add additional Sprite instances. This process can cause unexpected behavior with mouse events because the Sprite instances you add as children can become the target object of a mouse event when you expect the parent instance to be the target object. To ensure that the parent instance serves as the target objects for mouse events, you can set the <code>mouseChildren</code> property of the parent instance to <code>false</code>.</p>
  22. * <p>No event is dispatched by setting this property. You must use the <code>addEventListener()</code> method to create interactive functionality.</p>
  23. * @see Sprite#buttonMode
  24. * @see flash.events.EventDispatcher#addEventListener()
  25. *
  26. * @example The following example sets up a Sprite object (a type of display object container) named <code>container</code> and shows that when you set its <code>mouseChildren</code> property to <code>false</code>, the target of a <code>mouseClick</code> event is the <code>container</code> object, not any one of its child objects:
  27. * <listing>
  28. * import flash.display.Sprite;
  29. * import flash.events.MouseEvent;
  30. *
  31. * var container:Sprite = new Sprite();
  32. * container.name = "container";
  33. * addChild(container);
  34. *
  35. * var circle:Sprite = new Sprite();
  36. * circle.name = "circle";
  37. * circle.graphics.beginFill(0xFFCC00);
  38. * circle.graphics.drawCircle(40, 40, 40);
  39. *
  40. * container.addChild(circle);
  41. *
  42. * container.mouseChildren = false;
  43. *
  44. * container.addEventListener(MouseEvent.CLICK, clicked);
  45. *
  46. * function clicked(event:MouseEvent):void {
  47. * trace(event.target.name); // container
  48. * }
  49. * </listing>
  50. */
  51. "public function get mouseChildren",function mouseChildren$get()/*:Boolean*/ {
  52. throw new Error('not implemented'); // TODO: implement!
  53. },
  54. /**
  55. * @private
  56. */
  57. "public function set mouseChildren",function mouseChildren$set(value/*:Boolean*/)/*:void*/ {
  58. throw new Error('not implemented'); // TODO: implement!
  59. },
  60. /**
  61. * Returns the number of children of this object.
  62. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e40.html Advantages of the display list approach
  63. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e04.html Improved depth management
  64. *
  65. * @example The following example sets up two Sprite objects named <code>container1</code> and <code>container2</code>. A Sprite is a type of display object container. The example calls the <code>addChild()</code> method to set up the display hierarchy: <code>container1</code> is a child of <code>container2</code>, and two other display objects, <code>circle1</code> and <code>circle2</code>, are children of <code>container1</code>. The calls to the <code>trace()</code> method show the number of children of each object. Note that grandchildren are not included in the <code>numChildren</code> count:
  66. * <listing>
  67. * import flash.display.Sprite;
  68. *
  69. * var container1:Sprite = new Sprite();
  70. * var container2:Sprite = new Sprite();
  71. *
  72. * var circle1:Sprite = new Sprite();
  73. * circle1.graphics.beginFill(0xFFCC00);
  74. * circle1.graphics.drawCircle(40, 40, 40);
  75. *
  76. * var circle2:Sprite = new Sprite();
  77. * circle2.graphics.beginFill(0x00CCFF);
  78. * circle2.graphics.drawCircle(80, 40, 40);
  79. *
  80. * container2.addChild(container1);
  81. * container1.addChild(circle1);
  82. * container1.addChild(circle2);
  83. *
  84. * trace(container1.numChildren); // 2
  85. * trace(container2.numChildren); // 1
  86. * trace(circle1.numChildren); // 0
  87. * trace(circle2.numChildren); // 0
  88. * </listing>
  89. */
  90. "public function get numChildren",function numChildren$get()/*:int*/ {
  91. return this.children$4.length;
  92. },
  93. /**
  94. * Determines whether the children of the object are tab enabled. Enables or disables tabbing for the children of the object. The default is <code>true</code>.
  95. * <p><b>Note:</b> Do not use the <code>tabChildren</code> property with Flex. Instead, use the <code>mx.core.UIComponent.hasFocusableChildren</code> property.</p>
  96. * @throws flash.errors.IllegalOperationError Calling this property of the Stage object throws an exception. The Stage object does not implement this property.
  97. *
  98. * @example The following example creates a <code>container1</code> display object container and adds two display objects, <code>circle1</code> and <code>circle2</code>, to its child list. The example sets tabChildren to <code>false</code> for the children so it can manage its own tab order using <code>tabIndex</code>:
  99. * <listing>
  100. * import flash.display.Sprite;
  101. *
  102. * var container:Sprite = new Sprite();
  103. * container.tabChildren = false;
  104. *
  105. * var circle1:Sprite = new Sprite();
  106. * circle1.graphics.beginFill(0xFFCC00);
  107. * circle1.graphics.drawCircle(40, 40, 40);
  108. * circle1.tabIndex = 1;
  109. *
  110. * var circle2:Sprite = new Sprite();
  111. * circle2.graphics.beginFill(0x00CCFF);
  112. * circle2.graphics.drawCircle(120, 40, 40);
  113. * circle2.tabIndex = 0;
  114. *
  115. * container.addChild(circle1);
  116. * container.addChild(circle2);
  117. * </listing>To see the results of this example, compile and run the file. When you select one of the circles, you can press the TAB key to switch the display object that has focus (indicated by a yellow highlight rectangle).
  118. */
  119. "public function get tabChildren",function tabChildren$get()/*:Boolean*/ {
  120. throw new Error('not implemented'); // TODO: implement!
  121. },
  122. /**
  123. * @private
  124. */
  125. "public function set tabChildren",function tabChildren$set(value/*:Boolean*/)/*:void*/ {
  126. throw new Error('not implemented'); // TODO: implement!
  127. },
  128. /**
  129. * Returns a TextSnapshot object for this DisplayObjectContainer instance.
  130. * @see flash.text.TextSnapshot
  131. *
  132. * @example The following example works only in the Flash authoring environment. Flex does not include any ways of adding static text to a file. To prepare the Flash file for this example, add one or more static text fields in the first frame of a movie. Then insert the following script into the first frame and run the file. The output will be the static text that you added:
  133. * <listing>
  134. * trace(this.textSnapshot.getText(0, this.textSnapshot.charCount));
  135. * </listing>
  136. */
  137. "public function get textSnapshot",function textSnapshot$get()/*:TextSnapshot*/ {
  138. throw new Error('not implemented'); // TODO: implement!
  139. },
  140. /**
  141. * Calling the <code>new DisplayObjectContainer()</code> constructor throws an <code>ArgumentError</code> exception. You <i>can</i>, however, call constructors for the following subclasses of DisplayObjectContainer:
  142. * <ul>
  143. * <li><code>new Loader()</code></li>
  144. * <li><code>new Sprite()</code></li>
  145. * <li><code>new MovieClip()</code></li></ul>
  146. */
  147. "public function DisplayObjectContainer",function DisplayObjectContainer$() {
  148. this.children$4 = [];
  149. flash.display.InteractiveObject.call(this);
  150. },
  151. /**
  152. * Adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added to the front (top) of all other children in this DisplayObjectContainer instance. (To add a child to a specific index position, use the <code>addChildAt()</code> method.)
  153. * <p>If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.</p>
  154. * <p><b>Note:</b> The command <code>stage.addChild()</code> can cause problems with a published SWF file, including security problems and conflicts with other loaded SWF files. There is only one Stage within a Flash runtime instance, no matter how many SWF files you load into the runtime. So, generally, objects should not be added to the Stage, directly, at all. The only object the Stage should contain is the root object. Create a DisplayObjectContainer to contain all of the items on the display list. Then, if necessary, add that DisplayObjectContainer instance to the Stage.</p>
  155. * @param child The DisplayObject instance to add as a child of this DisplayObjectContainer instance.
  156. *
  157. * @return The DisplayObject instance that you pass in the <code>child</code> parameter.
  158. * Events
  159. * <table>
  160. * <tr>
  161. * <td><code><b>added</b>:<a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html"><code>Event</code></a></code> — Dispatched when a display object is added to the display list.</td></tr></table>
  162. * @throws ArgumentError Throws if the child is the same as the parent. Also throws if the caller is a child (or grandchild etc.) of the child being added.
  163. *
  164. * @see #addChildAt()
  165. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e40.html Advantages of the display list approach
  166. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e02.html Off-list display objects
  167. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3d.html Working with display objects
  168. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7dff.html Adding display objects to the display list
  169. *
  170. * @example The following example sets up two Sprite objects named <code>container1</code> and <code>container2</code>. A Sprite is a type of display object container. The example calls the <code>addChild()</code> method to set up the display hierarchy: <code>container1</code> is a child of <code>container2</code>, and two other display objects, <code>circle1</code> and <code>circle2</code>, are children of <code>container1</code>. The calls to the <code>trace()</code> method show the number of children of each object. Note that grandchildren are not included in the <code>numChildren</code> count:
  171. * <listing>
  172. * import flash.display.Sprite;
  173. *
  174. * var container1:Sprite = new Sprite();
  175. * var container2:Sprite = new Sprite();
  176. *
  177. * var circle1:Sprite = new Sprite();
  178. * circle1.graphics.beginFill(0xFFCC00);
  179. * circle1.graphics.drawCircle(40, 40, 40);
  180. *
  181. * var circle2:Sprite = new Sprite();
  182. * circle2.graphics.beginFill(0x00CCFF);
  183. * circle2.graphics.drawCircle(80, 40, 40);
  184. *
  185. * container2.addChild(container1);
  186. * container1.addChild(circle1);
  187. * container1.addChild(circle2);
  188. *
  189. * trace(container1.numChildren); // 2
  190. * trace(container2.numChildren); // 1
  191. * trace(circle1.numChildren); // 0
  192. * trace(circle2.numChildren); // 0
  193. * </listing>
  194. */
  195. "public function addChild",function addChild(child/*:DisplayObject*/)/*:DisplayObject*/ {
  196. return this.addChildAt(child, this.children$4.length);
  197. },
  198. /**
  199. * Adds a child DisplayObject instance to this DisplayObjectContainer instance. The child is added at the index position specified. An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainer object.
  200. * <p>For example, the following example shows three display objects, labeled a, b, and c, at index positions 0, 2, and 1, respectively:</p>
  201. * <p><img src="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/DisplayObjectContainer_layers.jpg" /></p>
  202. * <p>If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.</p>
  203. * @param child The DisplayObject instance to add as a child of this DisplayObjectContainer instance.
  204. * @param index The index position to which the child is added. If you specify a currently occupied index position, the child object that exists at that position and all higher positions are moved up one position in the child list.
  205. *
  206. * @return The DisplayObject instance that you pass in the <code>child</code> parameter.
  207. * Events
  208. * <table>
  209. * <tr>
  210. * <td><code><b>added</b>:<a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html"><code>Event</code></a></code> — Dispatched when a display object is added to the display list.</td></tr></table>
  211. * @throws RangeError Throws if the index position does not exist in the child list.
  212. * @throws ArgumentError Throws if the child is the same as the parent. Also throws if the caller is a child (or grandchild etc.) of the child being added.
  213. *
  214. * @see #addChild()
  215. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e40.html Advantages of the display list approach
  216. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e02.html Off-list display objects
  217. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e3d.html Working with display objects
  218. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7dff.html Adding display objects to the display list
  219. *
  220. * @example The following example creates a <code>container</code> display object container and adds a display objects <code>circle1</code> to its display list. Then, by calling <code>container.addChildAt(circle2, 0)</code>, it adds the <code>circle2</code> object to index position zero (the back), and moves the <code>circle1</code> object to index position 1:
  221. * <listing>
  222. * import flash.display.Sprite;
  223. *
  224. * var container:Sprite = new Sprite();
  225. *
  226. * var circle1:Sprite = new Sprite();
  227. * var circle2:Sprite = new Sprite();
  228. *
  229. * container.addChild(circle1);
  230. * container.addChildAt(circle2, 0);
  231. *
  232. * trace(container.getChildAt(0) == circle2); // true
  233. * trace(container.getChildAt(1) == circle1); // true
  234. * </listing>
  235. */
  236. "public function addChildAt",function addChildAt(child/*:DisplayObject*/, index/*:int*/)/*:DisplayObject*/ {
  237. var wasInStage/*:Boolean*/ = ! !child.stage;
  238. this.internalAddChildAt(child, index);
  239. var isInStage/*:Boolean*/ = ! !this.stage;
  240. if (wasInStage !== isInStage) {
  241. child.broadcastEvent(new flash.events.Event(isInStage ? flash.events.Event.ADDED_TO_STAGE : flash.events.Event.REMOVED_FROM_STAGE, false, false));
  242. }
  243. return child;
  244. },
  245. /**
  246. * @private
  247. */
  248. "public function internalAddChildAt",function internalAddChildAt(child/*:DisplayObject*/, index/*:int*/)/*:void*/ {
  249. var containerElement/*:Element*/ = this.getElement();
  250. var childElement/*:Element*/ = child.getElement();
  251. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 263, 5);
  252. var oldParent/*:DisplayObjectContainer*/ = child.parent;
  253. if (oldParent) {
  254. oldParent.removeChild(child);
  255. } else {
  256. assert(!childElement.parentNode || childElement.parentNode === childElement.ownerDocument.body, "DisplayObjectContainer.as", 268, 7);
  257. }
  258. var refChild/*:DisplayObject*/ = this.children$4[index];
  259. this.children$4.splice(index, 0, child);
  260. child.setParent(this);
  261. // also add to DOM:
  262. if (refChild) {
  263. containerElement.insertBefore(childElement, refChild.getElement());
  264. } else {
  265. containerElement.appendChild(childElement);
  266. }
  267. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 279, 5);
  268. },
  269. /**
  270. * Indicates whether the security restrictions would cause any display objects to be omitted from the list returned by calling the <code>DisplayObjectContainer.getObjectsUnderPoint()</code> method with the specified <code>point</code> point. By default, content from one domain cannot access objects from another domain unless they are permitted to do so with a call to the <code>Security.allowDomain()</code> method. For more information, related to security, see the Flash Player Developer Center Topic: <a href="http://www.adobe.com/go/devnet_security_en">Security</a>.
  271. * <p>The <code>point</code> parameter is in the coordinate space of the Stage, which may differ from the coordinate space of the display object container (unless the display object container is the Stage). You can use the <code>globalToLocal()</code> and the <code>localToGlobal()</code> methods to convert points between these coordinate spaces.</p>
  272. * @param point The point under which to look.
  273. *
  274. * @return <code>true</code> if the point contains child display objects with security restrictions.
  275. *
  276. * @see flash.system.Security#allowDomain()
  277. * @see #getObjectsUnderPoint()
  278. * @see DisplayObject#globalToLocal()
  279. * @see DisplayObject#localToGlobal()
  280. *
  281. * @example The following code creates a display object container named <code>container</code>. The next block of code uses a Loader object to load a JPEG file named "test.jpg" from a remote file server. Note that the <code>checkPolicyFile</code> property of the LoaderContext object used as a parameter in the <code>load()</code> method is set to <code>false</code>. Once the file is loaded, the code calls the <code>loaded()</code> method, which in turn calls <code>container.areInaccessibleObjectsUnderPoint()</code>, which returns a value of <code>true</code> because the loaded content is assumed to be from an inaccessible domain:
  282. * <listing>
  283. * import flash.display.Sprite;
  284. * import flash.display.Loader;
  285. * import flash.system.LoaderContext;
  286. * import flash.net.URLRequest;
  287. * import flash.events.Event;
  288. * import flash.geom.Point;
  289. *
  290. * var container:Sprite = new Sprite();
  291. *
  292. * var urlReq:URLRequest = new URLRequest("http://localhost/RemoteFile.swf");
  293. * var ldr:Loader = new Loader();
  294. * var context:LoaderContext = new LoaderContext();
  295. * context.checkPolicyFile = false;
  296. * ldr.load(urlReq, context);
  297. *
  298. * ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
  299. * ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, urlNotFound);
  300. *
  301. * function loaded(event:Event):void {
  302. * var pt:Point = new Point(1, 1);
  303. * trace(container.areInaccessibleObjectsUnderPoint(pt)); // true
  304. * }
  305. *
  306. * function urlNotFound(event:Event):void {
  307. * trace("The URL was not found.");
  308. * }
  309. * </listing>This example assumes that the SWF file produced by this code is loaded from a different domain than that of the JPEG file, and that the loaded JPEG file occupies the point (1, 1).
  310. */
  311. "public function areInaccessibleObjectsUnderPoint",function areInaccessibleObjectsUnderPoint(point/*:Point*/)/*:Boolean*/ {
  312. throw new Error('not implemented'); // TODO: implement!
  313. },
  314. /**
  315. * Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return <code>true</code>.
  316. * @param child The child object to test.
  317. *
  318. * @return <code>true</code> if the <code>child</code> object is a child of the DisplayObjectContainer or the container itself; otherwise <code>false</code>.
  319. *
  320. * @example The following example sets up a number of Sprite objects and adds some to the child list of others. (A Sprite object is a type of display object container.) The relationship between various objects is shown by calling the <code>contains()</code> method:
  321. * <listing>
  322. * import flash.display.Sprite;
  323. *
  324. * var sprite1:Sprite = new Sprite();
  325. * var sprite2:Sprite = new Sprite();
  326. * var sprite3:Sprite = new Sprite();
  327. * var sprite4:Sprite = new Sprite();
  328. *
  329. * sprite1.addChild(sprite2);
  330. * sprite2.addChild(sprite3);
  331. *
  332. * trace(sprite1.contains(sprite1)); // true
  333. * trace(sprite1.contains(sprite2)); // true
  334. * trace(sprite1.contains(sprite3)); // true
  335. * trace(sprite1.contains(sprite4)); // false
  336. * </listing>
  337. */
  338. "public function contains",function contains(child/*:DisplayObject*/)/*:Boolean*/ {
  339. return child === this || this.children$4.some(function flash$display$DisplayObjectContainer$353_44(someChild/*:DisplayObject*/)/*:Boolean*/ {
  340. var container/*:DisplayObjectContainer*/ =as( someChild, flash.display.DisplayObjectContainer);
  341. return container ? container.contains(child) : someChild === child;
  342. });
  343. },
  344. /**
  345. * Returns the child display object instance that exists at the specified index.
  346. * @param index The index position of the child object.
  347. *
  348. * @return The child display object at the specified index position.
  349. *
  350. * @throws RangeError Throws if the index does not exist in the child list.
  351. * @throws SecurityError This child display object belongs to a sandbox to which you do not have access. You can avoid this situation by having the child movie call <code>Security.allowDomain()</code>.
  352. *
  353. * @see #getChildByName()
  354. *
  355. * @example The following example creates a display object container named <code>container</code> and then adds a three display objects to the child list of the <code>container</code> object. The calls to the <code>getChildAt()</code> method then reveal the positions of the child objects:
  356. * <listing>
  357. * import flash.display.Sprite;
  358. *
  359. * var container:Sprite = new Sprite();
  360. *
  361. * var sprite1:Sprite = new Sprite();
  362. * var sprite2:Sprite = new Sprite();
  363. * var sprite3:Sprite = new Sprite();
  364. *
  365. * container.addChild(sprite1);
  366. * container.addChild(sprite2);
  367. * container.addChildAt(sprite3, 0);
  368. *
  369. * trace(container.getChildAt(0) == sprite3); // true
  370. * trace(container.getChildAt(1) == sprite1); // true
  371. * trace(container.getChildAt(2) == sprite2); // true
  372. * </listing>
  373. */
  374. "public function getChildAt",function getChildAt(index/*:int*/)/*:DisplayObject*/ {
  375. return as( this.children$4[index], flash.display.DisplayObject);
  376. },
  377. /**
  378. * Returns the child display object that exists with the specified name. If more that one child display object has the specified name, the method returns the first object in the child list.
  379. * <p>The <code>getChildAt()</code> method is faster than the <code>getChildByName()</code> method. The <code>getChildAt()</code> method accesses a child from a cached array, whereas the <code>getChildByName()</code> method has to traverse a linked list to access a child.</p>
  380. * @param name The name of the child to return.
  381. *
  382. * @return The child display object with the specified name.
  383. *
  384. * @throws SecurityError This child display object belongs to a sandbox to which you do not have access. You can avoid this situation by having the child movie call the <code>Security.allowDomain()</code> method.
  385. *
  386. * @see #getChildAt()
  387. * @see DisplayObject#name
  388. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e40.html Advantages of the display list approach
  389. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e04.html Improved depth management
  390. *
  391. * @example The following example creates a display object container named <code>container</code> and then adds two child display objects to the container. Then, the code calls the <code>getChildByName()</code> and <code>getChildIndex()</code> methods to return the index position of the child of the <code>container</code> object that has the <code>name "sprite1"</code>.
  392. * <listing>
  393. * import flash.display.Sprite;
  394. * import flash.display.DisplayObject;
  395. *
  396. * var container:Sprite = new Sprite();
  397. *
  398. * var sprite1:Sprite = new Sprite();
  399. * sprite1.name = "sprite1";
  400. * var sprite2:Sprite = new Sprite();
  401. * sprite2.name = "sprite2";
  402. *
  403. * container.addChild(sprite1);
  404. * container.addChild(sprite2);
  405. *
  406. * var target:DisplayObject = container.getChildByName("sprite1");
  407. * trace(container.getChildIndex(target)); // 0
  408. * </listing>
  409. */
  410. "public function getChildByName",function getChildByName(name/*:String*/)/*:DisplayObject*/ {
  411. for (var i/*:int*/ = 0; i < this.children$4.length; i++) {
  412. var child/*:DisplayObject*/ = this.children$4[i];
  413. if (child.name === name) {
  414. return child;
  415. }
  416. }
  417. return null;
  418. },
  419. /**
  420. * Returns the index position of a <code>child</code> DisplayObject instance.
  421. * @param child The DisplayObject instance to identify.
  422. *
  423. * @return The index position of the child display object to identify.
  424. *
  425. * @throws ArgumentError Throws if the child parameter is not a child of this object.
  426. *
  427. * @example The following example creates a display object container named <code>container</code> and then adds two child display objects to the container. Then, the code calls the <code>getChildByName()</code> and <code>getChildIndex()</code> methods to return the index position of the child of the <code>container</code> object that has the <code>name "sprite1"</code>.
  428. * <listing>
  429. * import flash.display.Sprite;
  430. * import flash.display.DisplayObject;
  431. *
  432. * var container:Sprite = new Sprite();
  433. *
  434. * var sprite1:Sprite = new Sprite();
  435. * sprite1.name = "sprite1";
  436. * var sprite2:Sprite = new Sprite();
  437. * sprite2.name = "sprite2";
  438. *
  439. * container.addChild(sprite1);
  440. * container.addChild(sprite2);
  441. *
  442. * var target:DisplayObject = container.getChildByName("sprite1");
  443. * trace(container.getChildIndex(target)); // 0
  444. * </listing>
  445. */
  446. "public function getChildIndex",function getChildIndex(child/*:DisplayObject*/)/*:int*/ {
  447. var index/*:int*/ = this.children$4.indexOf(child);
  448. if (index == -1) {
  449. throw new ArgumentError();
  450. }
  451. return index;
  452. },
  453. /**
  454. * Returns an array of objects that lie under the specified point and are children (or grandchildren, and so on) of this DisplayObjectContainer instance. Any child objects that are inaccessible for security reasons are omitted from the returned array. To determine whether this security restriction affects the returned array, call the <code>areInaccessibleObjectsUnderPoint()</code> method.
  455. * <p>The <code>point</code> parameter is in the coordinate space of the Stage, which may differ from the coordinate space of the display object container (unless the display object container is the Stage). You can use the <code>globalToLocal()</code> and the <code>localToGlobal()</code> methods to convert points between these coordinate spaces.</p>
  456. * @param point The point under which to look.
  457. *
  458. * @return An array of objects that lie under the specified point and are children (or grandchildren, and so on) of this DisplayObjectContainer instance.
  459. *
  460. * @see #areInaccessibleObjectsUnderPoint()
  461. * @see DisplayObject#globalToLocal()
  462. * @see DisplayObject#localToGlobal()
  463. *
  464. * @example The following example creates a display object container named <code>container</code> and then adds two overlapping child display objects to the container. Then the code calls the <code>getObjectsUnderPoint()</code> twice — first using a point that touches only one object, then using a point where the objects overlap — and the <code>length</code> of the return Array shows the number of objects at each point in the container:
  465. * <listing>
  466. * import flash.display.Sprite;
  467. * import flash.geom.Point;
  468. *
  469. * var container:Sprite = new Sprite();
  470. *
  471. * var square1:Sprite = new Sprite();
  472. * square1.graphics.beginFill(0xFFCC00);
  473. * square1.graphics.drawRect(0, 0, 40, 40);
  474. *
  475. * var square2:Sprite = new Sprite();
  476. * square2.graphics.beginFill(0x00CCFF);
  477. * square2.graphics.drawRect(20, 0, 30, 40);
  478. *
  479. * container.addChild(square1);
  480. * container.addChild(square2);
  481. *
  482. * var pt:Point = new Point(10, 20);
  483. * var objects:Array = container.getObjectsUnderPoint(pt);
  484. * trace(objects.length); // 1
  485. *
  486. * pt = new Point(35, 20);
  487. * objects = container.getObjectsUnderPoint(pt);
  488. * trace(objects.length); // 2
  489. * </listing>
  490. */
  491. "public function getObjectsUnderPoint",function getObjectsUnderPoint(point/*:Point*/)/*:Array*/ {
  492. throw new Error('not implemented'); // TODO: implement!
  493. },
  494. /**
  495. * Removes the specified <code>child</code> DisplayObject instance from the child list of the DisplayObjectContainer instance. The <code>parent</code> property of the removed child is set to <code>null</code> , and the object is garbage collected if no other references to the child exist. The index positions of any display objects above the child in the DisplayObjectContainer are decreased by 1.
  496. * <p>The garbage collector reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.</p>
  497. * @param child The DisplayObject instance to remove.
  498. *
  499. * @return The DisplayObject instance that you pass in the <code>child</code> parameter.
  500. *
  501. * @throws ArgumentError Throws if the child parameter is not a child of this object.
  502. *
  503. * @example The following example creates a display object container named <code>container</code> and then adds two child display objects to the container. An event listener is added to the <code>container</code> object, so that when the user clicks a child object of the container, the <code>removeChild()</code> method removes the child clicked from the child list of the container:
  504. * <listing>
  505. *
  506. * import flash.display.DisplayObject;
  507. * import flash.display.Sprite;
  508. * import flash.events.MouseEvent;
  509. *
  510. * var container:Sprite = new Sprite();
  511. * addChild(container);
  512. *
  513. * var circle1:Sprite = new Sprite();
  514. * circle1.graphics.beginFill(0xFFCC00);
  515. * circle1.graphics.drawCircle(40, 40, 40);
  516. *
  517. * var circle2:Sprite = new Sprite();
  518. * circle2.graphics.beginFill(0x00CCFF);
  519. * circle2.graphics.drawCircle(120, 40, 40);
  520. *
  521. * container.addChild(circle1);
  522. * container.addChild(circle2);
  523. *
  524. * container.addEventListener(MouseEvent.CLICK, clicked);
  525. *
  526. * function clicked(event:MouseEvent):void {
  527. * container.removeChild(DisplayObject(event.target));
  528. * }
  529. * </listing>
  530. */
  531. "public function removeChild",function removeChild(child/*:DisplayObject*/)/*:DisplayObject*/ {
  532. return this.removeChildAt(this.getChildIndex(child));
  533. },
  534. /**
  535. * Removes a child DisplayObject from the specified <code>index</code> position in the child list of the DisplayObjectContainer. The <code>parent</code> property of the removed child is set to <code>null</code>, and the object is garbage collected if no other references to the child exist. The index positions of any display objects above the child in the DisplayObjectContainer are decreased by 1.
  536. * <p>The garbage collector reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.</p>
  537. * @param index The child index of the DisplayObject to remove.
  538. *
  539. * @return The DisplayObject instance that was removed.
  540. *
  541. * @throws SecurityError This child display object belongs to a sandbox to which the calling object does not have access. You can avoid this situation by having the child movie call the <code>Security.allowDomain()</code> method.
  542. * @throws RangeError Throws if the index does not exist in the child list.
  543. *
  544. * @example The following example creates a display object container named <code>container</code> and then adds two child display objects to the container. The code then shows that when you call the <code>removeChildAt()</code> method to remove the child at the lowest index position (0), any other child object in the list moves down one position:
  545. * <listing>
  546. * import flash.display.Sprite;
  547. *
  548. * var container:Sprite = new Sprite();
  549. *
  550. * var sprite1:Sprite = new Sprite();
  551. * sprite1.name = "sprite1";
  552. * var sprite2:Sprite = new Sprite();
  553. * sprite2.name = "sprite2";
  554. *
  555. * container.addChild(sprite1);
  556. * container.addChild(sprite2);
  557. *
  558. * trace(container.numChildren) // 2
  559. * container.removeChildAt(0);
  560. * trace(container.numChildren) // 1
  561. * trace(container.getChildAt(0).name); // sprite2
  562. * </listing>
  563. */
  564. "public function removeChildAt",function removeChildAt(index/*:int*/)/*:DisplayObject*/ {
  565. var containerElement/*:HTMLElement*/ = this.getElement();
  566. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 587, 5);
  567. var child/*:DisplayObject*/ = this.children$4.splice(index, 1)[0];
  568. child.setParent(null);
  569. // if successful, remove in DOM, too:
  570. var childElement/*:Element*/ = child.getElement();
  571. containerElement.removeChild(childElement);
  572. assert(!childElement.parentNode, "DisplayObjectContainer.as", 593, 5);
  573. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 594, 5);
  574. return child;
  575. },
  576. /**
  577. * Changes the position of an existing child in the display object container. This affects the layering of child objects. For example, the following example shows three display objects, labeled a, b, and c, at index positions 0, 1, and 2, respectively:
  578. * <p><img src="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/DisplayObjectContainerSetChildIndex1.jpg" /></p>
  579. * <p>When you use the <code>setChildIndex()</code> method and specify an index position that is already occupied, the only positions that change are those in between the display object's former and new position. All others will stay the same. If a child is moved to an index LOWER than its current index, all children in between will INCREASE by 1 for their index reference. If a child is moved to an index HIGHER than its current index, all children in between will DECREASE by 1 for their index reference. For example, if the display object container in the previous example is named <code>container</code>, you can swap the position of the display objects labeled a and b by calling the following code:</p>
  580. * <listing>
  581. * container.setChildIndex(container.getChildAt(1), 0);</listing>
  582. * <p>This code results in the following arrangement of objects:</p>
  583. * <p><img src="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/DisplayObjectContainerSetChildIndex2.jpg" /></p>
  584. * @param child The child DisplayObject instance for which you want to change the index number.
  585. * @param index The resulting index number for the <code>child</code> display object.
  586. *
  587. * @throws RangeError Throws if the index does not exist in the child list.
  588. * @throws ArgumentError Throws if the child parameter is not a child of this object.
  589. *
  590. * @see #addChildAt()
  591. * @see #getChildIndex()
  592. *
  593. * @example The following example creates a display object container named <code>container</code> and then adds three slightly overlapping child display objects to the container. When the user clicks any of these objects, the <code>clicked()</code> method calls the <code>setChildIndex()</code> method to move the clicked object to the top-most position in the child list of the <code>container</code> object:
  594. * <listing>
  595. * import flash.display.Sprite;
  596. * import flash.events.MouseEvent;
  597. *
  598. * var container:Sprite = new Sprite();
  599. * addChild(container);
  600. *
  601. * var circle1:Sprite = new Sprite();
  602. * circle1.graphics.beginFill(0xFF0000);
  603. * circle1.graphics.drawCircle(40, 40, 40);
  604. * circle1.addEventListener(MouseEvent.CLICK, clicked);
  605. *
  606. * var circle2:Sprite = new Sprite();
  607. * circle2.graphics.beginFill(0x00FF00);
  608. * circle2.graphics.drawCircle(100, 40, 40);
  609. * circle2.addEventListener(MouseEvent.CLICK, clicked);
  610. *
  611. * var circle3:Sprite = new Sprite();
  612. * circle3.graphics.beginFill(0x0000FF);
  613. * circle3.graphics.drawCircle(70, 80, 40);
  614. * circle3.addEventListener(MouseEvent.CLICK, clicked);
  615. *
  616. * container.addChild(circle1);
  617. * container.addChild(circle2);
  618. * container.addChild(circle3);
  619. * addChild(container);
  620. *
  621. * function clicked(event:MouseEvent):void {
  622. * var circle:Sprite = Sprite(event.target);
  623. * var topPosition:uint = container.numChildren - 1;
  624. * container.setChildIndex(circle, topPosition);
  625. * }
  626. * </listing>
  627. */
  628. "public function setChildIndex",function setChildIndex(child/*:DisplayObject*/, index/*:int*/)/*:void*/ {
  629. this.removeChild(child);
  630. this.addChildAt(child, index);
  631. },
  632. /**
  633. * Swaps the z-order (front-to-back order) of the two specified child objects. All other child objects in the display object container remain in the same index positions.
  634. * @param child1 The first child object.
  635. * @param child2 The second child object.
  636. *
  637. * @throws ArgumentError Throws if either child parameter is not a child of this object.
  638. *
  639. * @example The following example creates a display object container named <code>container</code>, then adds two child display objects to the container, and then shows the effect of a call to the <code>swapChildren()</code> method:
  640. * <listing>
  641. * import flash.display.Sprite;
  642. *
  643. * var container:Sprite = new Sprite();
  644. *
  645. * var sprite1:Sprite = new Sprite();
  646. * sprite1.name = "sprite1";
  647. * var sprite2:Sprite = new Sprite();
  648. * sprite2.name = "sprite2";
  649. *
  650. * container.addChild(sprite1);
  651. * container.addChild(sprite2);
  652. *
  653. * trace(container.getChildAt(0).name); // sprite1
  654. * trace(container.getChildAt(1).name); // sprite2
  655. *
  656. * container.swapChildren(sprite1, sprite2);
  657. *
  658. * trace(container.getChildAt(0).name); // sprite2
  659. * trace(container.getChildAt(1).name); // sprite1
  660. * </listing>
  661. */
  662. "public function swapChildren",function swapChildren(child1/*:DisplayObject*/, child2/*:DisplayObject*/)/*:void*/ {
  663. var child1Index/*:int*/ = this.children$4.indexOf(child1);
  664. var child2Index/*:int*/ = this.children$4.indexOf(child2);
  665. if (child1Index === -1 || child2Index === -1) {
  666. throw new ArgumentError;
  667. }
  668. this.swapChildrenAt(child1Index, child2Index);
  669. },
  670. /**
  671. * Swaps the z-order (front-to-back order) of the child objects at the two specified index positions in the child list. All other child objects in the display object container remain in the same index positions.
  672. * @param index1 The index position of the first child object.
  673. * @param index2 The index position of the second child object.
  674. *
  675. * @throws RangeError If either index does not exist in the child list.
  676. *
  677. * @example The following example creates a display object container named <code>container</code>, then adds three child display objects to the container, and then shows how a call to the <code>swapChildrenAt()</code> method rearranges the child list of the display object container:
  678. * <listing>
  679. * import flash.display.Sprite;
  680. *
  681. * var container:Sprite = new Sprite();
  682. *
  683. * var sprite1:Sprite = new Sprite();
  684. * sprite1.name = "sprite1";
  685. * var sprite2:Sprite = new Sprite();
  686. * sprite2.name = "sprite2";
  687. * var sprite3:Sprite = new Sprite();
  688. * sprite3.name = "sprite3";
  689. *
  690. * container.addChild(sprite1);
  691. * container.addChild(sprite2);
  692. * container.addChild(sprite3);
  693. *
  694. * trace(container.getChildAt(0).name); // sprite1
  695. * trace(container.getChildAt(1).name); // sprite2
  696. * trace(container.getChildAt(2).name); // sprite3
  697. *
  698. * container.swapChildrenAt(0, 2);
  699. *
  700. * trace(container.getChildAt(0).name); // sprite3
  701. * trace(container.getChildAt(1).name); // sprite2
  702. * trace(container.getChildAt(2).name); // sprite1
  703. * </listing>
  704. */
  705. "public function swapChildrenAt",function swapChildrenAt(index1/*:int*/, index2/*:int*/)/*:void*/ {
  706. if (index1 > index2) {
  707. this.swapChildrenAt(index2, index1);
  708. } else if (index1 < index2) {
  709. var containerElement/*:Element*/ = this.getElement();
  710. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 734, 7);
  711. var child1/* : DisplayObject*/ = this.children$4[index1];
  712. var child2/* : DisplayObject*/ = this.children$4[index2];
  713. this.children$4.splice(index1, 1, child2);
  714. this.children$4.splice(index2, 1, child1);
  715. // also change in DOM, mind to insert left element first:
  716. var child1Element/*:Element*/ = child1.getElement();
  717. var child2Element/*:Element*/ = child2.getElement();
  718. var refElement/*:Element*/ =/* js.Element*/(child2Element.nextSibling); // since index1 < index2, refElement cannot be child1Element
  719. containerElement.insertBefore(child2Element, child1Element); // this removes child2Element at its old position, but we still have refElement
  720. if (refElement) {
  721. containerElement.insertBefore(child1Element, refElement);
  722. } else {
  723. containerElement.appendChild(child1Element);
  724. }
  725. assert(containerElement.childNodes.length === this.children$4.length, "DisplayObjectContainer.as", 749, 7);
  726. }
  727. },
  728. /**
  729. * @inheritDoc
  730. */
  731. "override public function get height",function height$get()/*:Number*/ {
  732. var _height/*:Number*/ = this.height$4 || 0;
  733. for (var i/*:int*/ = 0; i < this.children$4.length; i++) {
  734. var child/*:DisplayObject*/ = this.children$4[i];
  735. var childHeight/*:Number*/ = child.y + child.height;
  736. if (childHeight > _height) {
  737. _height = childHeight;
  738. }
  739. }
  740. return _height;
  741. },
  742. /**
  743. * @inheritDoc
  744. */
  745. "override public function get width",function width$get()/*:Number*/ {
  746. var _width/*:Number*/ = this.width$4 || 0;
  747. for (var i/*:int*/ = 0; i < this.children$4.length; i++) {
  748. var child/*:DisplayObject*/ = this.children$4[i];
  749. var childWidth/*:Number*/ = child.x + child.width;
  750. if (childWidth > _width) {
  751. _width = childWidth;
  752. }
  753. }
  754. return _width;
  755. },
  756. // ************************** Jangaroo part **************************
  757. /**
  758. * @private
  759. */
  760. "override public function broadcastEvent",function broadcastEvent(event/*:Event*/)/*:Boolean*/ {
  761. if (this.dispatchEvent(event)) { // same as super.broadcastEvent(event), but more efficient
  762. this.children$4.every(function flash$display$DisplayObjectContainer$790_22(child/*:DisplayObject*/)/*:Boolean*/ {
  763. return child.broadcastEvent(event);
  764. });
  765. return true;
  766. }
  767. return false;
  768. },
  769. "private var",{ children/* : Array*/:null}/*<DisplayObject>*/,
  770. ];},[],["flash.display.InteractiveObject","Error","flash.events.Event","flash.display.DisplayObject","ArgumentError","js.Element"], "0.8.0", "0.9.6"
  771. );