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 1 of 1

Thread: BitmapData - draw method of Actionscript 3.0

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

    BitmapData - draw method of Actionscript 3.0

    flash templates
    The BitmapData class is a wonderful world. It allows us to work images, animate them, play with their pixels and much more.
    For those who haven"t yet approached this class, I"ll try to make life easier starting from the draw method of the BitmapData.
    What does this method do" In a few words, you could say that this method shoots a photo to the object passed in as parameter ( source ).
    This method takes 6 parameters"
    but in this tutorial I"ll only use 1 to simplify the approach to the class.
    The parameter in question is, in fact, the source, hence the name of the instance of the object I want to " photograph ".

    Let"s enter the core:
    I create an FLA and save it as " bitmapdata_draw.fla " inside of which I create a MovieClip and I animate it using the frame-to-frame technique.
    I create the Document Class, as AS file that I save as " Drawing.as ".
    I associate the FLA to the class ( we"ve already seen how in this site"s article "The best way to initiate the Main Class").

    And here is how I"ve written the Document Class:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.display.SimpleButton;
    	import flash.display.Bitmap;
    	import flash.display.BitmapData;
    	import flash.events.*;
    	
    	public class Drawing extends MovieClip
    	{
    		private var bitmap:BitmapData;
    		private var bitmaps_array:Array;
    		private var W:int=100;
    		private var H:int=100;
    		private var ratio:int=5;
    		private var clipCounter:int=0;
    		private var distance:int=10;
    		private var lines:int=0;
    		
    		public function Drawing()
    		{
    			stage.frameRate=31;
    			clip_mc.stop();
    			init();
    		}
    		
    		private function init():void
    		{
    			bitmaps_array=new Array();
    			clip_mc.play();
    			addEventListener(Event.ENTER_FRAME,onEnterFrameDraw);
    		}
    		
    		private function onEnterFrameDraw(event:Event):void
    		{
    			if(!(clip_mc.currentFrame%ratio))
    			{
    				bitmap=new BitmapData(W,H,true,0xFFFFFFFF);
    				bitmap.draw(clip_mc);
    				bitmaps_array.push(bitmap);
    				var image:Bitmap=new Bitmap(bitmap);
    				addChild(image);
    				image.y=150+distance;
    				image.x=(W+distance)*clipCounter;
    				if(!(clipCounter%ratio)&&clipCounter!=0)
    					lines++;
    				image.y+=(100+distance)*lines;
    				image.x=(W+distance)*(clipCounter-(ratio*lines));
    				clipCounter++;
    			}
    			if(clip_mc.currentFrame==clip_mc.totalFrames)
    			{
    				removeEventListener(Event.ENTER_FRAME,onEnterFrameDraw);
    				initButtonListener();
    			}
    		}
    		
    		private function initButtonListener():void
    		{
    			ripeti_btn.addEventListener(MouseEvent.MOUSE_DOWN,clearData);
    		}
    		
    		private function removeButtonListener():void
    		{
    			ripeti_btn.removeEventListener(MouseEvent.MOUSE_DOWN,clearData);
    		}
    		
    		private function clearData(event:MouseEvent):void
    		{
    			for(var i:int=0;i < bitmaps_array.length;i++)
    			{
    				bitmaps_array[i].dispose();
    			}
    			removeButtonListener();
    			clip_mc.gotoAndStop(1);
    			clipCounter=0;
    			lines=0;
    			init();
    		}
    	}
    }
    This is the result:







    In the script, under the onEnterFrame interval, I control the current frame"s number of the MovieClip we have in the FLA.
    If that number is a multiple of 5, than I create a new BitmapData which I assign to new Bitmap(BitmapData) and I perform addChild to make it visible.
    The rest of the code is needed to position the created images and manage the events of the " Ripeti " button.

    Source files:
    Attached Files

+ Reply to Thread

LinkBacks (?)

  1. 3 Weeks Ago, 17:38
  2. 11-07-10, 21:29
  3. 04-06-08, 13:53

Similar Threads

  1. curveTo Method with Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 1
    Last Post: 23-01-10, 16:18
  2. New HitTest method of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 5
    Last Post: 25-08-09, 15:13
  3. Actionscript 3.0 perlinNoise method
    By Flep in forum Tutorials
    Replies: 6
    Last Post: 05-12-08, 09:05
  4. BitmapData e metodo draw
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 19-09-07, 13:13
  5. BitmapData.draw() da movieclip
    By aguia in forum Actionscript 3.0 avanzato
    Replies: 7
    Last Post: 31-08-07, 06:24

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