View Full Version : Actionscript color change
Fungfu
03-09-2005, 06:04 PM
Hi, I'm kind of embarrassed to ask this because it's probably laughably easy, but hey I can't do it and I need help before my family have to book me into a home for the bewildered.
Basically I have a grey menu button, when you mouse over it I want it to turn red when you click on it I want it to turn green and stay that way until a different menu button is clicked. Now I can do that just fine with the easy button state method, but I want to learn something and do it using actionscripts. Can anyone help me please?
Cheers.
CyanBlue
03-09-2005, 06:59 PM
Howdy and Welcome... :)
This is how I'd do it...
theDepth = 10000;
menuText_arr = new Array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5");
colorOver = 0x0000FF;
colorReg = 0xCCCCCC;
topX = 50;
topY = 35;
for (var i = 0 ; i < 5 ; i++)
{
this.attachMovie("MC_Menu", "menu" + i + "_mc", theDepth++, {_x:topX, _y:topY + 21 * i});
this["menu" + i + "_mc"].menu_txt.text = menuText_arr[i];
this["menu" + i + "_mc"].id = i;
this["menu" + i + "_mc"].onRollOver = function ()
{
var bgColor = new Color(this.bg_mc);
bgColor.setRGB(colorOver);
}
this["menu" + i + "_mc"].onRollOut = function ()
{
var bgColor = new Color(this.bg_mc);
bgColor.setRGB(colorReg);
}
this["menu" + i + "_mc"].onPress = function ()
{
_level0.output_txt.text = "Menu " + this.id + " is selected...";
}
}
Fungfu
03-09-2005, 07:44 PM
Thanks for your reply but it's not quite what I'm after.
In the attached file menu.zip you can see that I've managed, however haphazardly, to make the buttons turn green on press but when you click one of the other menu buttons it stays green instead of returning to it's original color #666666.
????????
CyanBlue
03-09-2005, 07:55 PM
What about this???
createMenu();
function createMenu()
{
theDepth = 10000;
menuText_arr = new Array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5");
colorOver = 0x0000FF;
colorPress = 0x00FF00;
colorReg = 0xCCCCCC;
topX = 50;
topY = 35;
for (var i = 0 ; i < 5 ; i++)
{
this.attachMovie("MC_Menu", "menu" + i + "_mc", theDepth++, {_x:topX, _y:topY + 21 * i});
this["menu" + i + "_mc"].menu_txt.text = menuText_arr[i];
this["menu" + i + "_mc"].id = i;
this["menu" + i + "_mc"].onRollOver = function ()
{
if (!this.selected)
{
var bgColor = new Color(this.bg_mc);
bgColor.setRGB(colorOver);
}
}
this["menu" + i + "_mc"].onRollOut = function ()
{
if (!this.selected)
{
var bgColor = new Color(this.bg_mc);
bgColor.setRGB(colorReg);
}
}
this["menu" + i + "_mc"].onPress = function ()
{
if (!this.selected)
{
trace("!!!");
unselectMenu();
this.selected = true;
var bgColor = new Color(this.bg_mc);
bgColor.setRGB(colorPress);
_level0.output_txt.text = "Menu " + this.id + " is selected...";
}
}
}
}
function unselectMenu()
{
for (var i = 0 ; i < 5 ; i++)
{
this["menu" + i + "_mc"].selected = false;
var bgColor = new Color(this["menu" + i + "_mc"].bg_mc);
bgColor.setRGB(colorReg);
}
}
Fungfu
03-09-2005, 09:03 PM
Oh I see, I've got it now. You're a star, thank you so much, you've made me the happiest girl in christendom.
Cheers.
CyanBlue
03-09-2005, 11:12 PM
Hm... Christendom??? Where/what is that??? :)
Fungfu
03-09-2005, 11:56 PM
Nope, I celebrated too early, I don't get it. I think it uses the under nourished side of my brain. Am I making things more difficult for myself by trying to apply it to five MC menu items? I've looked every where for an example of this and found many that where close to what I was after but none that really got it.
I'm really close to chucking in the towel and doing it the kids way.
Any last minute suggestions?
hi
put this on your buttons (change what you have jet)
change of course _root.home to thew corect name
on (press) {
var colorful = new Color(_root.Curent);
colorful.setRGB(0x777777);
_root.Curent = _root.home;
var colorful = new Color(_root.home);
colorful.setRGB(0x00CC00);
}
on (release) {
gotoAndPlay("Home");
}
on (rollOver) {
var colorful = new Color(_root.home);
colorful.setRGB(0xFF0000);
}
on (rollOut) {
if (_root.Curent<>_root.home) {
var colorful = new Color(_root.home);
colorful.setRGB(0x777777);
}
}
the button states will NOT work if you use setRGB because the hole button will turn to the color so up,over,down,hit will have all the same color which was set
BY MM
Constructor for the Color class
Availability
Flash Player 5.
Usage
new Color(target_mc:Object) : Color
realy wounder me that it's working whit a STRING :p
BY CB Hm... Christendom??? Where/what is that???
BY Xeef Hm... Christendom??? Where/what is that???
Fungfu
03-10-2005, 09:19 AM
Yay! It works thanks Xeef and thankyou CyanBlue for all your help too.
I was just messing about using the word Christendom - *but here is it's correct meaning.
Pronunciation (krsn-dm)
Christians considered as a group.
The Christian world.
n : the collective body of Christians throughout the world and history (found predominantly in Europe and the Americas and Australia); "for a thousand years the Roman Catholic Church was the principal church of Christendom" [syn: Christendom, Christianity]
Fungfu
03-10-2005, 09:25 AM
Also, I'd like to pick up a book and learn about actionscripts, I've just had a look on Amazon and there are 59 to choice from. Can anyone recommend one in particular to me, nothing too complicated though.
Cheers.
nomaeswonk
08-02-2005, 04:53 PM
That's a nice little dynamic color menu, but what if you are pulling the hex values from XML. The variables are considered strings not numbers...and when you convert them to a Number, their values get all screwed up.
Is there a way to preserve the values or a better way to pull the hex values from XML?
a = "0xFFFFFF";
trace(Number(a));
trace(0xFFFFFF);
//in case you have it like : #FFFFFF
a = "#FFFFFF";
a = a.substr(1);
trace(Number("0x"+a));
Well, that's good for you('fungfu') for are able to pick up from the above actionscript. But, my brain looses it's nuts whenever it sees such long scripts. Well, I meant to say that I believe that you can do it either the hard way or the easier way.
I can do what you want to achieve in a simpler way. By making the buttons not from one 'Button' symbol, but instead a group of buttons in a 'Movie Clip' symbol. You can create the menu in a movie clip. Say the first instance of button as normal button with all it's normal sequence(on normal it appears grey, on mouseover turns red and when anyone clicks turns green). And, when someone clicks and release the button, it will actually take you to a different keyframe, where the particular button stays as you were intend to. This can made by actually replacing the button with a static button-like green symbol.
The movie clip stays at this mode unless a user clicks on a different button in the menu which will initiate the same action to that button.
Got it!! As simple as it gets!!
Of course now you have the options to choose. For those like me and having same type of question like 'fungfu' try my suggestion. Actually this was my first question that my interviewer asked me when I used to work as a graphic designer. That was 5 years ago.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.