我正在创建一种“游戏”,其中三个不同颜色的圆圈出现在屏幕上,并需要不同数量的点击才能消失。我有一个主要的 mxml 函数,然后是 4 个其他类。我以为我快要完成它了,但我遇到了一个错误,它没有告诉我它是什么。这是此处的评分准则的链接运行代码时遇到的错误是:“错误 #2032:流错误。URL:file:///C|/Users/Gabe/Adobe Flash Builder 4.6/Project 1/bin -debug/framework_4.6.0.23201.swf" 这是我的代码:
主.mxml:
import com.multiClicker.*;
import spark.components.Image;
//create the init function
public function init():void {
//create new target and add it to the stage
onEnterFrame();
}
public function onEnterFrame(e:Event):void{
//2% chance of being added per frame
if(Math.random() <= .02) {
//33% chance of adding red target
if(Math.random() <= .033){
//make a new image
var newCircle1:RedTarget = new RedTarget();
this.addElement(newCircle1);
//position circle
newCircle1.x = Math.random() * stage.stageWidth;
newCircle1.y = Math.random() * stage.stageHeight;
}
//33% chance of adding blue target
else if(Math.random() > .066){
//make a new image
var newCircle2:BlueTarget = new BlueTarget();
this.addElement(newCircle2);
//position circle
newCircle2.x = Math.random() * stage.stageWidth;
newCircle2.y = Math.random() * stage.stageHeight;
}
//33% chance of adding green target
else {
//make a new image
var newCircle3:GreenTarget = new GreenTarget();
this.addElement(newCircle3);
//position circle
newCircle3.x = Math.random() * stage.stageWidth;
newCircle3.y = Math.random() * stage.stageHeight;
}
}
}
我的 Target.as 文件:
package com.multiClicker{
//import the needed classes
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.utils.Timer;
import spark.components.Image;
public var hp:Number;
public class Target extends Image
{
public function Target() {
//add event listeners
this.addEventListener(MouseEvent.CLICK, onClick);
}
//sets the hp of the target
public function hP():Number {
return hp;
}
//get function that returns false if alpha is <= 0
public function dead():Boolean {
if(alpha <= 0){
return false;
}
}
//subtracts one from targets HP when clicked
public function onClick(e:MouseEvent = null):void {
//subtracts one from hp each click
hp--;
if(hp <=0) {
this.addEventListener(onEnterFrame);
}
}
//subtracts .1 from the classes alpha
public function onEnterFrame(e:Timer):void{
this.alpha =- .1;
}
//draws the target
public function drawTarget(color):void {
var circle:Shape = new Shape();
circle.graphics.beginFill(color);
circle.graphics.drawCircle(0,0,30);
}
}
}
那么目标文件 Red、Blue 和 GreenTarget.as 都是一样的:
package com.multiClicker{
import flash.events.MouseEvent;
public class RedTarget extends Target
{
private var hp:Number = 3;
public function RedTarget()
{
//draw the red circle
this.graphics.beginFill(0x990000);
this.graphics.drawCircle(0,0,30);
//include the super function
super();
}
//subtracts one from targets HP when clicked
override public function onClick(e:MouseEvent=null):void {
super.onClick(e);
//subtracts one from hp each click
hp--;
if(hp <=0) {
this.addEventListener(onEnterFrame);
}
}
}
}
我只在 Target 和 GreenTarget 中遇到错误。它没有告诉我错误是什么或在哪里。任何帮助都是极好的!
编辑:我发布了我收到的错误消息。我在 Flash Builder 上使用了 clean 功能,它消除了我的错误。然后我再次运行它,我得到一个找不到文件的错误。它说找不到我的 Main.swf。
edit2:我想我找到了错误,我删除了 Main.mxml 文件中的 onEnterFrame 函数,错误消失了。现在我只是看不出该功能有什么问题。