0

If I have a list of items in an array that represent the names of modules:

var phaseNames:Array = new Array("directorsPrep", "checkIO", "pickupPhoto", "pickupPhoto", "syncing", "dailies", "pictureEdit", "soundEdit", "soundMix", "colorCorrection", "finishing");

and I want to go through each one of these and call a function within each instance of each module, how would I go about doing so. So far, I have the following:

private function changeStartViewDate(numDays:Number):void
{
    startViewDate = rightDate(startViewDate.getMonth(), startViewDate.getDate() + numDays, startViewDate.getFullYear());
    getDateInfo();
    determineCalendarWeek();
    var phaseNames:Array = new Array("directorsPrep", "checkIO", "pickupPhoto", "pickupPhoto", "syncing", "dailies", "pictureEdit", "soundEdit", "soundMix", "colorCorrection", "finishing");

    for (var i:int = 0; i < wholeProject.length; i++)
    {
        wholeProject[i].moveProject(Number((1-2) * numDays));
    }
    for (i = 0; i < phaseNames.length; i++)
    {
        for (var j:int = 0; j < [phaseNames[i]].length; j++)
        {
            [phaseNames[i]].movePhase(Number((-1) * numDays));
        }
    }
}

But when I try to save it, I get the following error:

1084: Syntax Error: expecting identifier before dot.

It's telling me the error is on the following line:

[phaseNames[i]].movePhase(Number((-1) * numDays));

I tried doing something like the following, but it didn't work:

[phaseNames[i].movePhase(Number((-1) * numDays))];

The above attempt of trying to figure this out gave me the following error

1064: Invalid metadata.

Any help would be appreciated.

1 Answer 1

1

I am going to assume that:

  1. Each value of your phaseNames array references an actual instance of some other class [and not the name of the class]
  2. The instance defined in the phaseNames array is a child of the current class.

You should be able to do something like this:

var childName = phaseNames[0];
var myChild : myObjectType = this[childName];
// then call function
myChild.doStuff();

This approach is not dissimilar to what you have; I'm just doing it in more lines. I'm also adding the this keyword to access the child.

I bet if you tried this, directly, it would work:

this[phaseNames[i]].movePhase(Number((-1) * numDays));

I have to wonder why you haven't created an array of all the instances instead of an array of all the variables names that point to the instances.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.