# Reparenting exercise

**URL:** <https://forum.kirupa.com/t/reparenting-exercise/284717>\
**Category:** flash\
**Created:** [March 22, 2009, 10:23pm UTC](https://forum.kirupa.com/t/reparenting-exercise/284717 "2009-03-22T22:23:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thick](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@Thick](https://forum.kirupa.com/u/Thick)\
**Post date:** [March 22, 2009, 10:23pm UTC](https://forum.kirupa.com/t/reparenting-exercise/284717/1 "2009-03-22T22:23:00Z")

</div>

hello all. i’m trying to follow a reparenting exercise out of a book that i’ve purchased, but for one reason or another the script isn’t properly being executed.

the script is suppose to draw two squares, with a ball in one of them. when the ball is clicked, it should move to the other square. Here is the error that is showing up…

![](http://img.photobucket.com/albums/v257/Thought/reparentingissue.jpg)

and here is the script that i’ve written…

```auto
 
package {
 import flash.display.Sprite;
 import flash.events.MouseEvent;
 
 public class Reparenting extends Sprite {
  private var parent1:Sprite;
  private var parent2:Sprite;
  private var ball:Sprite;
 
  public function Reparenting() {
   init();
  }
  private function init():void {
   parent1 = new Sprite();
   addChild(parent1);
   parent1.graphics.lineStyle(1, 0);
   parent1.graphics.drawRect(-50, -50, 100, 100);
   parent.x = 60;
   parent.y = 60;
 
   parent2 = new Sprite();
   addChild(parent2);
   parent2.graphics.lineStyle(1, 0);
   parent2.graphics.drawRect(-50, -50, 100, 100);
   parent.x = 170;
   parent.y = 60;
 
   ball = new Sprite();
   parent2.addChild(ball);
   ball.graphics.beginFill(0xff0000);
   ball.graphics.drawCircle(0, 0, 40);
   ball.graphics.endFill();
   ball.addEventListener(MouseEvent.CLICK, onBallClick);
  }
 
  public function onBallClick(event:MouseEvent):void
  {
   parent2.addChild(ball);
  }
 }
}

```

appreciate the help.
