Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

AS2 - Create loop for repetitive initializations

Hello,

Oftentimes I'm doing the exact same thing multiple times for multiple instances. For example, in the attached code I'm initializing a reflection for 4 MCs, all sequentially numbered.

I figure there's gotta be a way to simplify this and do it within a loop. The normal code looks like this:

IE_MC.profiles_mc.panel1.reflection.cacheAsBitmap=true;
IE_MC.profiles_mc.panel1.mask.cacheAsBitmap=true;
IE_MC.profiles_mc.panel1.reflection.setMask("IE_MC.profiles_mc.panel1.mask");

IE_MC.profiles_mc.panel2.reflection.cacheAsBitmap=true;
IE_MC.profiles_mc.panel2.mask.cacheAsBitmap=true;
IE_MC.profiles_mc.panel2.reflection.setMask("IE_MC.profiles_mc.panel2.mask");

IE_MC.profiles_mc.panel3.reflection.cacheAsBitmap=true;
IE_MC.profiles_mc.panel3.mask.cacheAsBitmap=true;
IE_MC.profiles_mc.panel3.reflection.setMask("IE_MC.profiles_mc.panel3.mask");

IE_MC.profiles_mc.panel4.reflection.cacheAsBitmap=true;
IE_MC.profiles_mc.panel4.mask.cacheAsBitmap=true;
IE_MC.profiles_mc.panel4.reflection.setMask("IE_MC.profiles_mc.panel4.mask");

So I took that, and tried to create a loop that would do the same thing:

for(i=1;i<5;i++){
      panelNum = String(i);
      curPanel = ["panel"]+panelNum;
      panelPath = "IE_MC.profiles_mc." + curPanel + ".mask";
      IE_MC.profiles_mc.curPanel.reflection.cacheAsBitmap=true;
      IE_MC.profiles_mc.curPanel.mask.cacheAsBitmap=true;
      IE_MC.profiles_mc.curPanel.reflection.setMask("IE_MC.profiles_mc." + curPanel + ".mask");
}            

But it's not working. I'm not getting any errors, but the reflections aren't being initiated. Does anyone have any idea what I'm doing wrong?

Thanks!
0
Spiderstave
Asked:
Spiderstave
1 Solution
 
dgofmanCommented:
try this

for(i:Number = 1; i < 5; i++){
      var mc:MovieClip = IE_MC.profiles_mc["panel" + i];
      mc.reflection.cacheAsBitmap = true;
      mc.mask.cacheAsBitmap=true;
      mc.reflection.setMask("IE_MC.profiles_mc.panel" + i + ".mask");
}
0
 
SpiderstaveAuthor Commented:
Works perfect! Thank you!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now