Hello,
Here is what I am trying to do:
I have four circles in four different positions. On top of each circle I have a randomly generated number.
What I would like is to position the numbers randomly on top of the four circles (each above its own circle).
While I can generally read and understand AS, I am still very new to it, and I don’t know the proper method for achieving this.
I thought possibly getting the values for the _X and _Y of each number (the numbers are stored in a dynamic text field) from an array.
I was able to find a script which retrieves a random value from an array:
// START - Random value from array //
Array.prototype.randySelect = function(vSelect)
{
var temp = this.slice(0);
var result = new Array();
var i = ((vSelect==null||vSelect>this.length) ? this.length : Math.round(vSelect));
var x;
while(i--)
{
x = random(temp.length);
result* = temp[x];
temp.splice(x,1);
}
return result;
}
position_x = new Array("446.95","572.95");
position_y = new Array("107.2","236.9");
position_x_final = position_x.randySelect(1);
position_y_final = position_y.randySelect(1);
// END - Random value from array //
//This seems to be the problem area//
the_right_answer._x = position_x_final;
trace(position_x_final);
trace(position_y_final);
trace(the_right_answer._x);
Here is what happens when I test my movie:
-
trace(position_x_final) returns either “446.95” or “572.95” (without the quotes)
-
trace(position_y_final) returns “107.2” or “236.9” (again, without the quotes)
-
trace(the_right_answer._x) returns the current position of the number (this is the value that I want to match position_x_final)
-
When I change “the_right_answer._x = position_x_final;” to something like “the_right_answer._x = 15;” the object is positioned correctly (_x=15)
Please let me know what I need to change to make this code work, or if there is a better solution to accomplish what I am trying to do.
Thanks!