# Random Image Move

**URL:** https://forum.kirupa.com/t/random-image-move/119417
**Category:** Uncategorized
**Created:** [August 14, 2004, 4:40pm UTC](https://forum.kirupa.com/t/random-image-move/119417 "2004-08-14T16:40:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TRPlace](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@TRPlace](https://forum.kirupa.com/u/TRPlace)
#### Post date: [August 14, 2004, 4:40pm UTC](https://forum.kirupa.com/t/random-image-move/119417/1 "2004-08-14T16:40:13Z")

</div>

I want to create a random number that will move an image to a set x and y coordinate

var randomNum:Number = Math.round(Math.random()\*(30000-1000))+1000;  
var count:Number = 0;  
if(count=randomNum){  
\_root[matarola].\_x=200  
\_root[matarola].\_y=200  
}  
else{  
count=count+1;  
}

This is the code I have and it does not work. I am a newbie at actionscripting.  
What I did was create a random number and a counter, when the counter=the random number, move the imgae with the instance name “matarola” to (200,200) else count adds one to itself, which, if i did it right, would make the image randomly come down between 1 and 30 seconds. Is there a way to motion it in instead of having it just pop in…and also, I need another function to select a random number, say between 1 and 10…and I will have an array with 10 lines of text that will scroll across the “matarola” pager image, in a certain font I have.

Thanks for your help!!

-TJ

---

<div class="post-metadata">

### Author: ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)
#### Post date: [August 14, 2004, 10:21pm UTC](https://forum.kirupa.com/t/random-image-move/119417/2 "2004-08-14T22:21:28Z")

</div>

have you searched [kirupa.com](http://kirupa.com) already? there a some great tuts about this:  
[http://www.kirupa.com/developer/actionscript/array.htm](http://www.kirupa.com/developer/actionscript/array.htm)  
[http://www.kirupa.com/developer/actionscript/tricks/random.htm](http://www.kirupa.com/developer/actionscript/tricks/random.htm)  
[http://www.kirupa.com/developer/actionscript/setinterval.htm](http://www.kirupa.com/developer/actionscript/setinterval.htm)  
[http://www.kirupa.com/developer/actionscript/random.htm](http://www.kirupa.com/developer/actionscript/random.htm)

maybe some reading will help you out a bit 😃

---

<div class="post-metadata">

### Author: ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)
#### Post date: [August 15, 2004, 12:10am UTC](https://forum.kirupa.com/t/random-image-move/119417/3 "2004-08-15T00:10:07Z")

</div>

```auto
onClipEvent(enterFrame){
	if(_root.count==_root.randomNum){
		_root.matarola._x+= (200-_root.matarola._x)/_root.speed
		_root.matarola._y+= (200-_root.matarola._y)/_root.speed
	}
	else{
		_root.count++ // just a simpler way of writing what you wrote ;)
	}
}

```

on matarola and

```auto
randomNum = Math.round(Math.random()*(290))+10;
count = 0;
speed = 5

```

on the main timeline…  
note you had actually got your numbers wrong… FMX is slower than you thought 😉 it would be around 10 and 300 secs…  
BUT i would reccomend using something MUCH simpler and tidier such as:

```auto
speed = 5
Var1 = setInterval(ease,(Math.Random()*29000)+1000) // note setInterval works in milliseconds!
function easeIn(){
	_root.matarola.onEnterFrame = function(){
		_root.matarola._x+= (200-_root.matarola._x)/_root.speed
		_root.matarola._y+= (200-_root.matarola._y)/_root.speed
	}
}

```

on the main timeline and hey presto…

note that if you address a movieclip with an instance name it is simply _\_root.example.\_x_ **OR** _\_root[“example”].\_x_ **BUT** if you are addressing a movieclip via a variable (ie. you have 3 movieclips called\* ex1\*, _ex2_ and _ex3_ and the var eg = either 1, 2 or 3) you use _\_root[“ex”+eg].\_x_

note also:

```auto
 == // means *is equal to* and is used for **validation** , ie. an IF statement that checks if a variable is true would use this operator
= // means *now equals* and is used as an **assignment** operator only.

```

the movement code is from a kirupa tut about easing.

Prophet.

---

<div class="post-metadata">

### Author: ![TRPlace](https://avatars.discourse-cdn.com/v4/letter/t/6de8d8/32.png) [@TRPlace](https://forum.kirupa.com/u/TRPlace)
#### Post date: [August 16, 2004, 7:16pm UTC](https://forum.kirupa.com/t/random-image-move/119417/4 "2004-08-16T19:16:10Z")

</div>

Thanks for all your help, I had the idea in my head but I definately have it doing what I want now. You had a few errors in your code =Þ, the…Random should be random and the ease should be easeIn or the function should just be ease

Thanks again

-TJ
