Using the help of Flash8 in-built help, I tried to make a flash drawing board which we can draw images. An attempt to redraw the image is also made.
This is the code:
this.createEmptyMovieClip(“acanvas_mc”, this.getNextHighestDepth());
this.createEmptyMovieClip(“bcanvas_mc”, this.getNextHighestDepth());
var xarray = new Array();
var yarray = new Array();
var i = 0;
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
this.isDrawing = true;
acanvas_mc.lineStyle(2, 0xFF0000, 100);
captureposition = 1;
acanvas_mc.moveTo(_xmouse, _ymouse);
};
mouseListener.onMouseMove = function() {
if (this.isDrawing) {
acanvas_mc.lineTo(_xmouse, _ymouse);
}
updateAfterEvent();
};
mouseListener.onMouseUp = function() {
this.isDrawing = false;
captureposition = 0;
};
Mouse.addListener(mouseListener);
_root.onEnterFrame = function() {
if (captureposition == 1) {
xarray* = _xmouse;
yarray* = _ymouse;
}
i++;
};
drawbtn.onPress = function() {
for (j=0; j<xarray.length-1; j++) {
bcanvas_mc.moveTo(xarray[j]+400, yarray[j]);
bcanvas_mc.lineStyle(2, 0x000000, 100);
bcanvas_mc.lineTo(xarray[j+1]+400, yarray[j+1]);
}
};
Open flash and create a button named drawbtn. Then copy this script to the first frame of root.
Change the fps to 90. Run and draw something. Then click on the button. You can see the image is redrawn by flash. But there will be a line from position(0,0) to the first position in the drawing. Also if we draw to or more curves, there also lines appear. How I can correct the redraw? If it become correct, then I can save the array of points to an XML and include a save function.
OR Is there any tutorial for this?