Using dynamic variables with Load Vars

HI All,

I am writing actionscript to get variables from a database using php. I have used the LoadVars object and can set a variable using the following line of code which works


In this case myLoadVar is an instance of the Loadvars class and display1 is one of a series of variables sent from php.

I need to make the right hand side of the expression dynamic eg(display1, display2, display3 etc)

I have tried using eval but it does not work.

Thanks for any help.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can try this. Just take note that i = 0 at the start so you might want to change that to var i = 1 if ever you want to start from 1.

for(var i = 0; i<somenumber; i++){
     _root["show"+i] = myLoadVar["display"+i];

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RICHARDHAuthor Commented:
Many thanks for the help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.