Instantiate Typecasting

I am using Javascript and Unity iPhone to Instantiate a game piece. It works fine in the desktop version, but on the iPhone it doesn't work because it isn't the same type.

I am trying to parent this spawned object to a board, but Instantiate returns an Object and not a GameObject/transform, so I can't access the parent property. I read that a Transform is actual returned by Instantiate, but I can't typecast like you can in C#:

C#

Transform piece = (Transform)Instantiate(..); // I usually use JS, this may not be 100% correct

But this does not work in Javascript, and in standard Javascript you usually do Number(...) or .toString, etc. How would I set the parent of this spawned object using Javascript, or how would I typecast it to a transform?

var returnedObj : Transform;
returnedObj = Instantiate(...);

Is that what you want to do? Your question was sort of unclear.

But if you have #pragma strict on, then this doesn't work. Or at least, it doesn't for me. So I have the same question: how do you typecast from a more general type (Object) to a more specific type (e.g. GameObject), in order to satisfy the strict typechecking?

You've got to cast it to a transform, then you can get the gameObject or any other components.

Transform g = (Transform) Instantiate(indicatorPrefab, new Vector3(0,0,0), Quaternion.identity); GameObject obj = g.gameObject; GUITexture gui = g.gameObject.GetComponent();

var thing:GameObject=Instantiate(prefabThing,pos,rot) as GameObject;

this will not give errors with #pragma strict. another on to look out for is the for(thing in things) loop.

for(var thing:GameObject in things as Gameobject)

i think that’ll work