It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Simple Javascript variable problem

Simple Javascript variable problem

Postby sairus on Thu Jun 18, 2009 8:17 am

Sorry for actually asking this as it's a ridiculously simple problem, but I'm brand new to JavaScript.
I know how to do what I want to in ActionScript, but I'm not sure what the syntax is to accomplish it in JavaScript.
In ActionScript I've written a chunk of code that looks something like this:

---------------

var currentNumber = 1;
var picture1Video = " firstVideo.jpg";
var picture2Video = " secondVideo.jpg";

placeHolder1.loadMovie(this["picture"+(currentNumber)+"video"])

currentNumber++;

placeHolder2.loadMovie(this["picture"+(currentNumber)+"video"])

---------------


So basically I'm incrimenting currentNumber to change what variable placeHolder1 and placeHolder2 are looking at.

How do I write that in Javascript, so that a variable name being called is made up of a string and the contents of another variable, like ["picture"+currentNumber+"video"] ?

Cheers for any help!
sairus
 
Posts: 1
Joined: Thu Jun 18, 2009 8:15 am

Re: Simple Javascript variable problem

Postby panzer on Sat Jun 20, 2009 2:20 am

I have no idea what actionscript does, but how about an array?

Code: Select all
var arr = new Array("firstvideo.jpg", "secondvideo.jpg");
var idx = 0;

When you need the file, just use its index pos.
Code: Select all
   placeholder.loadMovie(arr[idx]);
   idx++;
panzer
 
Posts: 7
Joined: Mon Nov 17, 2008 5:50 am


Who is online

Users browsing this forum: No registered users and 4 guests