Hello MegaGewinnSpiel,
Since I was looking for a similar effect I investigated the generated code from Stencyl and tried to do a runtime or dynamic load and attach of a behavior.
Previously I used a selfmade extension but I always thought that there should/could be a better approach.
The thing I tested is fairly simple so I could have overlooked some things.
The behavior you need to add with the Actor.hx addBehavior code needs to be of type Behavior.
The Behavior new initialisation code needs several things to be able to run. I'm not too sure about the input values I selected, but my test worked.
Actor -Behavior: MyTest
In behaviors.xml ( Location: %AppData%\Stencyl\stencylworks\games-generated\YourGame\Assets\data )
snippet attachedevent="false" class="scripts.Design_6_6_MyTest" classname="scripts.Design_6_6_MyTest" desc="" description="" design="true" drawOrder="0" id="6" name="MyTest" oid="-1" package="scripts" scenespecific="false" shared="false" type="actor">
So I take name: MyTest, Class scripts.Design_6_6_MyTest and type "actor" from the xml reference.
In the example I created an actor using the [create actor at x: y: [front] ]
You don't need to investigate your generated behavior.xml file. This code will list all the behaviors of the game with the classname and the ID.
for(key in com.stencyl.Data.get().behaviors.keys()){
trace("Behavior Name: "+com.stencyl.Data.get().behaviors[key].name);
trace("Behavior ID: "+com.stencyl.Data.get().behaviors[key].ID);
trace("Behavior ClassName: "+com.stencyl.Data.get().behaviors[key].classname);
trace("===");
}
This is a hardcoded example, but you could use the code above to get the classname from the array.
var abcd:com.stencyl.behavior.Behavior=new com.stencyl.behavior.Behavior(getLastCreatedActor(), Engine.engine,6,"MyTest","scripts.Design_6_6_MyTest",true,true,new Map<String,com.stencyl.behavior.Attribute>(),"actor",true);
abcd.initScript();
getLastCreatedActor().addBehavior(abcd);
Again, I'm not sure what variables can be ignored/changed since I am doing pretty much everything with trial and error.
The attributes is something I don't need but that could be a challenge to get right as well!
Hope it helps you.
Best regards from
M.E.