类型错误:错误#2007:参数子项必须为非空。在 flash.display::DisplayObjectContainer/addChild()
创建了一个按钮,现在尝试将其添加到屏幕上,但我收到此错误。该按钮的代码是 -
private function submitButton():void {
submit_button=new SimpleButton();
submit_button.x=200;
submit_button.y=200;
submit_button.upState=buttonShape();
submit_button.overState=buttonShape();
submit_button.downState=buttonShape();
}
private function buttonShape() {
var rectangle:Shape = new Shape; // initializing the variable named rectangle
rectangle.graphics.beginFill(0x8C2B44); // choosing the colour for the fill, here it is red
rectangle.graphics.drawRect(200, 200, 300,20); // (x spacing, y spacing, width, height)
rectangle.graphics.endFill();
}
我已将其声明为公共变量,并且正在使用 addChild(submit_button);
edit - 所有代码都在一个类文件中。我在开始时设置了提交按钮, - private var Submit_button:SimpleButton;我有一个函数 private function SubmitButton():void { 提交按钮=新的SimpleButton(); 提交按钮.x=200; 提交按钮.y=200;
submit_button.upState=buttonShape(); commit_button.overState=buttonShape(); commit_button.downState=buttonShape(); } 和上面看到的绘图函数。我将它添加到另一个函数中的舞台 - private function gameOver():void { addChild(提交按钮); addChild(gameOver1);基本上这个函数是在命中测试中调用的。我有一个出现的文本框(这有效),但是当我添加按钮时,我收到错误
Created a button, now tried to add it to the screen and im getting this error. The code for the button is -
private function submitButton():void {
submit_button=new SimpleButton();
submit_button.x=200;
submit_button.y=200;
submit_button.upState=buttonShape();
submit_button.overState=buttonShape();
submit_button.downState=buttonShape();
}
private function buttonShape() {
var rectangle:Shape = new Shape; // initializing the variable named rectangle
rectangle.graphics.beginFill(0x8C2B44); // choosing the colour for the fill, here it is red
rectangle.graphics.drawRect(200, 200, 300,20); // (x spacing, y spacing, width, height)
rectangle.graphics.endFill();
}
I've declared it as a public var and I'm using addChild(submit_button);
edit - all the code is in one class file. i set the submit button at the start, - private var submit_button:SimpleButton; i have a function private function submitButton():void {
submit_button=new SimpleButton();
submit_button.x=200;
submit_button.y=200;submit_button.upState=buttonShape(); submit_button.overState=buttonShape(); submit_button.downState=buttonShape(); } and the drawing function seen above. and i add it to the stage in another function - private function gameOver():void { addChild(submit_button); addChild(gameOver1); basically this function is called on a hit test. and i have a text box that appears (this works) but when i add the button i get the error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
函数
buttonShape()
没有返回任何内容。您的初始行var矩形:Shape = new Shape;
正在创建一个局部变量,该变量超出范围并在函数末尾不再存在。由于
buttonShape()
不返回任何内容,因此它的实际函数签名是:在函数末尾隐含
return void;
。这意味着您的代码
本质上是编译为:
The function
buttonShape()
isn't returning anything. Your inital linevar rectangle:Shape = new Shape;
is creating a local variable, which goes out of scope and ceases to exist at the end of the function.As
buttonShape()
doesn't return anything, it's actual function signature is:with a
return void;
being implied at the end of the function.This means that your code
is essentially compiling to: