Using Communication Components > Using your component with the UserColor component

 

Using your component with the UserColor component

If you write a component and want it to work with the UserColor component, make sure to take the following steps to monitor color change:

1

Provide an onColorChange method, such as the one shown here:

MyComponentClass.prototype.onColorChange = function()
{
	this.setColor(gFlashCom.userprefs.color);
}

The gFlashCom.userprefs global object gets updated by the FCUserColor component with the new color.

The this.setColor method of the component deals with the change in color. It's good practice to split the logic between the onColorChange and setColor methods so you can use setColor even if you don't use the UserColor component, which triggers onColorChange.

2

Add your component class to the list of listeners for changes to the userprefs object (that includes color). After the #endinitclip statement of your component class, type the following code:

gFlashCom.userprefs.addListener(this);

These steps ensure that your onColorChange method is called whenever you use FCUserColor to change color.