Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : Drawing Tool Erase Problems


Stevie_R
11/16/2004 10:52:45 PM
I am trying to create an interactive drawing palette, where individuals can
choose to place a dot or use the Flash API functionality to draw a line. Most
of it is working, but I can't get the eraser to work. i, for some reason,
doesn't decrement properly when lineOn=true. The s does decrement when starOn
is true, but for some reason the i value continues to be reset. Added to that,
nothing actually gets erased from the canvas. Any thoughts/ideas would be much
appreciated.

Thanks, all! This community is wonderfully helpful!

var i:Number = 0;
var s:Number = 0;
var starArray:Array = new Array();
var lineOn:Boolean = false;
var starOn:Boolean = false;

makeStar_mc.onPress = function() {
if (starOn==false) {
makeStar_mc.gotoAndStop(2);
starOn=true;
_root.onMouseDown = function() {
if (_xmouse > 50 && _ymouse > 20 && _xmouse < 500 && _ymouse < 350) {
starArray[s] = _root.star_mc.duplicateMovieClip("star_mc"+s,s);
starArray[s]._x=_root._xmouse;
starArray[s]._y=_root._ymouse;
s++;
};
}
} else {
starOn=false;
makeStar_mc.gotoAndStop(1);
delete _root.onMouseDown;
}
}

pencil_mc.onRelease = function() {
if (lineOn==false) {
lineOn=true;
_root.onMouseDown = function () {
i=i+1;
createEmptyMovieClip("Line"+i,i);
["Line"+i]lineStyle(2,0x000000,100);
["Line"+i]moveTo(_xmouse, _ymouse);
_root.onMouseMove = function () {
["Line"+i]lineTo(_xmouse, _ymouse);
};
};
_root.onMouseUp=function() {
trace ("i is now "+i);
_root.onMouseMove=null;
};
} else {
lineOn=false;
_root.onMouseDown=null;
}
}

erase_mc.onRelease = function() {
trace("eraser's current value of i is "+i);
trace ("eraser's current value of s is "+s);
trace("starOn is " +starOn);
trace("lineOn is "+lineOn);
if (starOn==true) {
s=s-1;
_root.removeMovieClip(["star_mc"+s]);
trace ("Now removing "+["star_mc"+s]);
} else {
_root.removeMovieClip(["Line"+i]);
trace ("Now removing "+["Line"+i]);
i=i-1;
}
}
Stevie_R
11/17/2004 2:07:21 AM
That's fine, and I can certainly fix that, though the lines are drawing just
fine. What I'd really like to figure out is the code inside the
erase_mc.onRelease function. Nothing erases, and the i variable doesn't
decrement when you try to erase a line. Would the code corrections you offered
above be related to that, or am I also having a different problem?

Thanks!
Stevie
NSurveyor
11/17/2004 2:36:34 AM
Does trace ('Now removing '+['Line'+i]); trace that into the output window. If
not, that means that the else condition never is happens. Which you would have
to find out why. And by the way, if (starOn==true) { can be written as if
(starOn) {. Because the whole point of an if is to see if something is true. SO
if starOn is true, there you go. Saying true == true is a bit retoricle. But,
thats not really important.
Jeckyl
11/17/2004 10:04:30 AM
["Line"+i]lineStyle(2,0x000000,100);
["Line"+i]moveTo(_xmouse, _ymouse);
_root.onMouseMove = function () {
["Line"+i]lineTo(_xmouse, _ymouse);
};

That syntax is completely wrong .. you want

_root["Line"+i]

instead of ["Line"+i]

and you want a '.' between the ] and lineStyle etc (eg
_root["Line"+i].lineStyle...)

["Line"+i] is an single entry array .. not what you are wanting.

Jeckyl
11/17/2004 1:30:48 PM
[quoted text, click to view]

possibly .. as we only have a snippet of what is going on in your movie, its
hard to tell.

certainly, the more problems you fix, the less problems you're going to have
:)

for example, because of the error in your reference to the line, the line
are being drawn directly on the _root, not in the line clip .. so when you
remove the line clip, it will have no impact on the drawing you are seeing.

Jeckyl
11/17/2004 1:40:55 PM
Also all this is completely wrong as well

if (starOn==true) {
s=s-1;
_root.removeMovieClip(["star_mc"+s]);
trace ("Now removing "+["star_mc"+s]);
} else {
_root.removeMovieClip(["Line"+i]);
trace ("Now removing "+["Line"+i]);
i=i-1;
}

you seem to be missing the point of the [] operators and using it in a way
that does something completely different to what you're obviously trying to
do.

unless you fix all that, your code has no hope of working

AddThis Social Bookmark Button