问题描述
我创造了各种各样,其中三种不同颜色的圆圈出现在屏幕上,并采取不同数量的点击,使消失的游戏。我有一个主MXML函数,然后其他4类。我以为我即将完成它,但我遇到了一个错误,它没有告诉我它是什么。这里是一个链接到这里的专栏 的我得到的错误,当我运行code是:错误#2032:流错误的URL:文件:/// C | /用户/加布/使用Adobe Flash Builder的4.6 /项目1 /滨调试/ framework_4.6.0.23201.swf这是我的code:
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 here 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:
main.mxml:
main.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文件:
my Target.as file:
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);
}
}
}
那么目标文件红色,蓝色和GreenTarget.as这些都是相同的:
then the target files Red, Blue, and GreenTarget.as which are all the same:
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);
}
}
}
}
我收到的目标和GreenTarget只是一个错误。它是不会告诉我的错误是什么或在哪里。任何帮助将真棒!
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!
编辑:我张贴的错误消息,我得到。我用Flash Builder中的清洁功能,它抹去我的错误。然后,我再次去运行它,我得到错误未找到文件。它说我的main.swf无法找到。
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.
EDIT2:我想我找到了错误,我删除了我的onEnterFrame功能在我Main.mxml文件和错误走了。现在,我只是不明白什么是错的功能。
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.
推荐答案
我用MiniBuilder做类似的事情:
I made something similar using MiniBuilder:
http://www.swfcabin.com/open/1360282440
下面是类:
Application.as
Application.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--;
}
}
}
}
}
}
Target.as
Target.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
RedTarget.as
package com.multiClicker {
public class RedTarget extends Target {
public function
RedTarget() {
super();
hp = 3;
drawTarget( 0xff0000 );
}
}
}
GreenTarget.as
GreenTarget.as
package com.multiClicker {
public class GreenTarget extends Target {
public function
GreenTarget() {
super();
hp = 2;
drawTarget( 0x00ff00 );
}
}
}
BlueTarget.as
BlueTarget.as
package com.multiClicker {
public class BlueTarget extends Target {
public function
BlueTarget() {
super();
hp = 1;
drawTarget( 0x0000ff );
}
}
}
我希望帮助。
I hope that helps.
这篇关于如何使用类时创建图形? AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!