pragma strict problem with GetComponent and script name

I’m trying to use pragma strict to prepare a file for the iphone. In the file I have
a GameObject and I want to reference a function in another script. I have a function which allows the user to load an object dynamically then attach a script to the object. In this case they load a cow and then attach cowScript.js

This doesn’t work. The error is that initialize() is not a member of Component.

function loadObject(otype:String,oname:String){

//instantiates a cow from resources load first and names it oname



I’m not sure where the problem is or how to fix it. But I do want to have it so the user can name their object and attach different scripts to it. Is there a workaround that would preserve the dynamic script idea.


pretty sure the string-parameter forms of GetComponent and AddComponent don’t work at all in strict mode, so you’d have to refactor to replace those otype+“script” string variables with MonoBehaviors that reference the script, like this…

You also prolly want to keep the gameobject rather than calling find twice, and you definitely don’t want to add the component twice!

enter code here`function loadObject(typeScript:MonoBehavior, name:String)
    //get the object
    var obj:GameObject=GameObject.Find(name);
    //make sure it was there
    if (!obj)
        Debug.Error("Object called \""+name+"\" not found!");
    //add and initialize the component