开发者

Dynamically load and change graphics

I would like to do something like this:

The flash project loads any vector graphic object from hard disc (that graphic has only two color), change one color (for ex #ff开发者_JAVA技巧0000) to an other (for ex #00ff00) and display.

Is it possible?

If it is, what is the file format of this graphic object?


If you want to load vector graphics, the easiest, natively supported way in Flash is to load a SWF file. That SWF file can either have graphics in the root display list (in which case you can simply add the loaded SWF, which will come in as a MovieClip, to your display list) or it can define symbols that are linked to class names. In the latter case, you can get the class definitions using getDefinitionByName() and then instantiate that class.

// After having loaded a SWF with class definition "MySymbol"
var symbolClass : Class = getDefinitionByName("MySymbol") as Class;
var symbol : Sprite = new symbolClass();

As for the color transformation, you might be able to do it using the ColorTransform or ColorMatrixFilter classes, depending on the similarity of the two colors. Otherwise, the easiest way if you're sticking with the SWF-loading method would be to simply separate the two parts of your graphic into two separate layers/display objects when you generate the SWF file (e.g. in Flash Professional) and then access them and transform them separately.

var symbol : MovieClip = new symbolClass;
symbol.part1.transform.colorTransform = 
                        new ColorTransform(0, 0, 0, 1, 255, 0, 0);

This code will access the child of the MySymbol MovieClip with instance name part1 and change it's color to red. For more information on ColorTransform, see the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜