Hey all. New here to the forums and wondering if some of you could prehaps help me out. I’m making a MC that will choose a random variable for the Y axis. Here is what it is going to do: The script will choose a variable number between 1 and 10. Then, depending on the variable, the MC will have it’s x coordinate stay the same but the y variable will make the MC move upwards that many pixels. My question is, how do I get it so that the MC will move the number that was randomly picked? Thanks all!

easily done. :slight_smile: \r\rOn the first frame of your movie, place this code on an action script layer (a layer that contains nothing but action script, which you create, to keep things neat and tidy, it is not a layer type that you’ll find in Flash anywhere).\r\rclipMover=Math.random()*10+1;\r\r\rNow… select the movie clip, and open the action panel (if it’s not already open). With the movie clip selected, enter the following code into the action panel\r\ronClipEvent(enterFrame){\r this_y+=clipMover;\r}\r\r\r-------------------------------\rThe first part of this code sets the random number. As of Flash5.0 we are using this new method of the Math object called Math.random(); Multiply Math.random() times any number and you will get a random number between 0 and that number minus one. So we multiply it first, then add 1 to it to make it 1 - 10.\r\rThe onClipEvent is a Flash 5.0 code that is attached to movie clips the way that “on” events are placed on buttons. This particular one, onClipEvent(enterFrame){} creates a loop which repeats anything in the container handles “{}” every time this movie clips play head enters one of it’s frames.\r\rthis._y+=clipMover;\r\rsimple states… set this objects _y coordinate to whatever it is right now, plus the value of the variable “clipMover”.

ooo… and if I’m making a mistake and all you’re looking to do is move the clip a single time, then all you really need is this on the main timeline.\r\rclipMover=Math.random()*10+1;\rtheMovieClipIWantToMove._y+=clipMover;\r\rreplace “theMovieClipIWantToMove” with the instance name of your movie clip.

Well, I guess


would be better, since you don’t want your clip to move by 5.2253365478 pixles, do you ? :smiley: You can also round the darn number.\r\rpom 0]

Hey guys thanks for all your help! Unfortunately, I have never used Actionscript before and am not getting anything. Here is what I have:\r\rIn the main scene I have two layers. One is a layer with a keyframe in layer 1 and the text movieclip symbol. The other layer has actionscript that says:\r\rclipmover = “random(75)+1”;\r\rThen, the actionscript contained in my movie clip contains the following actionscript:\r\ronClipEvent (enterFrame) {\r this._y+=clipmover;\r}\r\rWhen I test my movie, nothing happens… If someone could tell me what I am doing wrong it would be greatly appreciated!

ok… three things to check on.\r\rclipmover = “random(75)+1”;\r\rshould be\r\rclipmover = random(75)+1;\r\rclick on it in the action script panel and then click on the appropriate check box at the bottem of the panel to change that to an expression.\r\rsecond thing is… that action script \r\ronClipEvent (enterFrame) {\rthis._y+=clipmover;\r}\r\rshould not be INSIDE the movie clip. Go to the main timeline, select the clip. Click inside the action panel, and paste that. It should be contained on the outside of the clip, not on a timeline.\r\rThird thing to check is to make sure that the object you’re trying to effect, ie the text, is in fact a movie clip. This you check in the instance panel. Open it, select the text. It should have the symbol for a movie clip. If it is not, select it, and hit F8, select movie clip from the options provided and give it a library name.

OK upnaut. Checked all three things and the stupid text just sits there…Could I possibly send you the .fla for you to look at? It’s really frustrating! \r\rThanks!

yes… my email is back up and running.\r\r[email protected]


I’m trying to get ahold of that. I’ll tell you tomarrow, if I did. You might have to resend it to another account of mine. :slight_smile:

Hey upnaut…It’s been a couple of days and I’m just wondering if you forgot about the file. Maybe if you could let me know whether you recieved it or not?

nah… just been having problems with my mail, and then I had to paint a house this weekend. I believe I did get the file and I will be opening it tomarrow sometime. Thanks for being patient.