Suprabeener: A quick Q:

thanks first: your randomotion code rokks.\r\ri checked the threads and am still a bit unclear as to where/what in the code needs to be changed in order to move the starting position of the clips to the center…\r\ralso, when using multiple clips, should i include the same code for each in the main timeline?\r\rlastly, is there anyway to have each load in random positions?\r\rsuprathanks beener!

Can I answer too ?\r\rpom 0]

thanks quandry,\r\reasiest way to put the clips in the center would be to move them there in the fla. or you could use the code below and replace the random coordinates with fixed ones representing the center of your movie.\r\ryou only need define the methods once for all the clips to use them. that’s the beauty of methods!\r\rhmmmm, do you want them in the center, or randomly spread? you could just run a bit of code at the start, assuming they’re all in _root:

 \r\rfor(mc in _root)\r\r   _root[mc]._x = Math.random()*100;\r\r   _root[mc]._y = Math.random()*100;\r\r}

\rput something like that in frame 1 with the functions etc.

no pom, the master has spoken.

LOL\r\rthanks for the quick reply Sb.\r\rCurrently they’re starting in the upper left which presents a problem with the mouse overs i’ve added tweening off the page. I don’t care if they eventually do this, but want them to be viewable at first.\r\rOpening Flash now to try your code. Will report :slight_smile: \r\rThanks again

Guess I’d better reply + ask Q’s in context, apologies in advance for my redardation where applicable :slight_smile: \r\r***\reasiest way to put the clips in the center would be to move them there in the fla. \r***\rThey are all positioned in the main scene of the fla as i would like them to originate the random movement from.\r\r***\rhmmmm, do you want them in the center, or randomly spread? \r***\rit would be ideal if they could start moving from the positions i placed the mc’s at in the fla. Otherwise, starting in the center and randomly moving outward would work fine. \r\r***\ryou could just run a bit of code at the start, assuming they’re all in _root:\r***\rI maybe putting this in the wrong place, but now there is no random movement at all. They are in their ideal starting positions though.\r\rI tried:\r1. dropping it on a new keyframe by itself\r2. pasting it into the already existant script code on frame 1.\r3. adding it to mc AS\r\rall to varying degrees of failure.\r\rIf you could apply a babytalk filter in letting me know where to place the code below, it would be MUCH appreciated :slight_smile: \r\rR\r\r\r\r

well, i’m beat. still can’t get this to work. thanks for the orig. effort though - if you get around to it, thanks.

try initialising the x and y values right at the start too. if they’re undefined, that will be interpreted as 0,0. you could use the same kind of loop to do this to:

 \r\rfor(mc in _root){\r\r   _root[mc].y = _root[mc]._y;\r\r   _root[mc].x = _root[mc]._x;\r\r}

\ror put it individually in each clip in an on load event:

 \r\ronClipEvent(load){\r\r   this.y = this._y;\r\r   this.x = this._x;\r\r}

\rhave you changed the range of possible placement to match your movie? the example was made in a 100 x 100 movie.\r\rthat code could go right beside the rest of the code, just tack it on to the bottom. if it’s not working there, maybe your movies aren’t in _root. just change the paths according to your movie’s structure. sounds like there’s an error of some kind if this code stopped everything from working.

first of all apologies for the belated nature of this thankful + humble reply to your last attempt to help me.\r\ri tried several placement iterations in trying to include the code you posted with failed results on this end.\r\ri’ve decided to upload a sample file with downloadable source which should prove to be easier than me trying to explain my problem with such a limited AS vocabulary.\r\\r\ryou’ll see that circle 03 (my last attempt at inclusion of the code) loads in place, but remains static. \r\rYour review is much appreciated. Feel free to paste the code in the src and email it to me ([email protected]) if you think it would be easier, otherwise thanks in advance for sticking with me on this one supraB. looking forward to your reply!\r\rR

i overlooked something in the code …\r\rif you set the x and y variables at the beginning, getDistance will return a positive number (instead of undefined) so if (_root.getdistance(_x, _y, targx, targy)>speed) always returns true and you never initialise the variables, hence no movement.\r\ryou can solve this by just forcing the reset method at the beginning.\r\radding this to frame 1 did the trick:

 \r\rfor(m in _root){\r\r&nbsp &nbsp &nbsp &nbsp _root[m].x = _root[m]._x;\r\r&nbsp &nbsp &nbsp &nbsp _root[m].y = _root[m]._y;\r\r&nbsp &nbsp &nbsp &nbsp _root[m].reset();\r\r}

thanks suprabeener, glad to read that a solution has been reached!\r\runfortunately again i have to seek education.\r\ri tried putting the code in several places again:\r\r[1] new layer in frame 1\r[2] individually in each clip at the bottom of:\r onClipEvent (enterFrame) {\r &nbsp &nbsp &nbsp &nbsp move();\r }

just this in each clip:

 \r\ronClipEvent (enterFrame) {\r\r&nbsp &nbsp &nbsp &nbsp move();\r\r}

\rand all this in frame 1:

 \r\r// Random Movement:\r\r// Thanks to Suprabeener for the original code!\r\rfunction getdistance (x, y, x1, y1) {\r\r&nbsp &nbsp &nbsp &nbsp var run, rise;\r\r&nbsp &nbsp &nbsp &nbsp run = x1-x;\r\r&nbsp &nbsp &nbsp &nbsp rise = y1-y;\r\r&nbsp &nbsp &nbsp &nbsp return (hyp(run, rise));\r\r}\r\rfunction hyp (a, b) {\r\r&nbsp &nbsp &nbsp &nbsp return (Math.sqrt(a*a+b*b));\r\r}\r\rMovieClip.prototype.reset = function () {\r\r&nbsp &nbsp &nbsp &nbsp var dist, norm, movie_height, movie_width;\r\r&nbsp &nbsp &nbsp &nbsp movie_height = 768;\r\r&nbsp &nbsp &nbsp &nbsp movie_width = 1024;\r\r&nbsp &nbsp &nbsp &nbsp speed = Math.random()*2+1;\r\r&nbsp &nbsp &nbsp &nbsp targx = Math.random()*(movie_width-_width);\r\r&nbsp &nbsp &nbsp &nbsp targy = Math.random()*(movie_height-_height);\r\r&nbsp &nbsp &nbsp &nbsp dist = _root.getdistance(_x, _y, targx, targy);\r\r&nbsp &nbsp &nbsp &nbsp norm = speed/dist;\r\r&nbsp &nbsp &nbsp &nbsp diffx = (targx-_x)*norm;\r\r&nbsp &nbsp &nbsp &nbsp diffy = (targy-_y)*norm;\r\r};\r\r\r\r\r\rMovieClip.prototype.move = function () { var cycle;\r\r&nbsp &nbsp &nbsp &nbsp cycle = 100;\r\r&nbsp &nbsp &nbsp &nbsp if (_root.getdistance(_x, _y, targx, targy)>speed) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp x += diffx;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp y += diffy;\r\r&nbsp &nbsp &nbsp &nbsp } else {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp x = targx;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp y = targy;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if (!this.t) this.t = getTimer();\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if (getTimer()-this.t > cycle) {\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp reset();\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp t = 0;\r\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }\r\r&nbsp &nbsp &nbsp &nbsp }\r\r&nbsp &nbsp &nbsp &nbsp _x = x;\r\r&nbsp &nbsp &nbsp &nbsp _y = y;\r\r};\r\r\r\rfor(m in _root){\r\r&nbsp &nbsp &nbsp &nbsp _root[m].x = _root[m]._x;\r\r&nbsp &nbsp &nbsp &nbsp _root[m].y = _root[m]._y;\r\r&nbsp &nbsp &nbsp &nbsp _root[m].reset();\r\r}


thanks for applying the newbie filter sB,\r\ri didn’t have any luck though… the files at:\\rare updated for review.\r\rthanks!\r

it seemed to have something to do with white space. very odd.\r\rreplacing the spaces in the indents with tabs made it all ok.

supraB.\r\rIt works PERFECTLY. \r\rYour assistance has been more than appreciated and borders on sainthood___<heh>\r\rIf you’d like, send your digits to [email protected] + i’ll mail you the disc when done.\r\rAgain, much thanks___.R