-
[RESOLVED] Help - removing dynamically named instances.
Hi, I'm hoping to get some help here, it seems it should be something simple but I'm having a really hard time trying to solve this one on my own!
I have a movieclip symbol named "item" and nested inside of "item" I have a button with an instance name of "deleteMe". I add an instance of "item" manually from the library and manually name it "item0". The "deleteMe" button on(release) uses the removeMovieClip(_root.item0) method to remove the movieclip instance from the stage. As it is now everything works as it want: I press the "deleteMe" button the "item" movieclip is removed from the stage.
Now my problem comes when I dynamically attach and dynamically name "item" instances. I made a button that attaches "item" instances to the stage one at a time, each instance is named using an increment counter. So each time I press the button it adds an instance named item0, item1, item2, item3 etc. So I have a bunch of instances on stage with names and each one has a "deleteMe" button nested inside. So my removeMovieClip() method on the "deleteMe" button won't work anymore because I have no idea what path/argument/expression to give to the removeMovieClip() method. I've tried using: removeMovieClip(_root._parent) and removeMovieClip(this._parent) but that doesn't seem to work.
I hope I'm explaining this clearly! Any help would be appreciated!
-
Originally Posted by Stoneebro
Hi, I'm hoping to get some help here, it seems it should be something simple but I'm having a really hard time trying to solve this one on my own!
I have a movieclip symbol named "item" and nested inside of "item" I have a button with an instance name of "deleteMe". I add an instance of "item" manually from the library and manually name it "item0". The "deleteMe" button on(release) uses the removeMovieClip(_root.item0) method to remove the movieclip instance from the stage. As it is now everything works as it want: I press the "deleteMe" button the "item" movieclip is removed from the stage.
Now my problem comes when I dynamically attach and dynamically name "item" instances. I made a button that attaches "item" instances to the stage one at a time, each instance is named using an increment counter. So each time I press the button it adds an instance named item0, item1, item2, item3 etc. So I have a bunch of instances on stage with names and each one has a "deleteMe" button nested inside. So my removeMovieClip() method on the "deleteMe" button won't work anymore because I have no idea what path/argument/expression to give to the removeMovieClip() method. I've tried using: removeMovieClip(_root._parent) and removeMovieClip(this._parent) but that doesn't seem to work.
I hope I'm explaining this clearly! Any help would be appreciated!
Hello,
If I understood what you have described above correctly, then just paste the following code in the button that lies inside the mc: item and it should work.
PHP Code:
on (release) {
_root[this._name].removeMovieClip();
}
-
Originally Posted by Dr_flash
Hello,
If I understood what you have described above correctly, then just paste the following code in the button that lies inside the mc: item and it should work.
PHP Code:
on (release) {
_root[this._name].removeMovieClip();
}
Hey, thank you for the quick reply!
I tried your code and though it seems like it should work, still nothing happening when I click the button inside the item mc!
Thanks again...any other ideas are welcome!!
-
Your code works after all!!! Thank you!! The reason it wasn't working when I tried it the first time (in case anyone else has this problem) was that I was using getNextHighestDepth when attaching a the movie clips, I changed this to a simple increment counter instead to create each movie on it's own level. So getNextHighest Depth and removeMovieClip() do not work together!! Thank you again, I spent a lot of time messing around with this!
-
Originally Posted by Stoneebro
So getNextHighest Depth and removeMovieClip() do not work together!!
The (removeMovieClip() and getNextHighestDepth() ) works together, no problem at all. You are probably using a built-in Button. If you use the Button component that comes with Flash, then the (getNextHighestDepth() ) won't work.
It was a good idea that you used a variable that increases each time a new mc attached if you still wanted to use the built-in Button.
Other method is to create a button yourself, then you can still use the (getNextHighestDepth() ).
Good luck!
Last edited by Dr_flash; 02-11-2016 at 12:25 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|