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

Color picker in game, used for multiple objects?

Explorer ,
May 24, 2018 May 24, 2018

Hi! I've been struggling all morning on this since there appears to be no easy answer. I'm building a character creator, and I want the user to be able to chose colors of skin tone and clothes color, etc. A search reveals the "easiest" way is to add a color picker. But as I want multiple objects to be changeable, I'm running into trouble.... Plus, I'm not a fan of the drag and drop method, way to messy... I already have a substitute method arranged that allows all customizations to be button selected.

Here is where my problem occurs... The code I found to create the color picker assumes all active movie clips are on the same frame, and possibly layer to the picker. Here is the tutorial I've found: Flash Actionscript 3 Tutorial by pichu90 on DeviantArt

I've adapted their code, and every time, at every arrangement I get errors... My current for is rather simple, from one & two unrelated loader code, frame 3 Button code for selecting body type as follows:

var myGenderArray = [male, female, none];

for each (var Gender in myGenderArray) {

  Gender.addEventListener(MouseEvent.CLICK, onGenderClick);

}

function onGenderClick (event:MouseEvent):void {

  MovieClip(parent).body1.gotoAndStop(event.target.name);

}

The listed values, male, female, none, all comply to a frame table on a movie clip where in the color picker code resides, as well as on buttons that can be clicked to activate those frames. 

On each frame an additional movie clip that is to be the color changing tone sits in line with my line art. They each have an instance name to be called upon.

Here is the code that is my main problem:

import fl.controls.ColorPicker;

import fl.events.ColorPickerEvent;

import flash.geom.ColorTransform;

var SkinFemalecolorInfo:ColorTransform = MovieClip().SkinFemale.transform.colorTransform;

MovieClip().CPer1.addEventListener(ColorPickerEvent.CHANGE, colorChange2);

function colorChange2(event:ColorPickerEvent):void {

MovieClip().SkinFemale.transform.colorTransform = MovieClip().CPer1.selectedColor;

}

This is the code for the female frame, on the male and none frames the "SkinFemale" is SkinMale or SkinNone. As well, CPer1 is the representative of the unique color picker, and there is also CPer2 and CPer3. Finally, functions have unique names, I believe, so the other two are called colorChange1 and colorChange3. You'll notice both SkinFemale & CPer1 have a MovieClip(). infant of them. This is because otherwise they will be undefined by flash as this code is within a movie clip its self. (or some logic to that effect, in my experience this is true please do offer alternate answer I've been looking)

I've messed with this code so much I don't know if it can even be saved.... but I'd greatly appreciate anyone who could solve my mystery.

TOPICS
ActionScript
1.1K
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

correct answers 1 Correct answer

Community Expert , May 27, 2018 May 27, 2018

click file>publish settings>swf and tick 'permit debugging'. retest and the problematic line of code will be referenced in the error message.

what line is triggering the problem?

Translate
Community Expert ,
May 24, 2018 May 24, 2018

all your code that contains MovieClip() is going to trigger an error.

if you have a movieclip that's not recognized by animate as being a movieclip (ie, you're seeing something like: error, implicit coercion of type whatever to type MovieClip), you can explicitly cast it.  eg,

MovieClip(parent)

MovieClip(root)

or maybe MovieClip(SkinFemale)

if you don't understand any of that, just remove MovieClip() from every place you used it.

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, 2018 May 24, 2018

Also remove the leading period. ".SkinFemale.transform.colorTransform" would cause a problem.

Here's the function I usually use for tinting movieclips:

  private function setColor(mc:MovieClip,color:uint){

     var obj_color:ColorTransform = new ColorTransform();

     obj_color.color = color;

     mc.transform.colorTransform = obj_color;

  }

I would have swatches somewhere with the RGB value as a uint (unsigned integer), and call that function with the movieclip I want to tint, and the color to tint to.

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
Explorer ,
May 24, 2018 May 24, 2018

Well... the idea of kglad​'s of putting the movie clip name in the brackets removed all loading errors to make it playable, however... when I loaded the game and clicked the display character button to reveal the frame where the color picker code is, I got a bit of a glitch... its rather hard to describe so I recorded it:

(mild flashing warning)

5-24-02.gif

I am genuinely unsure what steps to take next, I want to be able to change the color completely, If anyone has a complete alternate code and instructions link I could sure use it... Otherwise I'll keep working around this code...

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, 2018 May 24, 2018

That sort of flickering would happen with a movieclip that doesn't have a stop(); in it, or if there is a code error. Look in the Output panel to see if any errors are being reported.

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
Explorer ,
May 25, 2018 May 25, 2018

Okay well, as it turns out it was flickering for both reasons. You see I edited the color picker tool and apparently it lost linkage to a class, "fl.controls.ColorPicker" without the linkage to what is I believe the code I had placed, the movie clip failed to function as a component and just played as a clip. Once fixed, it acted as a true color picker, however I received an out put error.... Here it is as follows:

TypeError: Error #1034: Type Coercion failed: cannot convert fl.controls::ColorPicker@2c16ba1c50c1 to flash.display.MovieClip.

  at _5_24_01_fla::doll_9/frame2()

  at flash.display::MovieClip/gotoAndStop()

  at _5_24_01_fla::MainTimeline/onGenderClick()

I don't understand it... It seems to say it simply, can't change the color of my object? Did I need to convert to bitmap? I was not told to, is there some other altercations to be done to the movie clip that help?

Also for reference "doll" is the movie clip that holds both the color pickers and the go to frames that button summons. Each is a different frame.

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
Community Expert ,
May 26, 2018 May 26, 2018

remove this from wherever it appears:

MovieClip(CPer1)

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
Explorer ,
May 26, 2018 May 26, 2018

Well, in the code It is attached to an "addEventListener" so I'm not sure its okay to totally remove it... so I just changed it to "CPer1" now I receive a different error,

TypeError: Error #1034: Type Coercion failed: cannot convert fl.controls::ColorPicker@3a2a524320c1 to flash.display.MovieClip.

  at _5_24_01_fla::doll_9/colorChange2()

  at flash.events::EventDispatcher/dispatchEventFunction()

  at flash.events::EventDispatcher/dispatchEvent()

  at fl.controls::ColorPicker/onSwatchClick()

Still not sure what to do? I imported the Color Picker from the components tab, and it gave me options for symbol creation, I set it to movie clip... should it have been button or graphic?

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
Explorer ,
May 26, 2018 May 26, 2018

I found another place where I had forgotten to remove MovieClip() from CPer1. My current error is :

error 1067: Implicit coercion of a value of type flash.geom.ColorTransform.

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
Community Expert ,
May 27, 2018 May 27, 2018

click file>publish settings>swf and tick 'permit debugging'. retest and the problematic line of code will be referenced in the error message.

what line is triggering the problem?

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
Explorer ,
May 27, 2018 May 27, 2018

Well I looked at the line that was triggering the error, and it was one I had perviously modified, in an attempt to get it to run better, SO I restored it to its previous form, but with the modifications that had helped it run before. the problem code was here:

function colorChange2(event:ColorPickerEvent):void { 

MovieClip(SkinFemale).transform.colorTransform = CPer1.selectedColor; 

And I changed it to:

function colorChange2(event:ColorPickerEvent):void {

SkinFemalecolorInfo.color = CPer1.selectedColor;

MovieClip(SkinFemale).transform.colorTransform = SkinFemalecolorInfo;

}

And with this the code finally functions! Thank you all for your help!

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
Community Expert ,
May 27, 2018 May 27, 2018
LATEST

you're welcome.

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