Loading a different script per level
I have a project that I'm currently working on that is dynamically setup via an XML document.
Each level pulls it's data from individual nodes in that XML document. This way it knows what items to put on the screen, what background image to load, etc.
What I'm trying to figure out, is how to load/unload individual scripts depending on what level is currently loaded.
Say the current level == hotel, so I would want to load scripts that are specific to the hotel level. Maybe my hero walks offscreen and into the alley level. I would need to unload the scripts from the hotel and then load the scripts specific to the alley.
I know that I can include .as files at COMPILE time, but is there a way to pull the code at runtime? Could I store the actual actionScript in the XML file and pull it from there?
<level id="hotel" description="looks like a stinky hotel from the movies" code="door._x+=5;"> </level>
Is something like the above code possible or "allowed"?