Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Buttons changing colour of objects

New Here ,
May 24, 2015 May 24, 2015

Im using AS3 but dont know the code for when press button the object changes to the selected colour.

I have 5 colour buttons.

TOPICS
ActionScript
503
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2015 May 24, 2015

What kinds of objects are you trying to change the color of?  If they are movieclips then you could have the different colors on different frames and change them by moving to the different frames.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

object.png i want to change this in different colours

i have the code but when colour changes image looks like this

Screen Shot 2015-05-25 at 12.18.56 pm.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2015 May 24, 2015

If you are trying to change the color of an image like you show I have never done it myself but I believe you need to have different images for each color.  Otherwise when you try to transform the color you get what you got... it changes all colors in the object to the single color you specify.

If it is possible to add just a tint change to an image using code but maintain the shading of different areas/colors I am definitely not knowledgeable in such techniques.  You might be able to have copies of the same image and perform such tinting manually to get the effect, but I think you want to get the true color if this is for some sales effort where people are expecting the color they choose to be the color they receive.  Get a shot of six of the actual differently colored ones together and let the color selection be a checkbox next to a color  swatch.

Let Rob help you in any case - he likely knows more about this than I do.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2015 May 24, 2015

Here's a thread on using the ColorTransform object to change colors. Is this the sort of thing that you have in mind?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

I used the colour tranform but the whole image gets coloured in.

Is it possible that when a button is pressed a new image of the product in that colour pops up???. for example

simple.b-cssdisabled-png.h36a9b4535a39aee1a05b4dd18517f6d1.pack.pngif the pink button is chosen this will change

simple.b-cssdisabled-png.hf9a9420bd4d850020f166c509e1d8c67.pack.pngif green button pressed this will come up

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2015 May 25, 2015

There are a bunch of options to get what you want. You didn't show the code that you used for the ColorTransform so I can't comment on that. There is an alphaMultiplier property for the ColorTransform. It ranges from 0 to 1. 0 is fully transparent and 1 is fully opaque. Start with a .5 and see how you like that.

A second option is to break up your illustration of the wrist band into parts. Then you can apply the ColorTransform to only the parts that should change color.

The third option is to use Ned's method and render one band in each color. Put each of those into a keyframe in a movieClip. Then move from frame to frame to show each of the color options.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2015 May 25, 2015

The code I have used is below. When i click on a button colour the image changes which is good but if i click on the button twice, then the image changes to all different colours.

stop ()

black_btn.addEventListener(MouseEvent.CLICK, changeColor);

blue_btn.addEventListener(MouseEvent.CLICK, changeColor);

pink_btn.addEventListener(MouseEvent.CLICK, changeColor);

red_btn.addEventListener(MouseEvent.CLICK, changeColor);

mint_btn.addEventListener(MouseEvent.CLICK, changeColor);

orange_btn.addEventListener(MouseEvent.CLICK, changeColor);

function changeColor (event :MouseEvent) {

  if (this.currentFrame == this.totalFrames) {

  gotoAndStop (1);

  }

  else{

  nextFrame ();

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2015 May 25, 2015

Without seeing the actual movie file, I can only guess at the source of the problem. It looks like the target of the changeColor function is ambiguous. Instead of using "this", try using the actual name of the movieClip that contains the frames with the differently colored bands.

It's also hard to tell what is meant to gotoAndStop(1)  or nextFrame().

Maybe you want the function to look more like this:

function changeColor (event :MouseEvent) {

  if (bandsClip.currentFrame == bandsClip.totalFrames) {

  bandsClip.gotoAndStop (1);

  }

  else{

  bandsClip.nextFrame ();

  }

}

where bansClip is the name of the movieClip that contains all of the various wristband color options.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2015 May 25, 2015

i havent made the image a movie clip

Screen Shot 2015-05-26 at 10.56.07 am.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2015 May 26, 2015
LATEST

I think what you mean is that you are not getting to the color of the band that corresponds to the color of the button. The code that you wrote will just move the playback head to the next frame regardless of the color of that button or the color of the band.

One way to fix this is to add frame markers to each frame. Then use each button to jump to the frame that corresponds to that button's color.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines