It’s an odd behaviour for someone used to c# and more or less synchronous programming, not to mention complete ignorance regarding frame and timeline behaviour… (i have never before worked with as3 or flash)
I’m working on a part of game similar to a classic dress-up, with a difference being that a doll is dinosaur and clothes are his body parts (snuts, textures, eyes…) plus whole thing must be animated for use in the game (simple stuff, eating, walking…)
In short, when dino is instanced/created/added on stage everything is as it should be, changing and coloring body parts works, and so do the animations. However when the same dino is created from the same XMLs in the same manner for top list card (smaller and in different place in display tree) he gets surplus parts.
Graphics and animations are created in Flash CS4, and dino recieves 3 XMLs as constructor arguments describing where the slots for items are in display list (structure.xml), all available items (items.xml) and combination of items saved for a particular user (user.xml).
Process of creating dino:
- instancing imported symbol (swc) of whole dino as created in authoring tool, with animations etc… let’s call it display root
- replacing some movieclips in display root display list with slots. For example movieclip Snut1 (present because it is used in authoring tool for creating animations) is replaced with object of class Slot (extends movieclip) with id = 1, in which I will later put snuts Snut1 or Snut2 … , as selected by the user. This is done depending on information in structure.xml.
- inserting Items in Slots, depending on information in user.xml and items.xml. Creating of items is done with information from items.xml, and includes class name of imported symbol, paths to child objects to be colored onColorChange (for example when color of eyes is changes only retina filters are changed), animation descriptions (path of child object to animate, end frame, start frame, custom algorithm for frame progress etc…), etc… user.xml has information about selected items and their colors.
- adding animation descriptors for whole dino.
OK, not particularly elegant, but it works. (later, as i learned along the way, i found out some rather elementary stuff, but it was too late for reprogramming)
When i heard that addChild is asynchronous operation, i tried to ensure that animation descriptors are loaded after items, and items after slots, with ADDED event, but now it seems that was completely useless…
So, details about problem:
on stage, everything is ok.
in top list user card dino is created ok, trace immediately after new Dino() statement shows everything is where it should be.
in some frame later, for, to me, unknown reason in, to me, unknown manner, in display list of dino someone (and I assure you, no one on project wrote code that could do that intentionally) adds objects of imported symbols that should, and have, been removed from display list in stage 2 of dino assembling process.
So the original symbol body branch as exported from flash CS4 looks like this:
-Osteoderm1
-shape
-Belly1
-shape
-Texture1
Children of branch body look like this after new Dino(structure, items, user), because stage 2 of assembling.
- Slot (id=1)
–Osteoderm1 - shape
- Slot (id=2)
–Belly1 - shape
- slot (id=3)
–Texture1
but few (or just 1) frame later:
- Slot (id=1)
–Osteoderm1
-Osteoderm1 - shape
- Slot (id=2)
–Belly1
-Belly1 - shape
- slot (id=3)
–Texture1
-Texture1
Now, i’ve reread code several times, traced every step in creation process, everything is the same as it is when everything works on instancing for adding on stage.
The only difference is in size and position, but when we tried with same parameters problem remained.
I suspect it has something to do with time that is needed for creating dino in top list (because of creating dinos for several users and additional attaining of xmls from server), and either frame by frame rendering of flash player or add/remove child asynchronous behaviour, but i’m not sure what and how to fix it.
Can anyone explain to me what can go wrong, best practice for time consuming assembling, or anything like that that could be relevant? Or that doesn’t have anything to do with the problem?
Thanks for any help, i hope i descibed the problem clearly…