# Help with class reuseability problem

**URL:** https://forum.kirupa.com/t/help-with-class-reuseability-problem/277671
**Category:** Uncategorized
**Created:** [December 15, 2008, 6:52pm UTC](https://forum.kirupa.com/t/help-with-class-reuseability-problem/277671 "2008-12-15T18:52:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JTF2](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@JTF2](https://forum.kirupa.com/u/JTF2)
#### Post date: [December 15, 2008, 6:52pm UTC](https://forum.kirupa.com/t/help-with-class-reuseability-problem/277671/1 "2008-12-15T18:52:51Z")

</div>

Hi I have a class that was working fine on its own but is now running into a problem as I try to restructure it in a way to make it more reusable.

Heres the class:

```auto

package 
{
 import flash.display.Sprite;
 import flash.display.DisplayObject;
 import fl.transitions.Tween;
 import fl.transitions.easing.Strong;
 
 public class ImageRotater extends Sprite 
 {
  private var numImages:int;
  private var duration:int;
  private var image:DisplayObject;
  private var tween:Tween;
 
  public function ImageRotater(image:DisplayObject, numImages:int, duration:int) 
  {
   this.image = image;
   this.numImages = numImages;
   this.duration = duration;
   addImages();
   runTweens();
  }
 
  private function addImages():void
  {
   for (var i:int = 0; i < numImages; i++) 
   {
    addChild(image);
   }
  }
 
  private function runTweens():void
  {
   for (var j:int = 1; j < numImages; j++) 
   { 
    tween = new Tween(getChildAt(j), "rotation", Strong.easeOut, 0, ((360/numImages) * j), duration, true);
   }
  }
 }
}

```

and heres how I’m instantiating it: (Image is an exported movieclip with Image as its class name)

```auto

var ir = new ImageRotater(new Image(), 7, 5);

```

the error im getting is:

RangeError: Error #2006: The supplied index is out of bounds.  
at flash.display::DisplayObjectContainer/getChildAt()  
at ImageRotater/runTweens()  
at ImageRotater()  
at Main

as I said I was having no trouble when I wasnt passing Image to it and instead instantiating Image in the addImages() method as in:

```auto

private function addImages():void
  {
   for (var i:int = 0; i < numImages; i++) 
   {
image = new Image();    
addChild(image);
   }
  }

```

any ideas? thanks
