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…
and here is the script that i’ve written…
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.