所以我正在阅读Keith Peters的书"ActionScript 3.0动画~让事物移动“,其中一个例子是教家长Boxs……我已经写出了这段代码,在执行时,它会运行,但没有提供任何错误,没有发生任何事情,没有绘制任何Sprite,它是一个空白画布。使用Flash Pro CS 6,12.0.2.529。到目前为止,我还没有遇到任何其他示例的问题,当我尝试运行ParentBox2时遇到这个问题时,.as "ParentBox“运行得很好。有什么想法?(对不起,我是OOP的新手,正在努力学习尽可能多的知识,这个网站到目前为止因其丰富的知识而令人惊叹……
ParentBox.as
package {
import flash.display.Sprite;
public class ParentBox extends Sprite {
public function ParentBox()
{
init();
}
private function init():void{
graphics.lineStyle(1, 0);
graphics.drawRect(-50, -50, 100, 100);
}
}}ParentBox2.as代码....
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ParentBox2 extends Sprite {
private var parent1:ParentBox;
private var parent2:ParentBox;
private var ball:Sprite;
public function Reparenting2 (){
init();
}
private function init():void{
parent1 = new ParentBox();
addChild(parent1);
parent1.x = 60;
parent1.y = 60;
parent2 = new ParentBox();
addChild(parent2);
parent2.x = 170;
parent2.y = 60;
ball = new Sprite();
parent1.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);
}
}}发布于 2016-08-26 01:00:02
这个
public class ParentBox2 extends Sprite {需要重命名为
public class Reparenting2 extends Sprite {对于函数...就像我说的,我还在学习,特别是命名的东西,谢谢大家!
发布于 2016-08-30 14:40:47
你已经找到了答案,但对于任何其他有同样问题的人来说,
在ActionScript3中,构造函数的名称应该与类名相同。
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ParentBox2 extends Sprite {
private var parent1:ParentBox;
private var parent2:ParentBox;
private var ball:Sprite;
public function ParentBox2 (){ //the constructor function's name should be the same as that of the class.
init();
}
...https://stackoverflow.com/questions/39150794
复制相似问题