DEVPPL
http://www.devppl.com/forum/

Simple Javascript variable problem
http://www.devppl.com/forum/viewtopic.php?f=49&t=13707
Page 1 of 1

Author:  sairus [ Thu Jun 18, 2009 9:17 am ]
Post subject:  Simple Javascript variable problem

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!

Author:  panzer [ Sat Jun 20, 2009 3:20 am ]
Post subject:  Re: Simple Javascript variable problem

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

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

When you need the file, just use its index pos.
Code:
   placeholder.loadMovie(arr[idx]);
   idx++;

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/