# Set \_X and \_Y value from Array

**URL:** <https://forum.kirupa.com/t/set--x-and--y-value-from-array/300512>\
**Category:** flash\
**Created:** [November 23, 2009, 12:30am UTC](https://forum.kirupa.com/t/set--x-and--y-value-from-array/300512 "2009-11-23T00:30:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian\_nathaniel](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@brian\_nathaniel](https://forum.kirupa.com/u/brian_nathaniel)\
**Post date:** [November 23, 2009, 12:30am UTC](https://forum.kirupa.com/t/set--x-and--y-value-from-array/300512/1 "2009-11-23T00:30:38Z")

</div>

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:

```auto

// 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!
