Drawing simulation

Ok I commented my code… lemme know if there is anything specific you need me to go more into detail with…

[AS]//declare trigger variable originally set to false
trigger = false;
//create the 3 clips used…
//box is the grey box in the background (created on level 1)
//line is the uhhh line (created on level 2)
//dot is the dot (created on level 3)
//++depth sets each one on a new level (only 1 clip can exist on a level)
this.createEmptyMovieClip(“box”, ++depth);
this.createEmptyMovieClip(“line”, ++depth);
this.createEmptyMovieClip(“dot”, ++depth);
//use drawing API to draw dot
//3 is line width, 0xFF0000 is hex for red, 100 is alpha
dot.lineStyle(3, 0xFF0000, 100);
dot.lineTo(.15, .45);
//set dot clip to be invisible
dot._visible = false;
//set lineStyle of line you will be drawing with
//.25 is the line width, 0 (short for black), is the color, 100 is the alpha
line.lineStyle(.25, 0, 100);
line.onMouseDown = function() {
//if when the mouse is pressed it is also over the box clip
if (box.hitTest(_xmouse, _ymouse, true)) {
//if trigger is false
if (!trigger) {
//move the line clip the current mouse position
this.moveTo(_xmouse, _ymouse);
//make the dot clip visible
dot._visible = true;
//move the dot clip to the current mouse position
dot._x=_xmouse, dot._y=_ymouse;
//set trigger to true (so this stays in original position)
trigger = true;
//else… (meaning else if trigger was true)
} else {
//draw a line to the current mouse position
this.lineTo(_xmouse, _ymouse);
//make the dot clip invisible again
dot._visible = false;
//reset the trigger back to false
trigger = false;
}
//else if the mouse is pressed when it is not over the box clip
} else {
//hide the dot clip again
dot._visible = false;
//reset trigger to false
trigger = false;
}
};
//draw box… same as before
box.lineStyle(.25, 0x000000, 50);
box.beginFill(0xEEEEEE, 50);
box.moveTo(20, 0);
box.lineTo(20, 420);
box.lineTo(400, 420);
box.lineTo(400, 0);
box.lineTo(20, 0);
box.endFill();[/AS]

I was taking a look at your site and remembered that I had visited it once on the beginning of this year, if I`m right :confused:
I love the “Pixel Explosion” experiment!

Thanks for the code comments!
Would u mind if I ask you where did you learn so much about AS?
:slight_smile:

The pixel explosion was mostly Ilyas’ coding, I did modify it to do different things though.

As for where I learned so much about AS… I answered that earlier today in another thread :stuck_out_tongue:

http://www.kirupaforum.com/forums/showthread.php?s=&threadid=25479

sorry to post in an old topic… but i just came up with a better way to limit the drawing between certain coordinates:

minX = 5;
minY = 5;
maxX = 250;
maxY = 250;
createEmptyMovieClip("line", ++depth);
line.lineStyle(0);
line.onMouseDown = function() {
    this.moveTo(_xmouse, _ymouse);
    this.onMouseMove = function() {
       **x = (_xmouse>maxX) ? maxX : ((_xmouse<minX) ? minX : _xmouse);
        y = (_ymouse>maxY) ? maxY : ((_ymouse<minY) ? minY : _ymouse);**
        this.lineTo(x, y);
    };
};
line.onMouseUp = function() {
    delete this.onMouseMove;
};