I’ve searched the internet, and found similar problems, but definitely not the same. Here’s what I’m trying to do:
I’m attempting to make a platform game. Each level is contained within it’s own MovieClip, which has it’s own class. Each of these classes extend the Level class, which provides basic functionality for all levels.
Each individual level has a numPlatforms variable which stores the number of platforms in that particular level. I currently have a for loop that runs from 1-numPlatforms and sets the level area (the image, more or less) the platform contains:
for(var i:int = 1; i<=_numPlatforms; i++)
{[INDENT]this["platform" + i].gotoAndStop(_levelArea);
[/INDENT]
[INDENT]switch (_levelArea)[/INDENT]
[INDENT]{
[/INDENT]
[INDENT=2]case AREA_1:
[/INDENT]
[INDENT=3]this["platform" + i].offset = 15;
[/INDENT]
[INDENT=3]break;[/INDENT]
[INDENT=2]default:[/INDENT]
[INDENT=3]break; // no need to set anything, as platforms have their own default value
[/INDENT]
[INDENT]}
[/INDENT]
}
This works to a degree, but the big drawback is that every time I want to change the number of platforms in a level, I need to go into the class and change the numPlatforms variable.
What I would like to do is simply check if a platform exists, then initialize it, otherwise stop initializing platforms. Here’s what I’m thinking:
var i:int = 1;
while (true)
{[INDENT]if (this["platform" + i])[/INDENT]
[INDENT]{[/INDENT]
[INDENT=2]this["platform" + i].gotoAndStop(_levelArea);[/INDENT]
[INDENT=2]switch (_levelArea)[/INDENT]
[INDENT=2]{
[/INDENT]
[INDENT=3]case AREA_1:[/INDENT]
[INDENT=4]this["platform" + i].offset = 15;[/INDENT]
[INDENT=4]break;[/INDENT]
[INDENT=3]default:
[/INDENT]
[INDENT=4]break; // no need to set anything, as platforms have their own default value[/INDENT]
[INDENT=2]}[/INDENT]
[INDENT]}[/INDENT]
[INDENT]else[/INDENT]
[INDENT]{
[/INDENT]
[INDENT=2]trace("platform is not in this level");
[/INDENT]
[INDENT=2]break;
[/INDENT]
[INDENT]}[/INDENT]
[INDENT]i++;
[/INDENT]
}
However, whenever I try to run this code, Flash gives me the following error:
“Property platformX not found on Level1 and there is no default value.” where X is numPlatforms + 1.
Is there any way to check if a variable exists within a MoveClip? I’ve trying comparing it to null and also to undefined, but neither works.
Thanks in advance for any help.