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 \r\rThanks again
Guess I’d better reply + ask Q’s in context, apologies in advance for my redardation where applicable \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
\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\rhome.teleport.com/~quadpod/thankssb/\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        _root[m].x = _root[m]._x;\r\r        _root[m].y = _root[m]._y;\r\r        _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         move();\r }
just this in each clip:
\r\ronClipEvent (enterFrame) {\r\r        move();\r\r}
\rand all this in frame 1:
\r\r// Random Movement: kirupa.com\r\r// Thanks to Suprabeener for the original code!\r\rfunction getdistance (x, y, x1, y1) {\r\r        var run, rise;\r\r        run = x1-x;\r\r        rise = y1-y;\r\r        return (hyp(run, rise));\r\r}\r\rfunction hyp (a, b) {\r\r        return (Math.sqrt(a*a+b*b));\r\r}\r\rMovieClip.prototype.reset = function () {\r\r        var dist, norm, movie_height, movie_width;\r\r        movie_height = 768;\r\r        movie_width = 1024;\r\r        speed = Math.random()*2+1;\r\r        targx = Math.random()*(movie_width-_width);\r\r        targy = Math.random()*(movie_height-_height);\r\r        dist = _root.getdistance(_x, _y, targx, targy);\r\r        norm = speed/dist;\r\r        diffx = (targx-_x)*norm;\r\r        diffy = (targy-_y)*norm;\r\r};\r\r\r\r\r\rMovieClip.prototype.move = function () { var cycle;\r\r        cycle = 100;\r\r        if (_root.getdistance(_x, _y, targx, targy)>speed) {\r\r                x += diffx;\r\r                y += diffy;\r\r        } else {\r\r                x = targx;\r\r                y = targy;\r\r                if (!this.t) this.t = getTimer();\r\r                if (getTimer()-this.t > cycle) {\r\r                        reset();\r\r                        t = 0;\r\r                }\r\r        }\r\r        _x = x;\r\r        _y = y;\r\r};\r\r\r\rfor(m in _root){\r\r        _root[m].x = _root[m]._x;\r\r        _root[m].y = _root[m]._y;\r\r        _root[m].reset();\r\r}
\r
thanks for applying the newbie filter sB,\r\ri didn’t have any luck though… the files at:\rhome.teleport.com/~quadpod/thankssb/\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