ActionScript 3, using the Time Line and the DisplayList. DL keeps duplicating stuff

Hello there,

Iv’e been slowly moving over to AS3 in the past few months and I think I have learnt quite a considerable amout. However I am completly dumbstruck by the behaviour of the DisplayList.

The kind of work I do requuires that the flash movies I make are timeline based (I know spitting in the face of OOP) because of the amount of animation used. However within these animations I also use snippets of ActionScript to have interactive moments such as drag and drops or tabs for the user to select a section. Now in these cases I as you would expect have to redepth some stuff (like the currently active panel of some tabs or currently active drag item etc). Using the display list I think is dead easy and I actually prefer it to the old Depth based system of ActionScript 2. This is where the odd problem starts.

On my stage I have 2 insences of the same MovieClip (“Clock1” and “Clock2”) which has a child named “hand”, also I have 2 text boxes just to dictate which movie is which. These clips and text are nothing special just author created in flash so no code involved for adding them to the display list.

the display list looks like this

0 - [object StaticText] Piece of static text
1 - [object StaticText] Piece of static text
2 - [object Clock_1] “Clock1”
3 - [object Clock_1] “Clock2”

The time line is 20 frames long, at frame 1 i bring “Clock1” to the top of the display list using addChild and at frame 10 the hands on the clocks are rotated by 5 degrees.

frame 1

addChild(clock1)

frame 10

clock1.hand.rotation += 5;
clock2.hand.rotation += 5;
trace("Numchildren: " + numChildren);

Now if you run this you will notice the number of children keeps going up! As soon as the code goes back to frame 1 the display list duplicates any Display Objects that have had their display list order changed. Try changing the addChild(clock1) to swapChildren(clock1,clock2) and it will duplicate both clips.

If you take out any code that changes the display list the code will run and no dupications are made. Also this only happens when you gotoAndStop/gotoAndPlay an earlier frame.

I have read through the help docs and code references in Flash as well as googling my brain out but can’t find anyone complaining of similar problems.

Also to clarify I have Built this using AS3 in CS3 Player 9 but have also compiled it from CS4 Player 10 with the same results.

To me this seems like a bug rather than a feature but I am hoping there is a solution to stop this mad duplication

Answers on the back of a postcard…or on here :stuck_out_tongue:

Simon