I'm writing a plugin that creates new instances of objects that exist in the layout.
The SDK Runtime reference has this to say about runtime.createInstance:
[quote:1v5c1z11]runtime.createInstance(type, layer)
Create a new instance of the object type on the given layer. Returns a reference to the created instance.
After some searching the source (and a bit of trial-end-error) I was able to find a way get a reference to a type by its name:
function createObject(typeName,x,y) {
var type = null;
for( var i=0; i<runtime.types_by_index.length; ++i ) {
if( runtime.types_by_index[i].name === typeName ) {
type = runtime.types_by_index[i];
}
}
var layer = runtime.getLayerByName("game-elements");
var object = runtime.createInstance(type,layer);
return object;
};
[/code:1v5c1z11]
This code works just fine in the development environment. I pass the [b]typeName[/b] of the object, like "cardBackground" or "playButton" and voila, new instances. However, when I export the project to an HTML5 website this code no longer works. This is because the [b]name[/b]s of the types appear to have been transformed. The new names are strings like "t0" or "t1".
So what is the best way to locate an object instance (or perhaps an instance-type) to use when calling runtime.createInstance?