PDA

View Full Version : clicking 2 create MC


speedlemon
07-06-2004, 12:59 AM
ok. i was wondering if anyone could help me out here.

GOAL:
create an actionscript that creates duplicates of an MC and puts them where last clicked. let me try to explain this better.

EXPLANATION:
i click on the screen. the mc appears there. i click somewhere else. a copy of the same mc appears there too. and so on and so forth

sorry, no code yet, im at a cafe.

kudos to whoever helps me out. :cool:

Scottae
07-06-2004, 04:22 AM
Copy and paste this code into the first frame of the main timeline of a new Flash MX movie and test it out:


// initialize variable 'i'
var i = 0;

// create function that duplicates (or in this case creates)
// the movie clip and then positions it
function createMC() {

// width of square
var w = 10;

// clip is reference to the newly created empty clip
var clip = this.createEmptyMovieClip("clip" + i, i++);

// draw a square in the empty clip created above and position
// it to the current position of the mouse
with (clip) {
lineStyle(0, 0x000000, 100);
beginFill(0xFF0000, 20);
lineTo(w, 0);
lineTo(w, w);
lineTo(0, w);
lineTo(0, 0);
endFill();
_x = _xmouse;
_y = _ymouse;
}
}

// set onMouseDown event to the function 'createMC' above
_root.onMouseDown = createMC;

speedlemon
07-06-2004, 08:51 PM
thanks a lot. your comments will definately help too.

Alvaretto
07-10-2004, 02:51 AM
That was nice, Scottae!

In this example, after creating the clip, the mouse is on the left top corner of the square. How would it be for the mouse to be in the center?

Scottae
07-10-2004, 06:55 PM
// initialize variable 'i'
var i = 0;

// create function that duplicates (or in this case creates)
// the movie clip and then positions it
function createMC() {

// width of square
var w = 10 / 2;

// clip is reference to the newly created empty clip
var clip = this.createEmptyMovieClip("clip" + i, i++);

// draw a square in the empty clip created above and position
// it to the current position of the mouse
with (clip) {
lineStyle(0, 0x000000, 100);
beginFill(0xFF0000, 20);
moveTo(-w, -w);
lineTo(w, -w);
lineTo(w, w);
lineTo(-w, w);
lineTo(-w, -w);
endFill();
_x = _xmouse;
_y = _ymouse;
}
}

// set onMouseDown event to the function 'createMC' above
_root.onMouseDown = createMC;