Having trouble with multiple instances of the same object
I'm relatively new to Flash Actionscript but I've been programming in OOP for years so it only took a few days to get up to speed, however I've ran into a few weird quirks that make me wonder if I'm doing something wrong.
I've got a single scene, a main timeline within that scene and within certain frames of the main scene I've got mc's that play based on Actionscript commands. All of that works fine until I get into one of the mcs. Within them I have buttons defined on certain frames and I've assigned instance names to those buttons.
The problem is when I try to reuse an instance name on two different key frames. Within the parent scene it works fine, within the child mc only the first instance works. If I target a different frame that has the same button and instance name in the ActionScript, it does not work unless I rename the instance name in the second key frame. It sounds confusing so here is an example:
//Example_mc.Frame1 (keyframe1)
//Goes to frame 5 in Example_mc
this.button1_btn.onPress = function() {
gotoAndPlay(5)
}
//Example_mc.Frame10 (keyframe2)
//Should go to frame 5 in Example_mc but does not
this.button1_btn.onPress = function() {
gotoAndPlay(5)
}
//Example_mc.Frame10 (keyframe2)
//Properly goes to Frame5 after renaming button1 instance to button1a
this.button1a_btn.onPress = function() {
gotoAndPlay(5)
}
In the example above, when button1_btn is pressed frame 1 is properly displayed. When I try to reuse the button and button instance in frame 10, the button does not work until I rename the instance name to a unique name.
However, in the main scene, all of my navigation is done through re-usable button instances which is why I do not understand why it is not working in the child mcs.
My main question is, shouldn't I be able to re-use instance names in a child mc? If so, then what am I doing wrong?