• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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