actionscript-3 - 类型错误 : Error #2007: Parameter child must be non-null

标签 actionscript-3

我正在运行以下代码:

package {

import fl.controls.Button;
import fl.controls.Label;
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;

public class RadioButtonExample extends Sprite {
    private var j:uint;
    private var padding:uint = 10;
    private var currHeight:uint = 0;
    private var verticalSpacing:uint = 30;

    private var rbg:RadioButtonGroup;
    private var questionLabel:Label;
    private var answerLabel:Label;
    private var question:String = "What day is known internationally as Speak Like A Pirate Day?";
    private var answers:Array = [ "August 12", "March 4", "September 19", "June 22" ];

    public function RadioButtonExample() {
        setupQuiz();
    }
    private function setupQuiz():void {
        setupQuestionLabel();
        setupRadioButtons();
        setupButton();
        setupAnswerLabel();
    }
    private function setupQuestionLabel():void {
        questionLabel = new Label();
        questionLabel.text = question;
        questionLabel.autoSize = TextFieldAutoSize.LEFT;
        questionLabel.move(padding, padding + currHeight);

        currHeight += verticalSpacing;
        addChild(questionLabel);
    }
    private function setupAnswerLabel():void {
        answerLabel = new Label();
        answerLabel.text = "";
        answerLabel.autoSize = TextFieldAutoSize.LEFT;
        answerLabel.move(padding + 120, padding + currHeight);

        addChild(answerLabel);
    }
    private function setupRadioButtons():void {
        rbg = new RadioButtonGroup("question1");
        createRadioButton(answers[0], rbg);
        createRadioButton(answers[1], rbg);
        createRadioButton(answers[2], rbg);
        createRadioButton(answers[3], rbg);
    }
    private function setupButton():void {
        var b:Button = new Button();
        b.move(padding, padding + currHeight);
        b.label = "Check Answer";
        b.addEventListener(MouseEvent.CLICK, checkAnswer);

        addChild(b);
    }
    private function createRadioButton(rbLabel:String, rbg:RadioButtonGroup):void {
        var rb:RadioButton = new RadioButton();
        rb.group = rbg;
        rb.label = rbLabel;
        rb.move(padding, padding + currHeight);
        addChild(rb);

        currHeight += verticalSpacing;
    }
    private function checkAnswer(e:MouseEvent):void {
        if (rbg.selection == null) {
            return;
        }
        var resultStr:String = (rbg.selection.label == answers[2]) ? "Correct" : "Incorrect";
        answerLabel.text = resultStr;
    }
}

}

这是来自 Adob​​e Livedocs。 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/ 我在舞台上添加了一个 Radiobutton,然后将其删除,以便它在库中。

但是我收到以下错误

TypeError:错误 #2007:参数 child 必须为非 null。 在 flash.display::DisplayObjectContainer/addChildAt() 在 fl.controls::BaseButton/fl.controls:BaseButton::drawBackground() 在 fl.controls::LabelButton/fl.controls:LabelButton::draw() 在 fl.controls::Button/fl.controls:Button::draw() 在 fl.core::UIComponent/::callLaterDispatcher()

谁能告诉我发生了什么以及如何消除此错误。

最佳答案

这里的问题是您的库中没有包含 按钮组件

从组件面板(除了 RadioButton 组件之外)将一个 Button 拖到您的库中(或将其拖到舞台并删除它)。运行时错误将消失,您将在问题下方有一个有效的“检查答案”按钮。

关于actionscript-3 - 类型错误 : Error #2007: Parameter child must be non-null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4573282/

相关文章:

actionscript-3 - 如何将 .as 文件列表编译为单个 .swf?

xml - 在 ActionScript 3 中保存到没有用户提示对话框的 XML 文件?

flash - 如果一个对象在 Flash 中被垃圾回收,它引用的对象的引用计数器会自动递减吗?

apache-flex - ActionScript 中组件不同部分的不同工具提示

javascript - 难以在 IE 中使用 Javascript 捕获日语字符输入

flash - ApplicationDomain.domainMemory 有什么用?

apache-flex - 访问 mxml 标签内的类

apache-flex - 弹性 : does painless programmatic data binding exist?

java - 垃圾收集问题

actionscript-3 - 确定是否正在播放影片剪辑