Short version of the question, for those disinclined to reading: Under what circumstances could one display object be inside a Canvas, with non-zero height and width, alpha of 1, visible == true, have the highest myCanvas.getChildIndex() value, etc. etc. and still not be rendered onscreen (or respond to the mouse) even when other display objects inside the canvas are rendered correctly?
Moreover, under what circumstances could this happen only about 50% of the times the program is run, while working correctly the other 50% of the time after the same sequence of user actions?
Long version of the question:
I’m working on a Flex engine for browser-based point-and-click adventure games. It takes a game.xml file and parses it, along with a directory of graphic resources, into something along the lines of Submachine, though a bit more sophisticated.
I’ve run into a bug that I probably could just work around and get my game running… but I anticipate that others may eventually make games using my engine, so I’d like to actually squash the bug itself.
The game’s Rooms can contain RoomObjects and Exits. All of those (Room, RoomObject and Exit) extend Canvas. When the player moves to a new room, the old Room is removed from the game’s main Canvas, and the new Room is added.
The bug occurs when a player’s actions in one Room cause an Exit or RoomObject to be added to a different Room that the player has already visited. When the player returns to that room, the Exit or Object is rendered correctly about 50% of the times the program is run, and 50% it isn’t (even if the player tries leaving and coming back). Things like trace(Room(myObject.parent).name); and trace(myObject.visible); all give responses that indicate that everything has gone as planned and the object should be visible onscreen… it just isn’t.
I’ve tried calling things like validateNow() on the object, the room, the application, etc… nothing works.
When an Exit or RoomObject is added to the player’s current Room, it works 100% of the time. Likewise, when adding an Exit or RoomObject to a Room the player has not yet visited, it works 100% of the time.
Thus, I suspect it’s some kind of caching problem… the Flash player is remembering the Room the way it was the last time the player visited, and doesn’t realize that something new has been added since then. The question is, how do I force it to refresh?
Help!