AS3 ArgumentError:错误#1063:期望2,得到0



我一直得到这个错误:ArgumentError:错误#1063:参数计数不匹配的代码::simmonpad()。期望是2,结果是0。我完全不知道发生了什么,尤其是int。任何帮助都将不胜感激。我在下面展示了两个代码块。它们是基于Actionscript 3.0的当我试着运行这些代码时,我没有在舞台上得到任何东西。这个代码应该显示四个不同颜色的盒子,但它根本不起作用。请帮助。

package code

{

import flash.display.MovieClip;
import flash.events.Event;

public class Main extends MovieClip
{

    private var pads:Array = new Array();
    public function Main()
    {
        var pad:SimonPad;
        pad = new SimonPad(0xAA0000, 0xFF0000);
        pad.x = 5;
        pad.y = 5;
        addChild(pad)
        pads.push(pad)
        pad = new SimonPad(0x0000AA, 0x6666FF);
        pad.x = 205;
        pad.y = 205;
        addChild(pad)
        pads.push(pad)
        pad = new SimonPad(0xAAAA00, 0xFFFF00);
        pad.x = 5;
        pad.y = 205;
        addChild(pad)
        pads.push(pad)
        pad = new SimonPad(0x00AA00, 0x00FF00);
        pad.x = 205;
        pad.y = 205;
        addChild(pad)
        pads.push(pad)
        addEventListener(Event.ENTER_FRAME, theFrame);
    }
    private function theFrame(e:Event):void
    {
        for (var i:int = 0; i < pads.length; i++) 
        {
            (pads[i] as SimonPad).update();
        }
    }
}

}

package code

{

import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;

public class SimonPad extends Sprite
{

    private var dark:Shape;
    private var light:Shape;
    public function SimonPad(darkColor:uint, lightColor:uint)
    {
        dark = new Shape();
        dark.graphics.beginFill(darkColor, 1);
        dark.graphics.drawRect(0,0,190,190);
        dark.graphics.endFill();
        addChild(dark);
        light = new Shape();
        light.graphics.beginFill(lightColor, 1);
        light.graphics.drawRect(0,0,190,190);
        light.graphics.endFill();
        addChild(light);
        light.alpha = 0;
        mouseChildren = false;
        addEventListener(MouseEvent.CLICK, downClicked);
    }
    private function downClicked (e:MouseEvent):void
    {
        flash();
    }
    public function flash():void
    {
        light.alpha = 2;
    }
    public function update():void
    {
        if (light.alpha > 0)
        {
            light.alpha *= 0.85;
            if (light.alpha < 0.0125)
            {
                light.alpha = 0;
            }
        }
    }
}

}

看起来您确实在设计时在舞台上手动放置了一个SimonPad实例。跟踪您的Flash项目手动放置SimonPad实例。此外,为了获得帧,您可以尝试这个技巧:在SimonPad()函数中,除了为构造函数参数提供默认值外,还可以添加以下行:

var e:Error=new Error();
trace(e.getStackTrace());

这将为您提供一个跟踪,其中包含有帧号的at MainTimeline.frameXXX行,或at Sprite.constructChildren() at Sprite() at SomeClass()行,它给您提示哪个类的库原型有SimonPad引用。

相关内容

  • 没有找到相关文章

最新更新