Skip to main content
Inspiring
July 30, 2010
Question

How do I handle incremented varibles inside of URLRequest()

I am trying to set up a series of URL links inside a cycling button.  However, when I try to use the variable, the link sends me to the variable name instead of the URL.  Below is a snippet of the code:

//URL variables

var lk1="http://www.firstlink.com";
var lk2="http://www.secondlink.com";
var lk3="http://www.thirdlink.com";
//

var myCount:Number=1;

//
   navigateToURL(new URLRequest(lk[myCount]);
//

if I use the above code I get the error "Error #1010: A term is undefined and has no properties."

navigateToURL(new URLRequest(lk+[myCount]);

If I use this code I get the error "1120: Access of undefined property lk."

navigateToURL(new URLRequest("lk"+[myCount]);

And if I use this code it links me to "lk1" rather than the variable value of the link.

What is the proper code to get an incremented variable to work inside of the URLRequest ????

Ce sujet a été fermé aux réponses.

1 commentaire

Ned Murphy
Legend
July 30, 2010

Try using:

   navigateToURL(new URLRequest(this["lk"+String(myCount)]);

When you use bracket notation you build the whole variable/instance name string inside the brackets.

Inspiring
July 30, 2010

Yes.  That worked.  Thank you very much.

Ned Murphy
Legend
July 30, 2010

You're welcome