类型错误:错误#2007:参数孩子必须为非空 [英] TypeError: Error #2007: Parameter child must be non-null

查看:313
本文介绍了类型错误:错误#2007:参数孩子必须为非空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行下面这段code:

I am running the following piece of code:

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;
    }
}

}

这是从Adobe LiveDocs中。 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/ 我添加了一个单选框到舞台上,然后将其删除,以便其出现在库中。

This is from Adobe Livedocs. http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/ I have added a Radiobutton to stage and then deleted it so that its there in the library.

不过,我收到以下错误

类型错误:错误#2007:参数孩子必须为非空。     在flash.display使用::级DisplayObjectContainer / addChildAt()     在fl.controls ::的BaseButton / fl.controls:的BaseButton :: drawBackground()     在fl.controls ::的LabelButton / fl.controls:的LabelButton ::平局()     在fl.controls ::按钮/ fl.controls:按钮::平局()     在fl.core :: UIComponent / :: callLaterDispatcher()

TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChildAt() at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground() at fl.controls::LabelButton/fl.controls:LabelButton::draw() at fl.controls::Button/fl.controls:Button::draw() at fl.core::UIComponent/::callLaterDispatcher()

谁能告诉我是怎么回事,如何消除这种错误。

Can anyone tell me what is going on and how to remove this error.

推荐答案

这里的问题是,你有没有包括的按钮组件到库中。

the problem here is that you have not included a Button Component to your library.

拖动的按钮的从组件面板(除了的单选的组件)到库(或将其拖到舞台上并将其删除)。运行时错误就会消失,你就会有questionare以下工作检查答案按钮。

drag a Button from the components panel (in addition to the RadioButton component) into your library (or drag it to the stage and delete it). the runtime error will go away and you'll have a working "Check Answer" button below the questionare.

这篇关于类型错误:错误#2007:参数孩子必须为非空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆