This content has been marked as final. Show 18 replies
use the splice() method of arrays to remove your movieclip reference (or instance name) from your array.
You weren't too far off. I just made a few changes to your script. View the comments for more info.
Hope that helps
so....how if I want to add back the deleted one back to array? Let say while the btn0 was deleted, then if I press the 3rd button, btn3 will be deleted, and then btn0 add back to the array.
OK, so it's been awhile since I've played around with arrays to this extreme but I figured it out. What you do is create a temporary array to store the name of the current button that is being clicked. You then remove that button name from the fruit array. When you click on another button, you again store that button's name in the temp array and replace it with the button name that's already in there. Sounds pretty simple - right? Well take a look at the logic involved.
1) Start movie
Fruit array [btn0,btn1,btn2,btn3,btn4] Temp array [empty]
2) Click on btn2
Is this the first button ever clicked on? YES
Store btn2 in Temp array and remove it from Fruit array
Temp array [btn2] Fruit array [btn0,btn1,btn3,btn4]
3) Click on btn0
Is this the first button ever clicked on? NO
a) Store btn0 in Temp array
Temp array [btn2, btn0]
b) Remove it from Fruit array
Fruit array [btn1,btn3,btn4]
c) Replace it with btn2
Fruit array [btn1,btn2,btn3,btn4]
d) Remove btn2 from Temp array
Temp array [btn0]
4) Repeat 2 - 3 for subsequent button clicks.
Anyway - here's the script below that uses the logic above. Hope it helps
thanks for helping.....that's great....one thing that bothers me is, can the name of button that going to be added from the temp array to the current array, the position same with the starting one, or ascending one.
sorry i ask a stupid question
fruit.sort() do the thing.
After i looked into it, I found that if I click on the button few times, there will be duplicate name in the temp array, how can I make it not to store duplicate?
check your array to see if you're going to be adding a duplicate.
the array that I going to use is exactly same with the one I provided here, so if I click few times on the same button, the temp array with add the same button name. And I only hope that the temp only keep the recent one that I clicked. How to do it?
it doesn't make sense to maintain an array that always will contain one element. you should use a variable if you only need to store one value.
but, in general, if you want to maintain an array of fixed length maintaining only the most recently pushed elements of the array, use the shift() method.
what are you trying to accomplish? asking specific questions is great when you know the logic that's needed to accomplish your task. but it doesn't appear that you know what's needed.
so, without distilling what you're trying to do, explain what should happen if btn0, btn3, btn2 are pressed in that order. use more buttons if that isn't enough to display the pattern.
I'm trying to make a list of button, when the mouse roll over them, each of them will change color, when roll out, the color reset. So if the button clicked, the button change color again and it will be reset to the default color if another button is clicked. Maybe the method I'm trying to do in this in wrong, am I?
Well - now that we know what you want, then the following script will help you get there. In order for it to work though your buttons(btn1,btn2,etc) must be movieclip symbols. Inside each button you will need to have a movieclip symbol with the instance name of 'bkg'. This is the actual object that changes color and can be whatever you like.
You can view my example here and download it to see how it was done.
i know you're trying to help noel, but you're over-complicating this and causing confusion.
the following is all that's needed:
remove the quotes in btnA. those are instance names, not strings.
and use btnA.length in the for-loop.
Thanks for the heads up kglad! Yeah my way was way too long. Thats what I like about these forums is that someone will post script that solves a solution another way. Or I should say - an easier way! It's a learning lesson for all levels of Flash users. Good stuff!
Hopefully now, rockylhc has solved his problem.