Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 2 of 2

Thread: Coloring regions of images

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Coloring regions of images

    flash templates

    In this tutorial we see how to color the sections of an image using the method floodFill() of the BitmapData class of Actionscript 3.0.

    This method works almost like magic wand tool in Photoshop (or other photo editor) with a setting of zero tolerance.

    It fills in all contiguous regions of the same pixel color with the specified color.


    This method allows us to create such an application of coloring and much more.


    The example that I created works with an external black and white GIF image.

    The image has been loaded into Flash and with a ColorPicker component, check the color you will use to fill in certain areas of the image.


    For example, choose a color and click to image's area.









    Actionscript


    Code:
    package
    {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.net.*;
    	import flash.geom.*;
    	
    	public class Main extends MovieClip
    	{
    		private var bitmap:Bitmap;
    		private var bitmapdata:BitmapData;
    		
    		private var holder_mc:MovieClip;
    		
    		private var current_color:uint=0;
    		
    		public function Main()
    		{
    			addEventListener(Event.ADDED_TO_STAGE,init);
    		}
    		
    		private function init(evt:Event):void
    		{
    			removeEventListener(Event.ADDED_TO_STAGE,init);
    			
    			reset_btn.label="RESET";
    			
    			loadImage();
    		}
    		
    		private function loadImage():void
    		{
    			if(holder_mc!=null)
    			{
    				removeChild(holder_mc);
    				bitmapdata.dispose();
    				bitmap=null;
    				holder_mc=null;
    			}
    			var request:URLRequest=new URLRequest("jerry.gif");
    			var loader:Loader=new Loader();
    			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onImageLoaded);
    			loader.load(request);
    		}
    		
    		private function onImageLoaded(evt:Event):void
    		{
    			bitmap=evt.target.loader.content as Bitmap;
    			bitmapdata=bitmap.bitmapData;
    			holder_mc=new MovieClip();
    			holder_mc.addChild(bitmap);
    			addChild(holder_mc);
    			
    			addListeners();
    		}
    		
    		private function addListeners():void
    		{
    			color_picker.addEventListener(Event.CHANGE,onColorChange);
    			
    			holder_mc.mouseChildren=false;
    			//holder_mc.buttonMode=true;
    			holder_mc.addEventListener(MouseEvent.MOUSE_DOWN, paint);
    			
    			reset_btn.addEventListener(MouseEvent.MOUSE_DOWN,reset);
    		}
    		
    		private function onColorChange(evt:Event):void
    		{
    			current_color=evt.target.selectedColor;
    		}
    		
    		private function paint(evt:MouseEvent):void
    		{
    			var xx:Number=evt.localX;
    			var yy:Number=evt.localY;
    			bitmapdata.floodFill(xx,yy,current_color);
    		}
    		
    		private function reset(evt:MouseEvent):void
    		{
    			loadImage();
    		}
    	}
    }
    Source files:
    Attached Files

  2. #2
    Junior Member Settled In mikyun_patel13 is on a distinguished road
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Re: Coloring regions of images

    thanks
    this one is great

+ Reply to Thread

Similar Threads

  1. Images Scroller version 3
    By Flep in forum FlepStudio utilities
    Replies: 4
    Last Post: 2 Weeks Ago, 02:54
  2. Images Scroller version 2
    By Flep in forum FlepStudio utilities
    Replies: 3
    Last Post: 4 Weeks Ago, 18:49
  3. Images Scroller
    By Flep in forum FlepStudio utilities
    Replies: 60
    Last Post: 09-01-10, 12:10
  4. Caricare images da xml
    By nocciola in forum Actionscript 3.0 avanzato
    Replies: 0
    Last Post: 12-04-09, 07:13
  5. unload images
    By karonte in forum Actionscript 3.0 base
    Replies: 2
    Last Post: 14-05-08, 19:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts