Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 试图在类中推送细节_Actionscript 3_Apache Flex_Class_Push - Fatal编程技术网

Actionscript 3 试图在类中推送细节

Actionscript 3 试图在类中推送细节,actionscript-3,apache-flex,class,push,Actionscript 3,Apache Flex,Class,Push,我正在做一个创造三个圆圈的游戏“红色、绿色和蓝色分别拥有3、2、1条生命。当他们的生命值达到0并且每次点击减少1时,他们将从阶段中移除。我使用的是Main.mxml文件,然后我有一个Target.as文件,还有RedTarget.as、GreenTarget.as和BlueTarget.as。我的问题是,我想在Target.as文件中设置所有内容,然后通过这些函数推送诸如颜色、健康状况以及它们是否已死亡等详细信息。但是,我在这样做时遇到了困难,因为我不确定Target.as中需要什么,以及在每个

我正在做一个创造三个圆圈的游戏“红色、绿色和蓝色分别拥有3、2、1条生命。当他们的生命值达到0并且每次点击减少1时,他们将从阶段中移除。我使用的是Main.mxml文件,然后我有一个Target.as文件,还有RedTarget.as、GreenTarget.as和BlueTarget.as。我的问题是,我想在Target.as文件中设置所有内容,然后通过这些函数推送诸如颜色、健康状况以及它们是否已死亡等详细信息。但是,我在这样做时遇到了困难,因为我不确定Target.as中需要什么,以及在每个彩色目标文件中需要编写什么。 这是我的Target.as文件:

package com.multiClicker {
//import the needed classes
import flash.display.Shape;
import flash.events.MouseEvent;

import spark.components.Image;


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;
    }

    return true;
}

//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():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);

}

}
}

在这个问题上有任何帮助都会很好。我一整天都在想办法,但还没想出来。

你是在问创建目标对象时如何传入变量吗

public class Target extends Image {

    public function Target(hp:Number, dead:Boolean, color:String) {

        this.hp = hp;
        this.dead = dead;
        this.color = color;

    }

}
然后按如下方式实例化每个目标:

var redTarget:Target = new Target(3, false, "red");
var greenTarget:Target = new Target(2, false, "green");
等等。

在这里发布了回复:
var redTarget:Target = new Target(3, false, "red");
var greenTarget:Target = new Target(2, false, "green");