我有三个班级
BaseShape
.img-overlay{
position:absolute;
top:0;
left:14.5%;
z-index:3;
}
五角形
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.system.System;
public class BaseShape extends MovieClip
{
var isActive:Boolean;
public function BaseShape(iX:int, iY:int)
{
x = iX;
y = iY;
isActive=true;
}
//Other function here
}
}
PentangularClk
package {
import flash.display.MovieClip;
public class Pentangular extends BaseShape {
public function Pentangular(iX:int, iY:int) {
super(iX, iY);
}
}
}
当我在主(舞台)课程中使用时
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class PentangularClk extends Pentangular {
public function PentangularClk(iX:int, iY:int) {
super(iX, iY);
Cross.visible=false;
addEventListener(MouseEvent.CLICK, setActive);
}
private function setActive(e:MouseEvent):void{
Tick.visible=!Tick.visible;
Cross.visible=!Cross.visible;
isActive=Tick.visible;
}
}
}
我的图书馆有两个MovieClip:
PentangularClk基于五角形 - 它具有五角形的所有形状。
我的SWF已启动并正常运行。但我看到了下一条消息:
package
{
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.ui.Keyboard;
public class Main extends MovieClip
{
var myShape:Array=new Array();
var toVertical:int=0;
var toHorizontal:int=0;
var pressedKeys:Object = { };
public function Main()
{
SpeedShape.value=8;
SpeedShape.minimum=0;
SpeedShape.maximum=20;
SpeedShape.stepSize= 1;
RotationShape.value=8;
RotationShape.minimum=1;
RotationShape.maximum=20;
RotationShape.stepSize= 1;
myShape[0] = new Star(mainShape.width / 2,mainShape.height / 4);
//Next line makes this MovieClip
myShape[1] = new PentangularClk(-1 * mainShape.width / 2,-1 * mainShape.height / 4);
mainShape.addChild(myShape[0]);
mainShape.addChild(myShape[1]);
stage.addEventListener(KeyboardEvent.KEY_DOWN,moveShapeByKeyboard);
stage.addEventListener(KeyboardEvent.KEY_DOWN,moveShapeByKeyboard,true);
stage.addEventListener(KeyboardEvent.KEY_UP,stopShapeByKeyboard);
stage.addEventListener(KeyboardEvent.KEY_UP,stopShapeByKeyboard,true);
}
}
}
我检查了发送给类的参数类型。他们都还好。我不明白这条消息的原因。
答案 0 :(得分:1)
感谢大家的建议。
添加Pentangular
时以及添加子项形状(PentangularClk
)时,构造函数Pentangular
将被调用两次。
第二次,在没有任何参数的情况下调用构造函数。
所以@Selirion的推荐适合我。
我的默认值为iX
和iY
。
现在看起来像
public function Pentangular(iX:int=0, iY:int=0)
答案 1 :(得分:0)
你的函数PentangularClk(iX:int, iY:int)
需要两个整数类型的变量,所以试试(未经测试):
var int1 : int = (-1 * mainShape.width / 2);
var int2 : int = (-1 * mainShape.height / 4);
myShape[1] = new PentangularClk(int1, int2);
或者你可以尝试这样......
myShape[1] = new PentangularClk( int(-1 * mainShape.width / 2), int(-1 * mainShape.height / 4) );