PDA

View Full Version : Having problems with scripting of sketchpad?


juz_me
03-14-2007, 05:57 AM
Basically what i want to achieve is a sketch pad (within an image) with colour swatches (where ppl can draw on it, and change colour). I tried out this tutorial which works nicely, however, the funny part is, i can only draw STARTING from the left area. If i were to start drawing from the right, nothing appears. But if i start drawing from the left ONLY then i can continue drawing to the right. It's weird and i dun understand why is this is so. Can anyone help me out pls? Wud really appreciate it. If possible, fast answer as i am stuck with my project. Hope to hear from someone soon.

By the way, this is the script that i used,

lineThickness = 0;
selectedColour = "0x000000";
drawOn.onMouseDown = startDrawing;
drawOn.onMouseUp = stopDrawing;
function startDrawing() {
if (_xmouse<455) {
drawOn.lineStyle(lineThickness, selectedColour);
drawOn.moveTo(drawOn._xmouse,drawOn._ymouse);
drawOn.onMouseMove = drawLine;
}
}
function drawLine() {
drawOn.lineTo(this._xmouse, this._ymouse);
}
function stopDrawing() {
delete this.onMouseMove;
}
line0.onPress = function() {
lineThickness = 0;
};
line3.onPress = function() {
lineThickness = 3;
};
line6.onPress = function() {
lineThickness = 6;
};
colourRed.onPress = function() {
selectedColour = "0xFF0000";
};
colourGreen.onPress = function() {
selectedColour = "0x00FF00";
};
colourBlue.onPress = function() {
selectedColour = "0x000099";
};
colourWhite.onPress = function() {
selectedColour = "0xFFFFFF";
};
colourBlack.onPress = function() {
selectedColour = "0x000000";
};
colourViolet.onPress = function() {
selectedColour = "0xCC00FF";
};
colourPurple.onPress = function() {
selectedColour = "0x9900FF";
};
colourYellow.onPress = function() {
selectedColour = "0xFFFF00";
};

halfasleeps
03-14-2007, 05:16 PM
the reason it won't start drawing from the right is because it is above 455 and you clearly tell it to start drawing only if its below 455 ie: if(_xmouse<455) but the reason you can start from the lest and drag onto the right is because your onmousemove function never checks to see if it has passed 455 once it starts...you can check it to fix this like this:

lineThickness = 0;
selectedColour = "0x000000";
this.onMouseDown = startDrawing;
this.onMouseUp = stopDrawing;
function startDrawing() {
if (_xmouse<455) {
this.lineStyle(lineThickness, selectedColour, 100);
this.moveTo(this._xmouse, this._ymouse);
this.onMouseMove = drawLine;
}
}
function drawLine() {
if (_xmouse<455) {
this.lineTo(this._xmouse, this._ymouse);
}else{
moveTo(this._xmouse, this._ymouse);
}
}
function stopDrawing() {
delete this.onMouseMove;
}

juz_me
03-15-2007, 06:49 AM
Hi halfasleeps,

Thanx for the tip. Now it works. However, there's another problem which i'm facing. The situation now is like this: I have an image on screen, where it can be zoomed in and out of. It can be drawn onto by selecting the colours that i have provided. So the thing now is that, i want to make it such that the user is able to draw on certain parts of the image that they would like to, for eg, in the image there is a house n tree. N i would like to draw on the roof of the house, so i would zoom into the roof to draw. After that i can zoom out n my DRAWING IS SUPPOSED TO REMAIN AT THE ROOF, tt is, it SHOULD ZOOM OUT TOGETHER WIF THE PIC). This is the problematic part. How can i get it to work that way? Currently, my drawing would not zoom out wif the image. It just stays there evn after zooming out, thus not be in the correct position where it should be n thus does not serve the point of zooming into the particular area. Please help me out. Thanx u.