Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Array 1

Status
Not open for further replies.

styleBunny

Technical User
Jun 20, 2002
133
0
0
AU
Hi Guys,

I am trying to use an array to store numbers generated at random, using the below script:

function mouseUp(Javatest) {
//javascript
var myArray = new Array();
Javatest = test
myArray.push(Javatest);
trace(myArray);
}

Where 'test' contains the randomly generated number during a mouse down event.

Tho this creates a new array called myArray each time, and the value from the previous array is lost.

i tried to create the array "myArray" as an exit frame event, earlier in the movie like so:

function exitFrame(me) {
//javascript
var myArray = new Array();
}

When it comes time to access myArray, it says "reference error, myArray is not defined".

So i presume i need to make the scope of myArray global?

Any help and love would be appreciated :) This is the first time i have used js in director.

Paul.
 
function mouseUp(){
if(typeof(myArray) != "object"){
myArray = new Array
}
test = Math.round(Math.random()*10)
myArray.push(test)
trace(myArray)
}
 
Thanks again Kenneth, i hadn't used the typeof function before. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top