April 30, 2009

AS3 Drawing Pad

In this tutorial we are going to develop flash drawing pad using actionscript3. In this tutorial we are using color picker component and Numeric stepper.




Let’s start . open New flash cs3 file. Create new Movie clip , name it as “drawpad”. Drag and drop color component from components list and give instance name as “mcColor” , similarly drag and drop Numeric stepper and name it as “mcStepper”. Create new Moviclip called “bg”, and make drawable area inside that. Now drag this Movieclip inside “drawpad” Movieclip. Now write the following script in the first frame of “drawpad” Movieclip.
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.MovieClip;
var isDrawing:Boolean = false;
var child:Shape = new Shape();
var bytes:ByteArray;
var thisX;
var thisY;
canvas.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
canvas.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
canvas.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

function mouseDownHandler(event:MouseEvent) {
isDrawing = true;
if ( isDrawing) {

var val=mcStepper.value;
var col=mcColor.selectedColor;
child.graphics.lineStyle(val, col);
child.graphics.moveTo(mouseX, mouseY);
thisX=mouseX;
thisY=mouseY;
}
}
function mouseMoveHandler(event:MouseEvent) {
//cursor.x=mouseX;
//cursor.y=mouseY;
if (isDrawing) {

child.graphics.lineTo(mouseX, mouseY);
canvas.addChild(child);
//child.graphics.curveTo(thisX,thisY,mouseX, mouseY);
}
/*if(mouseX <> 295)
{
isDrawing = false;
}
if(mouseY <> 145)
{
isDrawing = false;
}*/
}
function mouseUpHandler(event:MouseEvent) {

isDrawing = false;
var myBitmapData:BitmapData = new BitmapData (canvas.width, canvas.height, false, 0x00FFFFFF);
var rect:Rectangle = new Rectangle(0, 0, canvas.width, canvas.height);
myBitmapData.draw(canvas);
//
bytes = myBitmapData.getPixels(rect);
//
bytes.position = 0;
}

Thats all. you can download source file from here

 

About

we are doing all kind of web / standalone applications using Flash , FMS, PHP , XML , CSS , etc. we handle all projects starting from the initial design concept through the delivery of your personalized product. Our commitment to you is comprehensive and complete-aimed at satisfying your every need. We have the experience and the expertise to get the job done.

Site Info

we Currently handling web requirements and multimedia productions and we have the capability of cutting your web , graphics and multimedia expenses to a bare minimum without sacrificing professional quality or delaying production. Our focus is on the development of smart, successful ideas and we always strive to maintain the highest . we currently using following technologies Flash 8, Flash cs3,Actionscript 2 ,Action script 3 ,Flash Media server , PHP,AMFPHP,XML ,HTML ,CSS ,Photoshop

Text

Digizone, AnnaNagar East, Chennai, TamilNadu ,India. Please view our website for further details

Flash and photoshop resources FREE Download Copyright © 2009 Community is Designed by Bie