View Full Version : Suprabeener: A quick Q:
quandary23
May 30th, 2002, 12:36 PM
thanks first: your randomotion code rokks.
i 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...
also, when using multiple clips, should i include the same code for each in the main timeline?
lastly, is there anyway to have each load in random positions?
suprathanks beener!
ilyaslamasse
May 30th, 2002, 01:00 PM
Can I answer too ?
pom 0]
suprabeener
May 30th, 2002, 01:20 PM
thanks quandry,
easiest 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.
you only need define the methods once for all the clips to use them. that's the beauty of methods!
hmmmm, 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:
for(mc in _root)
_root[mc]._x = Math.random()*100;
_root[mc]._y = Math.random()*100;
}
put something like that in frame 1 with the functions etc.
thoriphes
May 30th, 2002, 08:24 PM
no pom, the master has spoken.
quandary23
May 31st, 2002, 02:23 PM
LOL
thanks for the quick reply Sb.
Currently 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.
Opening Flash now to try your code. Will report :)
Thanks again
quandary23
May 31st, 2002, 02:45 PM
Guess I'd better reply + ask Q's in context, apologies in advance for my redardation where applicable :)
***
easiest way to put the clips in the center would be to move them there in the fla.
***
They are all positioned in the main scene of the fla as i would like them to originate the random movement from.
***
hmmmm, do you want them in the center, or randomly spread?
***
it 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.
***
you could just run a bit of code at the start, assuming they're all in _root:
***
I maybe putting this in the wrong place, but now there is no random movement at all. They *are* in their ideal starting positions though.
I tried:
1. dropping it on a new keyframe by itself
2. pasting it into the already existant script code on frame 1.
3. adding it to mc AS
all to varying degrees of failure.
If you could apply a babytalk filter in letting me know where to place the code below, it would be MUCH appreciated :)
R
quandary23
June 1st, 2002, 05:24 PM
well, i'm beat. still can't get this to work. thanks for the orig. effort though - if you get around to it, thanks.
suprabeener
June 2nd, 2002, 12:16 PM
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:
for(mc in _root){
_root[mc].y = _root[mc]._y;
_root[mc].x = _root[mc]._x;
}
or put it individually in each clip in an on load event:
onClipEvent(load){
this.y = this._y;
this.x = this._x;
}
have you changed the range of possible placement to match your movie? the example was made in a 100 x 100 movie.
that 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.
quandary23
June 5th, 2002, 01:57 AM
first of all apologies for the belated nature of this thankful + humble reply to your last attempt to help me.
i tried several placement iterations in trying to include the code you posted with failed results on this end.
i'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.
home.teleport.com/~quadpod/thankssb/ (http://home.teleport.com/~quadpod/thankssb/)
you'll see that circle 03 (my last attempt at inclusion of the code) loads in place, but remains static.
Your review is much appreciated. Feel free to paste the code in the src and email it to me (spiralstares@mac.com) 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
suprabeener
June 6th, 2002, 11:20 AM
i overlooked something in the code ...
if 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.
you can solve this by just forcing the reset method at the beginning.
adding this to frame 1 did the trick:
for(m in _root){
        _root[m].x = _root[m]._x;
        _root[m].y = _root[m]._y;
        _root[m].reset();
}
quandary23
June 7th, 2002, 01:06 AM
thanks suprabeener, glad to read that a solution has been reached!
unfortunately again i have to seek education.
i tried putting the code in several places again:
[1] new layer in frame 1
[2] individually in each clip at the bottom of:
onClipEvent (enterFrame) {
        move();
}
suprabeener
June 7th, 2002, 01:22 AM
just this in each clip:
onClipEvent (enterFrame) {
        move();
}
and all this in frame 1:
// Random Movement: kirupa.com
// Thanks to Suprabeener for the original code!
function getdistance (x, y, x1, y1) {
        var run, rise;
        run = x1-x;
        rise = y1-y;
        return (hyp(run, rise));
}
function hyp (a, b) {
        return (Math.sqrt(a*a+b*b));
}
MovieClip.prototype.reset = function () {
        var dist, norm, movie_height, movie_width;
        movie_height = 768;
        movie_width = 1024;
        speed = Math.random()*2+1;
        targx = Math.random()*(movie_width-_width);
        targy = Math.random()*(movie_height-_height);
        dist = _root.getdistance(_x, _y, targx, targy);
        norm = speed/dist;
        diffx = (targx-_x)*norm;
        diffy = (targy-_y)*norm;
};
MovieClip.prototype.move = function () { var cycle;
        cycle = 100;
        if (_root.getdistance(_x, _y, targx, targy)>speed) {
                x += diffx;
                y += diffy;
        } else {
                x = targx;
                y = targy;
                if (!this.t) this.t = getTimer();
                if (getTimer()-this.t > cycle) {
                        reset();
                        t = 0;
                }
        }
        _x = x;
        _y = y;
};
for(m in _root){
        _root[m].x = _root[m]._x;
        _root[m].y = _root[m]._y;
        _root[m].reset();
}
quandary23
June 7th, 2002, 07:18 PM
thanks for applying the newbie filter sB,
i didn't have any luck though... the files at:
home.teleport.com/~quadpod/thankssb/ (http://home.teleport.com/~quadpod/thankssb/)
are updated for review.
thanks!
suprabeener
June 7th, 2002, 09:56 PM
it seemed to have something to do with white space. very odd.
replacing the spaces in the indents with tabs made it all ok.
quandary23
June 11th, 2002, 03:40 PM
supraB.
It works PERFECTLY.
Your assistance has been more than appreciated and borders on sainthood___<heh>
If you'd like, send your digits to spiralstares@mac.com + i'll mail you the disc when done.
Again, much thanks___.R
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.