PDA

View Full Version : Manipulating color and [Inspectable] private var


xxlm
11-12-2003, 09:53 PM
Hello everybody.
Such a long time I don't come on the board. :-/

Ok, here is my problem:

I want to manipulate color dynamically.
Actually I want to make a component and want the user be able to set the background color.


How can I do this?

I tried several way, but with no success.


class test {
[Inspectable] private var backgroundColor:Color;
private var _backgroundColor:Color;

private function test () {
_backgroundColor = new Color(this);
_backgroundColor.setRGB(backgroundColor.getRGB().t oString());
}
}


this is the class attached to my component. The problem is that I can't setRGB cause I am not able to have the CORRECT TYPE FOR MY VALUE (here backgroundColor.getRGB().toString()).


**Error** C:\__DEVELOPPEMENT__\__FLASHCLASS__\test.as: Line 7: Type mismatch.
_backgroundColor.setRGB(backgroundColor.getRGB().t oString());


Please help....


But if you create a new fla and put 2 mc on it
then do:
[as
_backgroudOne = new Color(mc1);
_backgroundTwo = new Color(mc2);
_backgroundOne.setRGB(0xFF0000);
_backgroundTwo.setRGB(_backgroundOne.getRGB().toSt ring());
[/as]
It's working.... So... what the hell... I'm sure it's cause of the strict type of varibale. Here flash should put the result of _backgroundOne.getRGB().toString() in a correct type. But then with strict var type, wich type is it?

xxlm
11-12-2003, 10:51 PM
OK i just get it...

class test {
[Inspectable (type=Color, defaultValue="#ff0000")] private var AbackgroundColor:String;
private var _backgroundColor:Color;

private function test () {
_backgroundColor = new Color(this);
_backgroundColor.setRGB(Number(AbackgroundColor));
}
}


Ok in the Inspectable you have the metatag type. I put type=Color then I have a colorpicker and store my value(string) in my var of type String. The default value is the string ("#FF0000" which is red).

So here it is the working fla --> a color picker for background (and whatelse).

mlegris
08-22-2005, 08:25 PM
goes like this :


// at class definition level :
private var _borderColor:Number = 0x6A645B;


// with other properties
[Inspectable(defaultValue="#6A645B",type=Color)]
public function get borderColor():Number
{
return _borderColor;
}

public function set borderColor(borderColor:Number):Void
{
_borderColor = borderColor;
}


It seems odd, but it's the cleanest way i've found. And it is very nice to be able to use the color pickers when manipulating components properties.

Martin.