View Full Version : Selecting Items
Stevai0
January 15th, 2008, 10:25 PM
Hay,
Situration: Items, when you click them they highlight. (boxes for example)This is abit like radio buttons.
Problem: But when another item is clicked, how do I unhighlight all the other items?
I havent used flash in awhile and would love to get back into it... got CS3 :P
Thanks guys,
this.lex;
Marz
January 15th, 2008, 10:48 PM
Well. There are multiple ways you can handle this. Lemme give you a quick example. After you click the button and it highlights, you want it to check to see if any other buttons are highlighted.
So, when you click a button, set a variable. - buttonHighlight = number; If that number = 0 then it isn't highlighted, if it isn't a 0 then another button is highlighted and you could even put the reference number in that spot to show which one was highlighted before it and you could un-highlight it.
Of course, you could always set up a variable that stores all of the highLight values of all of your linked buttons and then do a simple array sweep test to unhighlight every single one and then highlight the one you just clicked.
Stevai0
January 15th, 2008, 10:56 PM
Thanks, How do I sweep through the array?
I do alot of PHP, MySQL stuff... i would use foreach()...
Can you please give me an example?
Need to learn the basics again lol
Lex
Marz
January 15th, 2008, 11:17 PM
I would love to give you an example but currently I am on my Server Computer which only has everything basic running on it! *lol* I'm also with you on the PHP and MySQLi() stuff. I find it extremely useful and so much more beneficial over ASP.
But anyways, You can use a for loop or you can use a for each loop or you can even use a while loop. It really depends on what you are use to using. In the loop just have the array check for the specific data type (make it easy 0's and 1's) and then just reset the one that's actually clicked.
Stevai0
January 15th, 2008, 11:58 PM
Ah ok, I think i can make something :)
Thanks
Edit: mmm having trouble with this lol
Marz
January 16th, 2008, 12:29 AM
How much trouble? It's not allowing you to highlight at all kind of trouble or other type of trouble?
Charleh
January 16th, 2008, 08:16 AM
Add your buttons/objects to an array, then loop through the array after you've clicked and unhighlight all the ones that weren't clicked
i.e.
At the start of your code
var buttonsArray:Array = new Array(button1, button2, button3, button4, etc);
Create a function to handle the highlight
HighlightButtonInGroup(btn:Object, group:Array) {
for(var i = 0; i < group.length; i++) {
if(group[i] == btn) {
group[i].highlighted = true;
} else {
group[i].highlighted = false;
}
}
}
Now in your click code for the button instance call the function passing in the button and array instances
HighlightButtonInGroup(this, _root.buttonArray);
neilmmm
January 16th, 2008, 11:52 AM
Charleh knows loads more than me - but for what it is worth i would just use a couple of variables
var select:MovieClip;
var oldSelect:MovieClip;
function highLight () {
oldSelect=select;
select=this;
select.gotoAndStop(5);
oldSelect.gotoAndStop(1);
}
mc1_mc.onRelease=mc2_mc.onRelease=mc3_mc.onRelease =mc4_mc.onRelease=highLight;
Stevai0
January 16th, 2008, 06:39 PM
Thanks guys, I got it working :)
The code was not quiet right, fixed it with your help...
Some of this stuff is coming back to me now! ty
Cheers,
Lex
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.