如何修复子 class 中的参数计数不匹配错误?
How to fix an argument count mismatch error in a child class?
我有三个classes
基础形状
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
}
}
五角星
package {
import flash.display.MovieClip;
public class Pentangular extends BaseShape {
public function Pentangular(iX:int, iY:int) {
super(iX, iY);
}
}
}
PentangularClk
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;
}
}
}
当我在主要(阶段)使用时class
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);
}
}
}
UPD:添加于 2016-05-13
我的库中有两个 MovieClips:
- 五边形
- PentangularClk
PentangularClk 基于 Pentangular - 它具有 Pentangular 的所有形状。
我的 SWF 已启动并且可以使用。但是我看到了下一条消息:
ArgumentError: Error #1063: Argument count mismatch on Pentangular(). Expected 2, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at BaseShape()
at Pentangular()
at PentangularClk()
at Main()
我检查了发送给 classes 的参数类型。他们都还好。我不明白这条消息的原因。
你的函数 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) );
感谢大家的建议。
添加 PentangularClk
及其子形状 (Pentangular
) 时,构造函数 Pentangular
被调用两次。
第二次调用构造函数时不带任何参数
所以,@Selirion的推荐很适合我。
我刚刚设置了 iX
和 iY
.
的默认值
现在看起来像
public function Pentangular(iX:int=0, iY:int=0)
我有三个classes
基础形状
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
}
}
五角星
package {
import flash.display.MovieClip;
public class Pentangular extends BaseShape {
public function Pentangular(iX:int, iY:int) {
super(iX, iY);
}
}
}
PentangularClk
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;
}
}
}
当我在主要(阶段)使用时class
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);
}
}
}
UPD:添加于 2016-05-13
我的库中有两个 MovieClips:
- 五边形
- PentangularClk
PentangularClk 基于 Pentangular - 它具有 Pentangular 的所有形状。
我的 SWF 已启动并且可以使用。但是我看到了下一条消息:
ArgumentError: Error #1063: Argument count mismatch on Pentangular(). Expected 2, got 0.
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at BaseShape()
at Pentangular()
at PentangularClk()
at Main()
我检查了发送给 classes 的参数类型。他们都还好。我不明白这条消息的原因。
你的函数 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) );
感谢大家的建议。
添加 PentangularClk
及其子形状 (Pentangular
) 时,构造函数 Pentangular
被调用两次。
第二次调用构造函数时不带任何参数
所以,@Selirion的推荐很适合我。
我刚刚设置了 iX
和 iY
.
现在看起来像
public function Pentangular(iX:int=0, iY:int=0)