Okay, so I'm making an animation in which i want a movie clip to fade in at a random spot each time it fades in. I went ahead and made a movie clip, added my motion tween but I'm having trouble with the random part. so i tried to add some action script on the first frame of the movie clip that tells the movie clip to be in position(x,y) where x and y are random, i went ahead and searched the internet and found out how to make a random number but i could not find how to define a location in flash
Okay, here is an example of what i have
Animation: http://www.truploader.com/view/404168
Download Link: http://www.truploader.com/view/944774
And the code for the random number is as follows: Math.floor(Math.random()*(1+High-Low))+Low; where high is the highest integer you want, and low is the lowest integer you want.
Better explained here: http://www.kirupa.com/developer/actionscript/tricks/random.htm
So kind of what i want to do is somewhat along the lines of
movieclip location(
Math.floor(Math.random()*(1+High-0))+0;,Math.floor(Math.random()*(1+High-0))+0;)
where low is 0 for that would be the lowest dimension on the canvas and high would be your dimensions for x and y respectively
ActionScript Help
Started by: Tortuga | Replies: 3 | Views: 610
Jan 24, 2010 5:44 AM #540088
Jan 24, 2010 1:47 PM #540189
i'm not 100% sure what you're asking...
do you want to have the movie clip move to a random position on the stage each time the animation finishes, and then play again?
because if that's what you're trying to do you're doing it completely wrong
the script for the random position of the movie clip would look more like
movieclip._x = (random(Stage.width) + 1)
movieclip._y = (random(Stage.height) + 1)
EDIT that's AS2, i expect AS3 is similar if that's what you're using
do you want to have the movie clip move to a random position on the stage each time the animation finishes, and then play again?
because if that's what you're trying to do you're doing it completely wrong
the script for the random position of the movie clip would look more like
movieclip._x = (random(Stage.width) + 1)
movieclip._y = (random(Stage.height) + 1)
EDIT that's AS2, i expect AS3 is similar if that's what you're using
Jan 24, 2010 6:52 PM #540270
That is exactly what i am asking, and i'm using AS2
is there anything i have to edit in that script to make it work with mine or is it a premade script?
Because it doesn't work when i insert it into the first frame of my movie clip
is there anything i have to edit in that script to make it work with mine or is it a premade script?
Because it doesn't work when i insert it into the first frame of my movie clip
Jan 25, 2010 10:39 AM #540477
that was just an example of how it ought to look, not the whole code
put this on the frame
and put this on the last frame of the movieclip
put this on the frame
_root.movetheclip = true;
onEnterFrame = function(){
if(_root.movetheclip == true){
MOVIECLIPINSTANCENAME._x = (random(Stage.width) + 1)
MOVIECLIPINSTANCENAME._y = (random(Stage.height) + 1)
_root.movetheclip = false;
}
}
and put this on the last frame of the movieclip
_root.movetheclip = true;