Creation of a Flash coloring book

Before you start reading this tutorial, there is something you must do.

Turn off the lights, close your eyes, raise your hands, and say:

« Hail, Lord of Flash Game. Shall I read this tutorial and forget it before I try to flood the web with another silly Coloring Book Game »

Really, seriously… I am showing you how do it but please, please… don’t do it.

Finding the right image

If you can’t draw your image, you’ll have to download it from the web. Try to Google for coloring book and you’ll know what I mean.

Just remember the “copyright” word… I don’t think you’re allowed to use Ben 10 or Hello Kitty images… but if you are about to create a Flash coloring book, you are an evil person and stealing artworks won’t be a problem.

The image I’ll use is taken from www.coloringbook.info

Main concept

Every colorable part is a distinct movieclip, and its color is dynamically changed with Actionscript

Converting the image

First, you need to import it into Flash

File->Import->Import to Stage

Then, select the image on the stage, and convert it from bitmap to vector

Modify->Bitmap->Trace Bitmap

with these settings:

Color threshold: 100

Minimum area: 1

Curve fit: Very Smooth

Corner threshold: Few Corners

Now you have your bitmap converted into a Flash shape. Select all the black outline clicking on every black line you see while pressing Shift, then convert it to a symbol

Modify->Convert to Symbol

name it outline and don’t check Export for Actionscript

Now do the same thing with the head…

Then with the remaining body parts and eventually the background. Once the shape has been divided into objects, select all objects on the stage and convert them as a unique symbol you will call teddy_mc.

This time remember to check Export for Actionscript

Now you can delete everything from the stage and remove the image from the library.

Now your library should look like this one:

Now edit teddy_mc movieclip, selecting every movieclip inside it (head, outline, …) and giving it a proper instance name… head for the head, feet for the feet and so on

Obviously tracing a bitmap won’t give the same quality results as if you were able to draw your coloring book by yourself

Finally you are ready to code some interesting lines

Actionscript

The aim of this script is putting on stage the teddy bear, a three color palette, setting a default color, allowing people to change color clicking on the palette, and painting the teddy bear.

package {
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.events.MouseEvent;
	public class coloring extends Sprite {
		public var teddy:teddy_mc = new teddy_mc();
		public var palette:palette_mc;
		public var pal_color:ColorTransform;
		public var colors:Array=new Array(0xFF0000,0x00FF00,0x0000FF);
		public var current_color:int=0;
		public function coloring():void {
			addChild(teddy);
			teddy.addEventListener(MouseEvent.CLICK,on_teddy_click);
			for (var i:int=0; i<3; i++) {
				palette = new palette_mc();
				pal_color=palette.transform.colorTransform;
				pal_color.color=colors[i];
				palette.transform.colorTransform=pal_color;
				palette.x=40+i*60;
				palette.y=300;
				palette.ind=i;
				addChild(palette);
				palette.addEventListener(MouseEvent.CLICK,on_palette_click);
			}
		}
		public function on_palette_click(e:MouseEvent):void {
			var palette_clicked:palette_mc=e.currentTarget as palette_mc;
			current_color=palette_clicked.ind;
		}
		public function on_teddy_click(e:MouseEvent):void {
			for (var i:int = 0; i < teddy.numChildren; i++) {
				if (teddy.getChildAt(i).hitTestPoint(mouseX,mouseY,true)) {
					pal_color=teddy.getChildAt(i).transform.colorTransform;
					pal_color.color=colors[current_color];
					teddy.getChildAt(i).transform.colorTransform=pal_color;
				}
			}
		}
	}
}

Line 3: ColorTransform class lets you adjust the color values in a display object

Line 6: Declaring the teddy bear object

Line 7: Declaring the palette: it's a simple white circle that will be instanced three times in three different colors

Line 8: Variable used to handle color adjustment

Line 9: Array with possible colors... in this case red, green and blue

Line 10: Setting the default color

Line 12: Placing the teddy bear on stage

Line 13: Adding a listener to know when I'm clicking on it

Line 14: Beginning of the loop that will create the three-color palette

Line 15: Creating a new palette object

Lines 16-18: Giving the palette object the i-th color in the colors array

Lines 19-20: Setting the palette position on the stage

Line 21: Giving the palette an index, to easily recognize it

Line 22: Adding the palette on stage

Line 23: Adding a listener to know when I'm clicking on a palette

Lines 26-29: Changing the current color according to the index (see line 21) of the palette I clicked

Line 31: Looping through all teddy's children (the colorable parts)

Line 32: Checking which movieclip I clicked

Lines 33-35 Changing its color in the same way shown at lines 16-18

And this is the result:

Play with colors... as you can see the antialiasing sucks... but you can make it perfect if you draw the image by yourself.

Download the source code.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stairs
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers