First of all (and a private advice from me) is you do this kind of programming in Actionscript 3.0, taking into account the practicality in the treatment of on-screen clicks, since AS3 is event-oriented, and possibly you will be more familiar.
Following the logic of video in question, I have prepared a simple class, which performs both operations, both fills with solid colors GraphicsSolidFill
like bitmap textures GraphicsBitmapFill
.
Understanding the filling of objects
Every and every drawing you perform with fillers, has an object called Shape
(ref.). In this object, a property called graphics
(ref.) controls the shapes and lines of your "drawing", which means you can change any property of your object.
This drawing is nothing more than an image in Vector Drawing. Which means that the measurement is not in Pixels, but in Mathematical Coordinates. Ref.
We will use exactly this object to handle all modifications of our movieclips.
Answering the question
- Draw a picture on stage and each part of your drawing converts it into one
MovieClip
. (Just like in the video. It is important to instantiate them. Ex.: braco_mc, perna_mc, cabeca_mc... 'Supposing it is a doll.')
We will create our function, we will call it fillTo();
who receives a MovieClip
and an object, whether Bitmap
or hexadecimal color uint
:
var colortransform:ColorTransform = new ColorTransform(); //Criamos o objeto que aplica a transformação de cores no nosso desenho;
var shapeGD:Vector.<IGraphicsData>; //Objeto vetor que contém os dados da nossa imagem
var newGD:Vector.<IGraphicsData>; //Irá contém os novos dados do nosso desenho
function fillTo(mc:MovieClip, obj:*):void {
var shape:Shape = (mc.getChildAt(0) as Shape); //Recupera o desenho dentro do movieclip
shapeGD = shape.graphics.readGraphicsData(); //Recupera os dados do nosso objeto Shape (curvas e linhas)
newGD = new Vector.<IGraphicsData>;
//Para cada objeto dentro do nossos objeto vetor, recuperamos apenas a propriedades de linhas e curvas, deixando de lado as de preenchimento
shapeGD.forEach(function(it:*, i:int, vec:Vector.<IGraphicsData>):void {
if(!(it is GraphicsBitmapFill) && !(it is GraphicsGradientFill) && !(it is GraphicsSolidFill)) {
newGD.push(it); //Adicionar somente as propriedades citadas
}
});
//Verificamos se a propriedade passada é um Bitmap ou cor hexadecimao uint
if(obj is Bitmap) {
//Recupera o bitmap (no caso a textura)
var bitmapData:BitmapData = (obj as Bitmap).bitmapData;
//Objeto responsável por adicionar o preenchimento em bitmap ao nosso desenho
var graphicsbitmap:GraphicsBitmapFill = new GraphicsBitmapFill(bitmapData);
newGD.push(graphicsbitmap); //Puxa este objeto para nosso vetor
//Adiciona as novas propriedades ao nosso desenho
shape.graphics.beginBitmapFill(bitmapData, null, true, true);
shape.graphics.drawGraphicsData(newGD);
}
else if(obj is uint) {
//O procedimento é o mesmo, mas o objeto é diferente
//aplicamos apenas a cor sólida ao nosso objeto
var graphicscolor:GraphicsSolidFill = new GraphicsSolidFill(obj);
newGD.push(graphicscolor);
shape.graphics.beginFill(obj);
shape.graphics.drawGraphicsData(newGD);
}
}
To carry out the filling to our movieclips, you just call the function so:
fillTo(perna_mc, 0xFF0000); //Pintando a perna de vermelho
fillTo(perna_mc, textura_bitmap); //Pintando a perna com a textura em bitmap
I took a class called Filler, to simplify the tutorial.
Hello Dexter, Perhaps another approach that can be done is to add to the object (I believe a movieclip) an object (movieclip) inside it, this object can have the size of the screen, so there will be no need to put more than one or to redeem. One way to think is to have a variable that stores the value of the palette (Which color or texture selected) this value can be a reference to a movieclip. When the release event is activated it uses this variable and adds the object referred to it as the only child in the way it wants to paint, for example the elephant’s trunk.
– ooredroxoo
This should give you the desired effect, and can be done using programming, however objects must exist in your library so they can be referenced in AS.
– ooredroxoo
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#beginBitmapFill()
– bfavaretto
No guesswork asked, but for the "good of the web" would suggest you go to the universe of HTML, SVG, JS and CSS to do this (or use some more robust technology if it is for desktop)because Flash is becoming more and more inconvenient with its security flaws and constant updates (and now with the attempts to push a browser along with the installation), and is no longer "light" as it was before.
– Bacco