Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-23-2005, 11:10 AM   #1
dafman
Registered User
 
Join Date: Aug 2005
Posts: 4
Default how to create objects that move away from cursor but return to original position

hey all, i'm new here, allready searched a lot on the internet and this forum but couldn't find what i want.

for a website i want to place a lot of squares on a grid, and when the cursor move over them, they need to evade (move away) the cursor, but only a maximum of a distance, and when the cursor is far away enough, they need to get back to their original position. In other words, when the cursor gets to close, the squares should try to get away from it as far as poossible, but they are "chained" to their position by an elastic. It would also be nice if the speed of the cursor affects the way this all happens.

thanx all in advance!
dafman is offline   Reply With Quote
Old 08-23-2005, 02:53 PM   #2
majicassassin
Demigod
 
majicassassin's Avatar
 
Join Date: Aug 2005
Posts: 282
Send a message via AIM to majicassassin
Default

Long answer short: you're asking for a lot of complicated things in one actionscript.

How to do what you want:
You're going to have to create variables inside eachbox (you can do this dynamically) so that it remembers what position is it is at/supposed to return to.
You're going to have to make a movie clip that checks the mouse position, and rusn through each square, looking at the boxes and telling them how far they are from it (you use the variables I just said you need to store to check this) and tell them how to move out of the way accordingly.
The speed thing will come naturally, since you're going to have a box move as aresult of the distance of the mouse, the faster they move it in, the faster the box will move away from it if you do the first two right.

Have fun =^^=
majicassassin is offline   Reply With Quote
Old 08-23-2005, 02:57 PM   #3
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

this is mostly what you described:
http://www.senocular.com/flash/source.php?id=0.71
__________________
(6)
senocular is offline   Reply With Quote
Old 08-23-2005, 04:14 PM   #4
dafman
Registered User
 
Join Date: Aug 2005
Posts: 4
Default thanks

both posts were very usefull!
dafman is offline   Reply With Quote
Old 08-23-2005, 07:59 PM   #5
dafman
Registered User
 
Join Date: Aug 2005
Posts: 4
Default going allright so far

thanks to this senocular script i managed to get it almost right... almost!

there is a part of the script that generates all the balls:

generateBallCluster = function(x, y){
this.createEmptyMovieClip("cluster",0);
this.cluster._x = x;
this.cluster._y = y;

var currball,x,y, depth = 0;
for (x=0; x<15; x++){
for (y=0; y<15; y++){
currball = this.cluster.attachMovie("ball", "b"+depth, depth++);
currball._x = x*40;
currball._y = y*40;
currball.origin = {
x: currball._x,
y: currball._y
}
currball.onEnterFrame = balloEF;
}
}
}
generateBallCluster(20,20);


so with this you get 15*15 rows with an offset of 40 pixels. what can i do when i want to leave some balls out, to make some white spots?

i hope you understand what i mean,
thanx!
dafman is offline   Reply With Quote
Old 08-24-2005, 11:05 AM   #6
dafman
Registered User
 
Join Date: Aug 2005
Posts: 4
Default

well i think i can answer my own question; i'll need to create an array in order to define at which position there has to be a ball and on which position there hasn't.
but i really don't know how to make anything like that, and how it can be fitted in in this script.
anybody out there who can help?
cheers
dafman is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:28 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.