0

我正在创建一种“游戏”,其中三个不同颜色的圆圈出现在屏幕上,并需要不同数量的点击才能消失。我有一个主要的 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 函数,错误消失了。现在我只是看不出该功能有什么问题。

4

1 回答 1

0

我使用 MiniBuilder 做了类似的事情:

http://www.swfcabin.com/open/1360282440

以下是课程:

应用程序.as

package com.multiClicker {
import flash.display.*;
import flash.events.*;

public class Application extends Sprite {
    public function
    Application() {
        addEventListener( Event.ENTER_FRAME, onEnterFrame );
    }

    private function
    onEnterFrame( e:Event ):void {
        var circle:Target;
        var n:Number = Math.random();

        // 33% of 2% chance each of being added per frame
        if ( n <= 0.00667 )     circle = new RedTarget();
        else if( n <= 0.01334 ) circle = new GreenTarget();
        else if( n <= 0.02 )    circle = new BlueTarget();

        if ( circle ) {
            circle.x = Math.random() * stage.stageWidth;
            circle.y = Math.random() * stage.stageHeight;
            addChild( circle );
        }

        // Remove dead
        for ( var i:int = 0; i < numChildren; i++ ) {
            var child:Target = getChildAt( i ) as Target;
            if ( child ) {
                if ( child.dead ) {
                    removeChild( child );
                    i--;
                }
            }
        }
    }
}
}

目标.as

package com.multiClicker {
import flash.display.*;
import flash.events.*;

public class Target extends Sprite {
    protected var hp:Number;

    public function 
    Target() {
        addEventListener( MouseEvent.CLICK, onClick );
    }

    public function
    get dead():Boolean {
        if ( alpha <= 0 ) return true;
        return false;
    }

    protected function
    drawTarget( color:uint ):void {
        graphics.beginFill( color );
        graphics.drawCircle( 0, 0, 30 );
        graphics.endFill();
    }

    private function 
    onClick( e:MouseEvent = null ):void {
       if ( --hp <= 0 ) addEventListener( Event.ENTER_FRAME, onEnterFrame );
    }

    private function 
    onEnterFrame( e:Event ):void{
        alpha -= 0.1;
        if ( alpha <= 0 ) {
            removeEventListener( Event.ENTER_FRAME, onEnterFrame );
            removeEventListener( MouseEvent.CLICK, onClick );
        }
    }
}
}

RedTarget.as

package com.multiClicker {
public class RedTarget extends Target {
    public function
    RedTarget() {
        super();
        hp = 3;
        drawTarget( 0xff0000 );
    }
}
}

绿色目标

package com.multiClicker {
public class GreenTarget extends Target {
    public function
    GreenTarget() {
        super();
        hp = 2;
        drawTarget( 0x00ff00 );
    }
}
}

BlueTarget.as

package com.multiClicker {
public class BlueTarget extends Target {
    public function
    BlueTarget() {
        super();
        hp = 1;
        drawTarget( 0x0000ff );
    }
}
}

我希望这会有所帮助。

于 2013-02-08T02:21:22.473 回答