【发布时间】:2011-01-24 22:58:00
【问题描述】:
我在这里遗漏了一些基本的东西。我有一个非常简单的自定义类,它绘制了一个圆圈和一个复选框,并且仅在选中复选框时才允许拖动该圆形精灵。一个复选框组件被手动添加到我的 .fla 中的库中。
来自我的 .fla 项目的操作面板:
var ball:DragBall = new DragBall();
addChild(ball);
我的自定义类 .as 文件(与 .swf 位于同一文件夹中)
package
{
import fl.controls.CheckBox;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class DragBall extends Sprite
{
private var ball:Sprite;
private var checkBox:CheckBox;
public function DragBall():void
{
drawTheBall();
makeCheckBox();
assignEventHandlers();
}
private function drawTheBall():void
{
ball = new Sprite();
ball.graphics.lineStyle();
ball.graphics.beginFill(0xB9D5FF);
ball.graphics.drawCircle(0, 0, 60);
ball.graphics.endFill();
ball.x = stage.stageWidth / 2 - ball.width / 2;
ball.y = stage.stageHeight / 2 - ball.height / 2;
ball.buttonMode = true;
addChild(ball);
}
private function makeCheckBox():void
{
checkBox = new CheckBox();
checkBox.x = 10;
checkBox.y = stage.stageHeight - 30;
checkBox.label = "Allow Drag";
checkBox.selected = false;
addChild(checkBox);
}
private function assignEventHandlers():void
{
ball.addEventListener(MouseEvent.MOUSE_DOWN, dragSprite);
ball.addEventListener(MouseEvent.MOUSE_UP, dropSprite);
}
private function dragSprite(evt:MouseEvent):void
{
if (checkBox.selected) {ball.startDrag();}
}
private function dropSprite(evt:MouseEvent):void
{
if (checkBox.selected) {ball.stopDrag();}
}
}
}
从 .fla 编译会导致以下错误,我不明白
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DragBall/drawTheBall()
at DragBall()
at DragBall_fla::MainTimeline/frame1()
【问题讨论】:
标签: actionscript-3 class package