Copy link to clipboard
Copied
Hello, I apologize if this question has already been asked but as the title states I'm having problems with the instance names of my buttons. I am using Actionscript 3 with Flash CS5. I apologize in advance for being verbose but it'd be best if I explained my problem in detail.
I have my project set up so that everything occurs in one MovieClip and buttons within the MovieClip are clicked to navigate through the MovieClip. The MovieClip contains several frames which are all unique and contain a variety of textboxes, MovieClips, buttons, classes and other custom classes. All of these components are created directly in Flash Professional by dragging them from the library onto the stage inside of the MovieClip.
I then name these components using Flash Professional and use these instance names to work with the components. Usually this works without a problem. However, now that I am using a nested MovieClip for my project many problems are occuring. I have it so that when buttons are clicked, the MovieClip goes to a certain frame via the gotoAndStop(x); command. This works fine but I am having problems accessing the buttons that I have named earlier. It gives a null object reference error and when I trace the button it traces as "null".
Originally I thought that this problem was because the MovieClip had not yet initialized but I had used the ADDED and RENDER event listeners, Timeline scripting, and other methods but the button was still null, leading me to believe that the problem was more than that.
So I used a click event listener that traced the instance names of the components that I was clicking (trace(e.target.name)). I have a total of 8 buttons on the specific frame of my MovieClip so I clicked on them all. 6/8 of the buttons traced the correct instance name that I had given them whereas the other two buttons traced "instance 169" and "instance 177" instead of the instance name.
With all this strangeness, I commented out the code for these 2 specific buttons to see if it would work without them. Sure enough it did.
I believe that my buttons have lost their stage instance names and I do not know how to fix this problem. I have tried deleting the buttons and creating them again but to no avail. It does work, however, if I use the Button component that Flash has but I do not want to do that because I'd like to use my own custom buttons (I know the Button component is customizeable, but I'd like to use my own anyways).
If anyone could help, please how can I fix this problem? If my .fla or specific code needs to be provided, I can do so.
Do not use 'e.target.name' because that can end up pointing to an object that was clicked that lives inside the button rather than the button itself. Instead you should use 'e.currentTarget.name'. That will always point to the object that has the event listener assigned to it.
If you are getting error 1009, here are some things to consider to help resolve it...
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is
...Copy link to clipboard
Copied
Do not use 'e.target.name' because that can end up pointing to an object that was clicked that lives inside the button rather than the button itself. Instead you should use 'e.currentTarget.name'. That will always point to the object that has the event listener assigned to it.
If you are getting error 1009, here are some things to consider to help resolve it...
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is declared but not instantiated
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.
Copy link to clipboard
Copied
Without looking at your code I can't say 100% what is going on. However, I suspect what is happening is that you're doing the following:
Or some variation of above, where an instance was on the stage, is removed, and even though it appears to have been added back you can't reference it anymore. I've discussed fixes for this issue in depth in this article, but it all boils down to the fact that when the object is removed from the stage the variable that contained the instance the first time will go to null, and then when you go back to the frame with the instance on it, the variable will be populated with an instance which is probably not the same as the first one.
If the problem is what Ned Murphy speculated, you can easily fix it by setting mouseChildren to false on the buttons.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more