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.
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 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:
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._xOR_root[“example”]._xBUT 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:
== // 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.
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
Creating engaging and entertaining content for designers and developers since 1998.