Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to essentially push details through classes
    primarykey
    data
    text
    <p>I am working on a game that creates three circles" red, green, and blue who have 3,2,1 health respectively. They get removed from the stage after their health reaches 0 and it is decremented by 1 per click. I am using a Main.mxml file then I have a Target.as file, as well as RedTarget.as, GreenTarget.as, and BlueTarget.as. My question is that I would like to set everything up in my Target.as file, then push the details such as color, health, and if they are dead or not through those functions. I am having trouble doing that though because I am not sure what I would need in the Target.as and then what I would need to code in each of the colored target files. Here is my Target.as file:</p> <pre><code>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 &lt;= 0 public function dead():Boolean { if(alpha &lt;= 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 &lt;=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); } } } </code></pre> <p>and then my RedTarget.as file, which is the same as blue and green, except for that they are labeled as such in the variables:</p> <pre><code>package com.multiClicker { import flash.events.MouseEvent; public class RedTarget extends Target{ private var redHP:Number = 3; private var redDead:Boolean = false; private var redColor:String = "red"; public function RedTarget() { redHP = hp; redDead = dead; redColor = color; //include the super function super(); } //subtracts one from targets HP when clicked override public function onClick(e:MouseEvent=null):void { super.onClick(e); //push all to super } } } </code></pre> <p>Any help on the issue would be great. I have been trying to figure it out throughout the day but have not figured it out.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload