培训代码不工作
Training Code Not working
所以我正在阅读 Keith Peters 的书 "ActionScript 3.0 Animation ~ Making Things Move",其中一个例子是教授父框...我已经写出这段代码,并且在执行时,它 运行 s,但没有提供任何错误,没有任何反应,绘制了 none 个 Sprites,它是一个空白 canvas..?使用 Flash Pro CS 6、12.0.2.529。到目前为止,我还没有遇到任何其他示例的问题,并且 .as "ParentBox" 运行 很好,当我尝试 运行 ParentBox2 时,我遇到了这个问题。 .. 想法? (抱歉,我是 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);
}
}}
public class ParentBox2 extends Sprite {
需要重命名为
public class Reparenting2 extends Sprite {
功能...就像我说的,我还在学习,尤其是命名方面的东西,谢谢大家!
您已经找到了答案,但对于遇到同样问题的其他人,
在 ActionScript3 中,构造函数的名称应与 class 名称相同。
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();
}
...
所以我正在阅读 Keith Peters 的书 "ActionScript 3.0 Animation ~ Making Things Move",其中一个例子是教授父框...我已经写出这段代码,并且在执行时,它 运行 s,但没有提供任何错误,没有任何反应,绘制了 none 个 Sprites,它是一个空白 canvas..?使用 Flash Pro CS 6、12.0.2.529。到目前为止,我还没有遇到任何其他示例的问题,并且 .as "ParentBox" 运行 很好,当我尝试 运行 ParentBox2 时,我遇到了这个问题。 .. 想法? (抱歉,我是 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);
}
}}
public class ParentBox2 extends Sprite {
需要重命名为
public class Reparenting2 extends Sprite {
功能...就像我说的,我还在学习,尤其是命名方面的东西,谢谢大家!
您已经找到了答案,但对于遇到同样问题的其他人,
在 ActionScript3 中,构造函数的名称应与 class 名称相同。
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();
}
...