[web] Symbol instances being overwritten or not found

Started by
0 comments, last by shadowisadog 15 years, 10 months ago
Either this is a flash bug, or I'm seriously overlooking a subtely of movieclips. I'm creating a flash game where you can walk around 10 different rooms. Each room has its own background. And each room can have either one or two doors, which lead to other rooms. So very simply, I have a movieclip symbol called "backgrounds", and its timeline has 10 frames, where each frame is a different room background. Also I have a symbol called "door" which I'm nesting inside the frames of the backgrounds. For example, in frame 1 of "backgrounds", I've manually placed two "doors". I've named the door instances "door1" and "door2". Likewise in all the other background frames, I similarly manually position one or two door symbols and also name their instances "door1" or "door2" so that my code can work universally with doors. Now here's the part that has been driving me insane for about 4 days and you're probably a flash genius if you know the answer: I use backgrounds.gotoAndStop(x) to jump to the correct background for the given room. When I go forward with gotoAndStop, I can access the door instance variables with no problem. But when I go backwards, the door instances are erased or write over each other!!! Example: frame 1 of backgrounds has just "door1" instance. I now do backgrounds.gotoAndStop(2). Frame 2 of backgrounds has just a "door2" instance. If I now do backgrounds.gotoAndStop(1), I can no longer access the "door1" instance in frame 1! If I now do backgrounds.getChildByName("door1"), it returns null in frame 1! It's as if the door instances are not being reinitialized when I go backwards with gotoAndStop. By the way, I'm just accessing the door instances to do collision detection with the doors such as myCharacter.hitObjectTest(backgrounds.door1) for example. Any insights enormously appreciated!
Advertisement
What I would do would be to give the doors on each frame different instance names but make them all export the same classes for ActionScript (in the properties).

So like on frame 1 you would have Level1_Door1 which exports class Door1.

If you do things that way then you can still have your code apply universally to the doors and you get the benefit of not worrying about your instance names being overwritten.

I hope this helps :) .

This topic is closed to new replies.

Advertisement