0

Possible Duplicate:
How to fix Array indexOf() in JavaScript for IE browsers

I am using three.js and when I am adding camera to the scene it is alerting error the

Object doesn't support property or method 'indexOf'

My code is

<script src="build/Three.js"></script>
<script>
        var container;
        var camera, scene, renderer, objects;
        var particleLight, pointLight,theta = 45;
        var materials,k=0;

        init();
        animate();

        function init()
        {
            container = document.createElement('div');
            document.body.appendChild(container);

            camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
            camera.position.set( 0, 200, 800 );

            scene = new THREE.Scene();
            scene.add(camera);
         }
</script>

The indexOf function is used in Three.js file with following code

add:function(a){if(a===this)console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");else if(-1===this.children.indexOf(a)){void 0!==a.parent&&a.parent.remove(a);a.parent=this;this.children.push(a);for(var b=this;void 0!==b.parent;)b=b.parent;void 0!==b&&b instanceof THREE.Scene&&b.__addObject(a)}}
Community
  • 1
  • 1
heyanshukla
  • 701
  • 8
  • 17
  • Your posted code doesn't show any use of `indexOf`. If `Three.js` is using it, quote where. `indexOf` is a function on `String` and `Array` instances, but older versions of IE don't have `Array#indexOf` (they do have `String#indexOf`). – T.J. Crowder Apr 26 '12 at 09:41
  • @T.J.Crowder i have added the problematic code in my question and I am using IE9.. – heyanshukla Apr 26 '12 at 09:45
  • @Gazler I show the refered question by you.But how would I use it in my edited question to eovercome the problem?? – heyanshukla Apr 26 '12 at 09:47
  • Good deal, that tells us that this is indeed answered by the earlier question linked above. (If `Three.js` is a library you got from somewhere, **they** should be ensuring that `Array.prototype` has `indexOf`; I'd report this as a bug.) – T.J. Crowder Apr 26 '12 at 09:47
  • @T.J.Crowder I show the answers but couldn't get what to change in my script :( – heyanshukla Apr 26 '12 at 09:47
  • The short version of that question and its answers is: Add this code to your script, anywhere prior to your first use of the code from `Three.js`: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/IndexOf#Compatibility – T.J. Crowder Apr 26 '12 at 09:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10537/discussion-between-heyanshukla-and-t-j-crowder) – heyanshukla Apr 26 '12 at 09:58

0 Answers0