Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create graphics when using classes? AS3
    primarykey
    data
    text
    <p>I am creating a "game" of sorts where three different colored circles appear on the screen and take different amounts of clicks to make disappear. I have a main mxml function and then 4 other classes. I thought I was close to finishing it, but I have encountered an error and it is not telling me what it is. Here is a link to the rubric <a href="http://mypage.iu.edu/~tfaas/222/assignments/project1.html" rel="nofollow">here</a> The error I get when I run the code is: "Error #2032: Stream Error. URL: file:///C|/Users/Gabe/Adobe Flash Builder 4.6/Project 1/bin-debug/framework_4.6.0.23201.swf" Here is my code:</p> <p>main.mxml:</p> <pre><code>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() &lt;= .02) { //33% chance of adding red target if(Math.random() &lt;= .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() &gt; .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; } } } </code></pre> <p>my Target.as file:</p> <pre><code>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 &lt;= 0 public function dead():Boolean { if(alpha &lt;= 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 &lt;=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); } } </code></pre> <p>}</p> <p>then the target files Red, Blue, and GreenTarget.as which are all the same:</p> <pre><code>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 &lt;=0) { this.addEventListener(onEnterFrame); } } } </code></pre> <p>}</p> <p>I am getting an error in Target and GreenTarget only. It is not telling me what the error is or where. any help would be awesome!</p> <p>edit: I posted the error message I was getting. I used the clean function on Flash Builder and it erased my errors. Then I go to run it again and I get a file not found error. It says my Main.swf cannot be found.</p> <p>edit2: I think I found the error, I deleted my onEnterFrame function in my Main.mxml file and the errors went away. Now I just do not see what is wrong with that function.</p>
    singulars
    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