# Strange error with is keyword

**URL:** <https://forum.kirupa.com/t/strange-error-with-is-keyword/252051>\
**Category:** flash\
**Created:** [February 15, 2008, 10:14am UTC](https://forum.kirupa.com/t/strange-error-with-is-keyword/252051 "2008-02-15T10:14:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlash](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@Phlash](https://forum.kirupa.com/u/Phlash)\
**Post date:** [February 15, 2008, 10:14am UTC](https://forum.kirupa.com/t/strange-error-with-is-keyword/252051/1 "2008-02-15T10:14:08Z")

</div>

Ok, so what I’m trying to do is create a function that looks for an Object in an Array with the same Class type as the parameter. This is the function I’m using.

```auto

/**
         * Searches for the first Controller in the Entity with the same Class type as the parameter,
         * and if exists, returns an instance of that Controller.
         * 
         * This should only be used if only one of a type of Controller is expected to exist. 
         * For gathering multiple Controllers, use getAllControllersOfType(cls:Class)
         * 
         * @param cls The Class type of the wanted constructor
         * @return The wanted Controller, otherwise null
         */
        public function getControllerOfType(cls:Class):Controller
        {
            for each(var c : Controller in controllers)
            {
                if(c is cls) {
                    trace("c is cls? "+c is cls);
                    return c;
                }
            }
            return null;
        }

```

In my example, I’m putting in a Controller (for this example, I’m using a PhysicsController) and testing it against a class that has a PhysicsController in it. The trace statement returns “c is cls? true”, and the function is not returning null. Now, in my DocumentClass I’m calling this function again and I’m running a trace statement of

```auto
var c:Controller = player.getControllerOfType(PhysicsController);
trace("c is a PhysicsController? "+ c is PhysicsController+ ". c is null? "+c == null)

// returns "c is a PhysicsController? false. c is null? false"

```

This is also returning the same if I test c as a Controller, but if I test it as an Object, it says it IS an Object. I don’t understand why this is happening.
