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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

proximity script what is it missing?

Status
Not open for further replies.

PoPaX2

Technical User
Nov 24, 2001
5
US
I am trying to write a script that will scale an object on the screen as the mouse curor gets closer to another object's instances. I am using this script as b-clip in a button movie. The following only scales to 1 of the instances and ignores the others. Can anyone help me with this?

point1x = _parent._x
point1y = _parent._y
point2x = _parent._parent._xmouse
point2y = _parent._parent._ymouse

1 = (point1x - point2x)
2 = (point1y - point2y)

distance = math.sqrt((1*1) + (2*2))

setProperty ( root.sphere,_xscale,distance)
setProperty ( root.sphere,_yscale,distance)

 
I think your problem probably stems from the fact that you can't use a straight number as a variable reference, the script above will be setting "distance" to the square root of 5 constantly.

I haven't strictly built this as a b-clip but is this the behaviour that you're after?


If so, here's the code on the control clip - the target sphere has the instance name "sphere1":

onClipEvent (enterFrame) {
xDifferential = _x-_root._xmouse;
yDifferential = _y-_root._ymouse;
distance = Math.sqrt((xDifferential*xDifferential)+(yDifferential*yDifferential));
_root.sphere1._xscale = _root.sphere1._yscale=100-(distance/10);
}
 
Thank you for your reply. I replaced variables with numbers on my post to make things easier but it appears that I have confused things. The effect you have created is what I want however, I need multiple "control clips" to scale the sphere. The following script is what I really used.

point1x = _parent._x
point1y = _parent._y
point2x = _parent._parent._xmouse
point2y = _parent._parent._ymouse

xfactor = (point1x - point2x)
yfactor = (point1y - point2y)

distance = math.sqrt((xfactor*xfactor) + (yfactor*yfactor))

setProperty ( root.sphere,_xscale,distance)
setProperty ( root.sphere,_yscale,distance)


 
I've updated the .swf with something more like what you want (I think).


Similar script to before except that each "controller" has an invisible button around it which triggers a hitTest - if the test is true then the distance is calculated and the sphere is resized accordingly. I've added some script on the sphere itself too so that the rescaling is smoother and it doesn't jump in size when you roll from one hit area to the next.

onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
xDifferential = _x-_root._xmouse;
yDifferential = _y-_root._ymouse;
distance = Math.sqrt((xDifferential*xDifferential)+(yDifferential*yDifferential));
_parent.size = 100-(distance*3);
}
}
 
Eureka!!! A million thanks Wangbar! I hope that you will be rewarded for your generosity soon.

Happy Thanksgiving
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top