PDA

View Full Version : new issue with duplicateDisplayObject in CS4


madrid1979
11-20-2008, 05:00 PM
Greetings all, long-time lurker, first-time poster.

I've ran into a problem with the ever popular duplicateDisplayObject() of Senocular fame. From version CS4, the duplicated displayObject only consists of the displayObjectContainer and not the displayObjects within the container.

Put another way, if the movie clip you're looking to duplicate contains children movie clips, they are not duplicated as part of the function (as was the case in the version prior to CS4.)

Here's some code as an example:


for (var i:int = 0; i < movieArray.length; i++) {

objectArray.push(duplicateDisplayObject(dataCapsul e, false));

objectArray[i].x = 54;
objectArray[i].y += startY+(i*15);

objectArray[i].titles.text = movieArray[i].title;
objectArray[i].descriptions.text = movieArray[i].description;
objectArray[i].runningTimes.text = movieArray[i].runningTime;
objectArray[i].categories.text = movieArray[i].category;
objectArray[i].instanceName = movieArray[i].filename;

objectArray[i].lite.visible = false;
objectArray[i].cadPlus.visible = false;
objectArray[i].optical.visible = false;
objectArray[i].advanced.visible = false;
objectArray[i].optional.visible = false;

....
}


As you can see from the above, the dataCapsule object was getting duplicated, and added to an object array, where in version CS3, the other objects that were children of the dataCapsule object were still accessible.

To prove this was working at one point, I turn you to a .swf exported in CS3, flash player 9 in which this was actually functioning:

http://www.breault.com/_testing/xml/ (http://http://www.breault.com/_testing/xml/)

Again, in version CS4, the code fails with the following error:


TypeError: Error #1010: A term is undefined and has no properties.
at BroDemoVersion4_MasterFile_v1_CS4_fla::IndexViewOb ject_2/renderResults()[BroDemoVersion4_MasterFile_v1_CS4_fla.IndexViewObj ect_2::frame2:140]
at BroDemoVersion4_MasterFile_v1_CS4_fla::IndexViewOb ject_2/xmlLoaded()[BroDemoVersion4_MasterFile_v1_CS4_fla.IndexViewObj ect_2::frame2:19]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()


It took me a while to figure out what was going on with the code; every property for the objects in objectArray doesn't exist as they had prior to CS4.

I ran a check on the dataCapsule object for a count of the children objects [trace(dataCapsule.numChildren);]. It returns 10 items; Correct. However, once the object is duplicated using the duplicateDisplayObject() function, the object returns 0 children.

My question is:
Are there any methods to which the duplicateDisplayObject() function can be added so that children of the DisplayObject to be duplicated will be included in the dupe?

Or

Is there a new method for which I should consider?

In case you haven't looked at the example, the purpose of my code is to take a line-item type object (like a list entry) and duplicate it, each line having unique data. The line consists of 4 text field object, a button object, and 5 basic graphics movie clip objects.

THINGS I'VE TRIED:
I've tried adding children to the duplicated object by duplicating the initial child objects from the intial dataCapsule object:

for (var c:int = 0; c < dataCapsule.numChildren; c++) {

var targetObj:DisplayObject = duplicateDisplayObject(dataCapsule.getChildAt(c), false);
objectArray[i].addChild(targetObj);
}


This doesn't work.

Any ideas?