          */
         public function addElementAt(c:Object, index:int, dispatchEvent:Boolean = true):void
         {
-            if (c is IUIBase)
-            {
-                addChildAt(IUIBase(c).element as DisplayObject, index);
-                IUIBase(c).addedToParent();
-            }
-            else
-                addChildAt(c as DisplayObject, index);
+            COMPILE::AS3 {
+                if (c is IUIBase)
+                {
+                    addChildAt(IUIBase(c).element as DisplayObject, index);
+                    IUIBase(c).addedToParent();
+                }
+                else
+                    addChildAt(c as DisplayObject, index);
+            }
+            COMPILE::JS {
+                var children:Array = internalChildren();
+                if (index >= children.length)
+                    addElement(c);
+                else
+                {
+                    element.insertBefore(c.positioner,
+                        children[index]);
+                    c.addedToParent();
+                }
+
+            }
         }
 
         /**

         *  @playerversion AIR 2.6
         *  @productversion FlexJS 0.0
         */
        public function removeBead(value:IBead):IBead	
        {
            var n:int = _beads.length;

////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.core
{
    import org.apache.flex.utils.MXMLDataInterpreter;

    COMPILE::AS3 {
