Jump to content

How Do I Increment A Variable Name Loop


calmchess

Recommended Posts

Here's two options. You could do it a couple other ways too but I don't really know what you're doing since you didn't show code.

 

// Wait to Load Page
window.addEventListener("load", function()
{
   // Function
   function myFunc1()
   {
       alert("Function 1");
   }

   // Function
   function myFunc2()
   {
       alert("Function 2");
   }

   // Loop Numbers
   for (var i = 1; i < 3; i++)
   {
       // Evaluate / Execute String
       eval("myFunc" + i + "();");
   }
}, false);

 

// Wait to Load Page
window.addEventListener("load", function()
{
   // Function
   function myFunc1()
   {
       alert("Function 1");
   }

   // Function
   function myFunc2()
   {
       alert("Function 2");
   }

   var myFuncs = [ myFunc1, myFunc2 ];

   // Loop Functions
   for (var i in myFuncs)
   {
       // Execute Function
       myFuncs[i]();
   }
}, false);

  • 3 weeks later...

well I do as I've asked allot in actionscript I suppose I can just push each variables data into an array and then iteriate over the array. I just didn't want to make the extra step. If what I ask were possible then you would have answered diffrently since it would be very basic. I don't have any code to show I'm just asking basic questions. Thanks for your time. Javascript is very verbose anyway so I guess making some extra steps will be well worth the effort.

 

--calmchess

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.