# \[CS3 & AS2\] Using Data Instead of Derivation to Refine Behavior in AS2?

**URL:** <https://forum.kirupa.com/t/cs3-as2-using-data-instead-of-derivation-to-refine-behavior-in-as2/300902>\
**Category:** flash\
**Created:** [November 30, 2009, 8:15am UTC](https://forum.kirupa.com/t/cs3-as2-using-data-instead-of-derivation-to-refine-behavior-in-as2/300902 "2009-11-30T08:15:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clc2007](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@clc2007](https://forum.kirupa.com/u/clc2007)\
**Post date:** [November 30, 2009, 8:15am UTC](https://forum.kirupa.com/t/cs3-as2-using-data-instead-of-derivation-to-refine-behavior-in-as2/300902/1 "2009-11-30T08:15:13Z")

</div>

I’m working on my first AS2 project and could use some advice. I’m trying to create two types of objects, a soldier and a villager, using a shared NPC class:

```auto
 
class ObjNpc extends MovieClip
{
 public function onLoad()
 {
  trace(_level.legalStateNames); // this is the list of legal states
 }
 // state machine code follows...
}

```

The ObjNpc class will know how to handle three states – “Idle,” “Fight,” and “Run” – but I want soldiers to never enter the “Run” state and villagers to never enter the “Fight” state.

Also, I want to create the soldier and villager objects in separate flash files, which will be loaded into the scene at runtime.

So, the Soldier.FLA and Villager.FLA files will each contain a movie clip that derives from the ObjNpc class, but how can I specify their list of “legal” states without deriving a separate class for each one?

This seems like a reasonable place to use component properties, using strings like “Idle;Fight” and “Idle;Run,” but for various reasons I can’t use components on this project. I also can’t use anything but AS2.

I tried adding a line to each object’s flash file in frame 0, like this:

// Soldier.FLA contains this line of code in frame 0:  
\_level.legalStateNames = [“Idle”, “Fight”];

// Villager.FLA contains this line of code in frame 0:  
\_level.legalStateNames = [“Idle”, “Run”];

This approach won’t work if a scene contains both a soldier and a villager, because the second object to load will overwrite \_level.legalStateNames, so both NPCs will end up sharing the same state table.

Is there any way to specify data like this in a FLA file? I really don’t want to make separate classes for each type, since their behaviors are so close. Component properties seem like a natual fit, except I can’t use them for other reasons. Are there any other options?

Thanks!
