Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Button Color by variable

Status
Not open for further replies.

tomhughes

Vendor
Aug 8, 2001
233
US
Is it possible to change the color of a button depending on the value of a variable ? If so does anyone have a simple example of code ?
 
the button object itself does not have a color property but if you converted the button to a movieclip and inside the on release function
have a switch statement (if there are more than a couple of variables) and add this to the case statement
myColor = new Color(mybuttonClip);
myColor.setRGB(0xff9933);//alter to suit

this ought to work but post again if it dont.
 
I'll have to use a cover over the button and change the alpha property then, since the buttons must remain buttons.
 
I tried this code, but it is not changeing the alpha propery to 100. "Microbiology Button Cover" is a movie clip.
It is origonally set to 50% alpha, but when the movie plays I am trying to get it to change to 100%.


ifFrameLoaded (1) {
setProperty ("_self.Microbiology Button Cover", _alpha, 100);
}
 
the buttons will remain as buttons even after converting them to a movie clip as long as you are using mx as in mx a movie clip can act as a button

to change alpha

microbiologtbuttoncolor._alpha=100;

if you want to post the fla ill try to fix it. as i understand it you want the button color to be dependant on a variable value.
 
I can't post the fla. I am using Flash 5. Here is the code I am presently trying:

ifFrameLoaded (1) {
Microbiology_Button_Cover._alpha = 100;
}
 
I'm exactly sure what you want, but I tried something, and it worked perfectly. Here is what I did, if it is what you are looking for, duplicate it.

I created a button and named it button. Then, I put an instance of that button on the main timeline. I then converted that button to a MC called button1. For the MC actionscript, I typed in:
Code:
onClipEvent (load) {
  ifFrameLoaded(1) {
    this._alpha = 50;
   }
}
When I tested the movie, the button's alpha was 50%, and the MC had the properties of a button.
 
FlashMax - When you convert the button to a movie clip you cannot use the button properties "on (release)"

Here is the error I am getting

"Mouse events are permitted only for button instances
on (release)"

Any ideas???
 
Ok, you need to create a button, in my example it will be named low1. Now create a MC. This MC will be what you final button looks like. Make the MC look exactly like the button, because you are going to be putting these together. I named my MC low. Put an instance of your MC on the main timeline. I added 30 frames to my timeline to test it out, which is what you might want to do. On the 30th frame, I added a key frame and put in a new layer and added a straight horizontal line. This way, I know if my imbedded button does what I ask it to.

Now double click on the MC low to edit it. Create a new layer below the current layer. On this new layer add your button, low1. Make sure to hide the MC layer so that you can work with the button. In the action of the button, type in:
Code:
on (press) {
   _root.move = true;
}

Unhide the MC layer, and go back to the main timeline. Now add actions to the MC low. Type this:
Code:
onClipEvent (load) {
   _root.move = false;
   this._alpha = 50;
}

onClipEvent (enterFrame) {
   if (_root.move) {
      gotoAndStop(30);
   }
}
Of course you will change the numbers and actions, but this is the form that you use to get the effect you are looking for. Try this one out to make sure that it works for you. It did for me. If you need any more help, just ask. If you need further explanation on what I did, I can give that as well.
 
FlashMax - This is getting much too complex - My buttons are actually text, and they are subject to change. Right now I have about 30 different buttons, some are located in various frames. These buttons will increase as this project continues.
I am working on a button cover which is the same color as the background, and trying to change its alpha properties according to a variable. If I can put the cover(which is a movie clip)in the button, it would make things go much smoother, however I cannot get the MC in the button to read the variable and change its alpha properties. Here is the code I am using to change the alpha of the Button Cover(MC)


onClipEvent (load) {
if (strVar3 == "Facilities Design") {
this._alpha = 50;
} else {
this._alpha = 0;
}
}


I can get this code to work in te main timeline, but not in the button.


I referenced the variable in the MC with the following:
_Level0.strVar3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top