Adding actions to duplicated MC's?

Im trying to duplicate a movieclip, that is trailing to my mouse (only on the _x axis). Now I want to duplicate that movieclip several times and making the duplicates follow the first movieclip, but with a _x difference between them (lineair steps).

Now I can get the first movieclip to follow the mouse on the _x axis, and I can get to duplicate it several times, but I get stuck when trying to add the actions to the ones I’ve duplicated…

Any ideas? :-\

What code do you have currently ?

This is the function for following the mouse over the _x axis, it’s currently stuck on a button…

	
on(release){
   carrierMC.onEnterFrame = function (){
	 with(this){
		distX = (_root._xmouse - _x)
		_x += distX*0.2;
		 }
 	}
}

This is the code for duplicating the main MC.


amount = 4;
	while (amount>0) {
		duplicateMovieClip (_root.carrierMC, "mc"+i, i);
		setProperty ("mc"+i, _x, random(500));
		i++;
		amount--;
	}

I added this next piece right under that one.


["mc"+i]._visible = false

just to try and test that, but it didn’t work

well this code is pretty messy, because I was just playing with it a little bit.
Im eventually not going to use it as a mouse trailer but more like a component for displaying pictures, this is why I want to use duplicated MC’s (and external jpeg’s). Now I don’t know how to load those correctly into a duplicated movieclip but I reckon it should be similar to the code for making the duplicated mc’s work.

Ok, dat laatste gedeelte maakt het allemaal een beetje heel erg verwarrend… sorry…

Ok, dat laatste gedeelte maakt het allemaal een beetje heel erg verwarrend… sorry…

Inderdaad :stuck_out_tongue:

I’m not sure what exactly it is you are trying to achieve. To load to a duplicated movieclip or to create a mouse trailer using duplicated movieclips ?

Anyway, a handier code for


amount = 4;
	while (amount>0) {
		duplicateMovieClip (_root.carrierMC, "mc"+i, i);
		setProperty ("mc"+i, _x, random(500));
		i++;
		amount--;
	}

is


amount=4;
for(i=0;i<=amount;i++){
m = _root.carrierMC.duplicateMovieClip ("mc"+i, i);
m._x = Math.floor(Math.random()*500+1);
}

Using m as reference to the just duplicated movieclip, you can write code much simpler. Just use m to target the las duplicated movieclip :slight_smile:

Using the same way, you can add dynamic event handlers to m:


amount=4;
for(i=0;i<=amount;i++){
m = _root.carrierMC.duplicateMovieClip ("mc"+i, i);
m._x = Math.floor(Math.random()*500+1);
m.onEnterFrame = function(){
//do stuff here
}
}

yeah this was the kind of code I was looking for, much better than that old FLash 4 duplicateMC stuff I reckon!
So I’ve played around with it a little, but when I tried to add some movement to the clips I ran into a problem because the function() command is only running once;
this is my code now (thanks to Voetsjoeba !):


amount=4;
for(i=1;i<=amount;i++){
        m = _root.carrierMC.duplicateMovieClip ("mc"+i, i);
        m._x = i*125-125;
        m.loadMovie(i+".jpg")
		m.onEnterFrame = function (){
 				m.distX = (_root._xmouse - m._x)
				m._x += m.distX*0.2;
 	}      
}


I’ don’t know what your problme is exactly. Can you please explain further ?

well this code only runs for as long as i is being iterated. and only when that happens.
So when you run a trace on m.distX ( trace(m.distX) ) you will get only 4 values, and the movieclips change accordingly, but that is not very usefull, since they move only once.

So what you want them to do is keep following the mouse, after the for([…]) loop has ended, but that doesn’t happen with this code, I don’t really understand why though.

Hope that explains it a little bit…

PS: is Ghent niet zonder G of zie ik iets over het hoofd? (nou ja ik ben natuurlijk een nederlander en geen belg :slight_smile: )

Gent in het engles is Ghent :wink:

This should do


amount=4;
for(i=1;i<=amount;i++){
        m = _root.carrierMC.duplicateMovieClip ("mc"+i, i);
        m._x = i*125-125;
        m.loadMovie(i+".jpg")
		m.onEnterFrame = function (){
 				this.distX = (_root._xmouse - this._x)
				this._x += this.distX*0.2;
 	}      
}

Should work.

sadly, that code doesn’t seem to work either. Wait I’ll through up the .fla (just a sec)

That sure did work for me :-\ but ok :slight_smile:

– attachement –

the *.fla contains the code of two posts earlier, e.g. not the edited version by Voetsjoeba (although there isnt a lot of difference between them).

I also included the externally loaded files to keep the file working.

pictures courtesy of www.orandajin.nl :slight_smile:

Wow, this behaviour is weird … lemme look into it.

Solved this the easy way.

*Oh, you can delete the empty movieclip that is on stage :slight_smile:

yup that code works great, cept there is one problem; everything on the stage moves along in the mouse trailer function, so not just the created movieclips…

this looks really strange offcourse, and I didnt figure out yet how to stop it from happening.

Any ideas?

(sorry for my lameness :*( )

Woops ! :stuck_out_tongue: Lemme fix that.

Here:

yup you did it :love:

only one more question (I hope): how can I trigger the movement part with a button? As in; I only want the last part of the code to be executed after I’ve pressed a button elsewhere on the stage?

With the last code I got it to work but I can’t get it working in the new version anymore :puzzle:

anyway, i’d like to thank you very much for you help already voetsjoeba, and Im sorry that Im a little confusing in what I want to do because Im learning how to do this first, so I can make a useful implementation of it later. Like: Im not going to use this exact code but if I can get this to work I know how to get something else to work, so I could make that myself. So thanks a lot as well for teaching me a whole lotta new stuff =)

Here you are :wink:

thanks, this is helping me a lot :slight_smile:

but I am afraid I have to ask one more question… sowwy :*(

What If I wanted to add a mask over the loaded images, how would I go about and do that?

Just create a movieclip with your mask in it, set the registration point to the left so you can easily control it’s position relative to the images, then use the setMask method :slight_smile: