-
Random Position
I have an animated movie clip that I would like to have loop on the main stage, but each time it plays, it appears in a random location. Also, I need to constrain it to the dimensions of the stage.
I'm really quite new to this, so I'm sure this is a simple thing to do, but I'm completely lost and in need of help. Thanks in advance!
-
AS2...code on the main timeline.
Code:
function randMove(myMC) {
var myLim = myMC._totalframes;
var maxX = Stage.width-myMC._width;
var maxY = Stage.height-myMC._height;
myMC.onEnterFrame = function() {
if (this._currentframe == myLim) {
myMC._x = Math.floor(Math.random()*maxX);
myMC._y = Math.floor(Math.random()*maxY);
}
};
}
randMove(animatedmovieclipinstancename);
-
That's starting to do the trick!
It's now moving randomly throughout the movie clip - but there's two small hiccups:
1 - it is sometimes cut-off, extending beyond the stage width and/or height
2 - it only appears to be moving up and down the left side of the stage - it never goes to the right side.
Do I need to change some of the code to fix this?
-
1. Code needs to be changed if registration of movie clip is not in upper left.
2. Did you re-type it? (Look for typos in your code).
-
I found out the source of the problem. One element of the movie clip wasn't aligned like the others, which was causing the clipping on the left side.
Works perfectly, now. Thank you very much dawsonk!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|