@@ -115,8 +115,7 @@ define(function (require, exports, module) { // jshint ignore:line
115
115
* @chainable
116
116
*/
117
117
DisplayObjectContainer . prototype . createChildren = function ( ) {
118
- // Meant to be overridden because the extended class should call the createChildren method.
119
- return this ;
118
+ throw new Error ( '[' + this . getQualifiedClassName ( ) + '] Error: The createChildren method is meant to be overridden.' ) ;
120
119
} ;
121
120
122
121
/**
@@ -135,7 +134,7 @@ define(function (require, exports, module) { // jshint ignore:line
135
134
DisplayObjectContainer . prototype . addChild = function ( child ) {
136
135
//If the child being passed in already has a parent then remove the reference from there.
137
136
if ( child . parent ) {
138
- child . parent . removeChild ( child ) ;
137
+ child . parent . removeChild ( child , false ) ;
139
138
}
140
139
141
140
this . children . push ( child ) ;
@@ -161,7 +160,7 @@ define(function (require, exports, module) { // jshint ignore:line
161
160
DisplayObjectContainer . prototype . addChildAt = function ( child , index ) {
162
161
//If the child being passed in already has a parent then remove the reference from there.
163
162
if ( child . parent ) {
164
- child . parent . removeChild ( child ) ;
163
+ child . parent . removeChild ( child , false ) ;
165
164
}
166
165
167
166
this . children . splice ( index , 0 , child ) ;
@@ -172,6 +171,55 @@ define(function (require, exports, module) { // jshint ignore:line
172
171
return this ;
173
172
} ;
174
173
174
+ /**
175
+ * Removes the specified child object instance from the child list of the parent object instance.
176
+ * The parent property of the removed child is set to null , and the object is garbage collected if no other references
177
+ * to the child exist. The index positions of any objects above the child in the parent object are decreased by 1.
178
+ *
179
+ * @method removeChild
180
+ * @param child {DisplayObjectContainer} The DisplayObjectContainer instance to remove.
181
+ * @returns {DisplayObjectContainer } Returns an instance of itself.
182
+ * @public
183
+ * @chainable
184
+ */
185
+ DisplayObjectContainer . prototype . removeChild = function ( child , destroy ) {
186
+ var index = this . getChildIndex ( child ) ;
187
+ if ( index !== - 1 ) {
188
+ // Removes the child object from the parent.
189
+ this . children . splice ( index , 1 ) ;
190
+ }
191
+
192
+ if ( destroy === true ) {
193
+ child . destroy ( ) ;
194
+ } else {
195
+ child . disable ( ) ;
196
+ }
197
+
198
+ child . parent = null ;
199
+
200
+ this . numChildren = this . children . length ;
201
+
202
+ return this ;
203
+ } ;
204
+
205
+ /**
206
+ * Removes all child DisplayObjectContainer instances from the child list of the DisplayObjectContainerContainer instance.
207
+ * The parent property of the removed children is set to null , and the objects are garbage collected if
208
+ * no other references to the children exist.
209
+ *
210
+ * @method removeChildren
211
+ * @returns {DisplayObjectContainer } Returns an instance of itself.
212
+ * @public
213
+ * @chainable
214
+ */
215
+ DisplayObjectContainer . prototype . removeChildren = function ( destroy ) {
216
+ while ( this . children . length > 0 ) {
217
+ this . removeChild ( this . children . pop ( ) , destroy ) ;
218
+ }
219
+
220
+ return this ;
221
+ } ;
222
+
175
223
/**
176
224
* Swaps two DisplayObjectContainer's with each other.
177
225
*
@@ -183,8 +231,7 @@ define(function (require, exports, module) { // jshint ignore:line
183
231
* @chainable
184
232
*/
185
233
DisplayObjectContainer . prototype . swapChildren = function ( child1 , child2 ) {
186
- // Meant to be overridden because the extended class should call the addChildAt method.
187
- return this ;
234
+ throw new Error ( '[' + this . getQualifiedClassName ( ) + '] Error: The swapChildren method is meant to be overridden.' ) ;
188
235
} ;
189
236
190
237
/**
@@ -234,50 +281,6 @@ define(function (require, exports, module) { // jshint ignore:line
234
281
return this . children . indexOf ( child ) >= 0 ;
235
282
} ;
236
283
237
- /**
238
- * Removes the specified child object instance from the child list of the parent object instance.
239
- * The parent property of the removed child is set to null , and the object is garbage collected if no other references
240
- * to the child exist. The index positions of any objects above the child in the parent object are decreased by 1.
241
- *
242
- * @method removeChild
243
- * @param child {DisplayObjectContainer} The DisplayObjectContainer instance to remove.
244
- * @returns {DisplayObjectContainer } Returns an instance of itself.
245
- * @public
246
- * @chainable
247
- */
248
- DisplayObjectContainer . prototype . removeChild = function ( child ) {
249
- var index = this . getChildIndex ( child ) ;
250
- if ( index !== - 1 ) {
251
- this . children . splice ( index , 1 ) ;
252
- }
253
- child . disable ( ) ;
254
- child . parent = null ;
255
-
256
- this . numChildren = this . children . length ;
257
-
258
- return this ;
259
- } ;
260
-
261
- /**
262
- * Removes all child DisplayObjectContainer instances from the child list of the DisplayObjectContainerContainer instance.
263
- * The parent property of the removed children is set to null , and the objects are garbage collected if
264
- * no other references to the children exist.
265
- *
266
- * @method removeChildren
267
- * @returns {DisplayObjectContainer } Returns an instance of itself.
268
- * @public
269
- * @chainable
270
- */
271
- DisplayObjectContainer . prototype . removeChildren = function ( ) {
272
- while ( this . children . length > 0 ) {
273
- this . removeChild ( this . children . pop ( ) ) ;
274
- }
275
-
276
- this . numChildren = this . children . length ;
277
-
278
- return this ;
279
- } ;
280
-
281
284
/**
282
285
* Returns the child display object instance that exists at the specified index.
283
286
*
@@ -339,6 +342,16 @@ define(function (require, exports, module) { // jshint ignore:line
339
342
return this ;
340
343
} ;
341
344
345
+ /**
346
+ * @overridden EventDispatcher.destroy
347
+ */
348
+ DisplayObjectContainer . prototype . destroy = function ( ) {
349
+ _super . prototype . destroy . call ( this ) ;
350
+ } ;
351
+ return DisplayObjectContainer ; ainer . prototype . layoutChildren = function ( ) {
352
+ return this ;
353
+ } ;
354
+
342
355
/**
343
356
* @overridden EventDispatcher.destroy
344
357
*/
0 commit comments