[Extendflash] converting fill color to tint

Erik Bianchi erik at erikbianchi.com
Fri Aug 5 15:54:03 PDT 2005


Hey Morten,

Thanks for the info! I didn't want to wait so I had to figure out my own
solution.

function setTint()
{
	
	var e;
	var fill;
	
	var layers = fl.getDocumentDOM().getTimeline().layers.length;
	
	for(var i = 0; i < layers; i++){
		
		fl.getDocumentDOM().getTimeline().setSelectedLayers(i);
		fl.getDocumentDOM().getTimeline().setSelectedFrames(0, 0);
		
		fill = fl.getDocumentDOM().getCustomFill("selection");
		fl.getDocumentDOM().convertToSymbol("movie clip",
"color_"+i, "center");
		fl.getDocumentDOM().setInstanceTint(fill.color,100);
	}
	
}

this.setTint();

This one assumes that all the shapes that I want to convert are on their own
layer. Also, I didn't take into account blank layers or layers with
movieclips on them so the functionality is somewhat limited. =)

The magic function I was really after all along was setInstanceTint.

Is it me or is working with JSFL a lot harder then it should be?

-erik


this.setTint();

-----Original Message-----
From: extendflash-bounces at flashguru.co.uk
[mailto:extendflash-bounces at flashguru.co.uk] On Behalf Of Morten Barklund
Shockwaved
Sent: Friday, August 05, 2005 2:36 PM
To: Extending Flash
Subject: Re: [Extendflash] converting fill color to tint

> How can I convert a fill hexadecimal color to color transform data?
> 
> I'm trying to iterate through about 700 movieclips and change their
> movieclips tint to equal the movieclips fill color.

Hi Erik,

I've made a little script, which does what you say.

It asumes a lot of things. First of all, all your elements are placed in 
frame 1 of layer 1 of scene 1. Second of all, all your movieclips 
contain only a simple shape (without any outline or anything) which is 
placed within the movieclip in frame 1 of layer 1.

If that is so, the following should work:

var dom = fl.getDocumentDOM();
var elements = dom.getTimeline().layers[0].frames[0].elements;
var i, e, c;
for (i = 0; i < elements.length; i++) {
	e = elements[i];
	if (e.elementType == "instance") {
		dom.library.editItem(e.libraryItem.name);
		dom.selectAll();
		c = parseInt(dom.getCustomFill().color.slice(2,-1),16);
		dom.editScene(0);
		e.colorRedAmount = (c & 0xFF0000) >> 16;
		e.colorGreenAmount = (c & 0xFF00) >> 8;
		e.colorBlueAmount = (c & 0xFF);
		e.colorRedPercent = 0;
		e.colorGreenPercent = 0;
		e.colorBluePercent = 0;
	}
}

Well, it isn't nice, but it's quite simple :)

Hope that helps you on the way.

-- 
Morten Barklund - Information Architect - Shockwaved ApS
Larsbjoernsstraede 8 - DK-1454 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
_______________________________________________
Extendflash mailing list
Extendflash at flashguru.co.uk
http://lists.flashguru.co.uk/mailman/listinfo/extendflash



More information about the Extendflash mailing list