Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

applying a function to multiple movieclips?

Status
Not open for further replies.

DGTLguy

Technical User
Jul 23, 2003
125
US
i have a sprite that grows as the mouse nears it, and shrinks as it pulls away using the distance formula (provided by the great wangbar)..

how can i apply this to multiple instances on the stage??

ActionScript.......//


function scanClip () {
// distance formula
diffX = _xmouse-clip._x;
diffY = _ymouse-clip._y;
// scaling
scale = 300-Math.sqrt(diffX*diffX+diffY*diffY);
scale = (scale<100) ? 100 : scale;
clip._xscale = clip._yscale=scale;
};
Clip.onEnterFrame = scanClip;
;
//

stop();
//
 
btw ... i have the actionscript sitting on the first frame of the movie
 
Hi TGTLguy,

what I'd propose is that you name all your clips that should be controled by this function as follows: clip1, clip2, clip3,...

Then insert this code on your first keyframe:
Code:
scanClip = function () {
	// distance formula
	var diffX = _xmouse-this._x;
	var diffY = _ymouse-this._y;
	// scaling
	var scale = 300-Math.sqrt(diffX*diffX+diffY*diffY);
	var scale = (scale<100) ? 100 : scale;
	this._xscale = this._yscale=scale;
	this.onEnterFrame = scanClip;
};
// 
for (i=1; i<4; i++) {
	clip = eval('clip'+i);
	clip.onEnterFrame = scanClip;
}
stop();

The 'for-statement' at the end attaches the function to all clips. This example works for 3 clips. If you had 7 for example you'd have to replace the '4' in the for-statement by a 8.


Hope that helps!

regards

tektips.gif
 
thank you firegambler... it worked easy as pie...

its always the simple stuff...
 
ok... i have four sprites on the stage with the scanClip function (look above) attached to each...

each are scaling as you move your mouse across the screen.

now, is it possible to use an onPress event to stop each MC at their current positions...
 
Try this...

Code:
...
for (i=1; i<4; i++) {
    clip = eval('clip'+i);
    clip.onPress = function(){
        clip.stop();
    };
    clip.onEnterFrame = scanClip;
}
stop();

Mind you I'm not too found of your use of &quot;eval&quot;, associative array syntax may be better.



Regards,

cubalibre2.gif
 
Oh! Might be a better idea to use &quot;my_clip&quot; rather than &quot;clip&quot; alone.

Regards,

cubalibre2.gif
 
for some reason that did not work oldnewbie...

i appreciate the help, any more suggestions anybody?
 
Can you post a link to your .fla or a mockup?
Zipped up and in MX only format. Not MX2004.

Regards,

cubalibre2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top