"Color" component parameter

I never really understood why when you define a component parameter, you can define its type. Wouldn’t the variable type that the parameter is related to, always define the type of the parameter? Aren’t parameter and variable types synonymous?

Well, it turns out that they are not necessarily.

I’ve never paid much attention to the fact that you can specify the ‘type’ of a parameter in the Inspectable tag, as it was obvious to me that this would be the same as the variable type.

But I’ve discovered at least one case where this is not so.

Attempting to define an Inspectable variable as type ‘fl.motion.Color’ seems to work okay – it invokes the Color Picker in the Component Inspector when you click on the component on the stage. However when in the Component Inspector when you change the color from the default, and run the file, you’ll get:

1067: Implicit coercion of a value of type int to an unrelated type fl.motion:Color.” error.

Obviously Flash expects the parameter of type ‘color’ to be related to a variable of type ‘int’. Seems a little strange but there is a way to get around this apparent conflict between parameter and variable types of ‘color’:

Specify the parameter to be of type ‘Color’ and the variable to be of type ‘int’.

package
{
	import flash.display.MovieClip;
	public class test extends MovieClip {
		private var _color:int;
		[Inspectable (type = "Color")]
		public function get color():int {
			return _color;
		}
		public function set color(value:int):void {
			_color = value;
		}
	}
}

Interactive developer, Author - iOS development with Swift - book coming 2017 https://manning.com/books/ios-development-with-swift

Tagged with: ,
Posted in Flash

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: