AS3:错误 1046:未找到类型或不是编译时常量:Stage 和 TextField
因此,我正在制作一个游戏,当我在文件中测试我的类时,我收到四个相同类型的错误“1046:未找到类型或不是编译时常量:Stage 和 TextField”。我已经导入了所有内容,请看一下:
Game.as
package {
import flash.display.Stage.*;
import flash.filter.GlowFilter.*;
import flash.text.TextField.*;
import flash.net.URLLoader.*;
import flash.net.URLRequest.*;
import flash.net.URLRequestMethod.*;
import flash.net.URLLoaderDataFormat.*;
import flash.net.URLVariables.*;
public class Game {
public static const STATUS_MENU:int = 1;
public static const STATUS_SURVIVAL:int = 2;
public static const STATUS_MULTIPLAYER:int = 3;
public static const GAME_RUN:int = 1;
public static const GAME_PAUSE:int = 2;
public static var palco:Stage;
public static var profileName:Array; //Name, status, pass
public function Game():void {
trace("Class Game is online.");
}
public function transStage(sender:Stage):Stage {
palco = sender;
palco.align = StageAlign.BOTTOM_LEFT;
palco.scaleMode = StageScaleMode.EXACT_FIT;
palco.displayState = StageDisplayState.FULL_SCREEN;
return(palco);
}
public function makeGlow(txt:TextField):void {
var glow:GlowFilter = new GlowFilter();
glow.color = 0xFFFFFF;
glow.alpha = 1;
glow.blurX = 4.5;
glow.blurY = 4.5;
glow.quality = BitmapFilterQuality.HIGH;
txt.filters = [glow];
}
public function removeGlow(txt:TextField):void {
txt.filters = [];
}
public function setStatus(current:int):void {
var request1:URLRequest = new URLRequest("http://www.url.com/");
var loader:URLLoader = new URLLoader();
var vari:URLVariables = new URLVariables();
vari.Profile = profileArray[1];
switch (current) {
case 1:
vari.Status = 1;
profileArray[2] = 1;
break;
case 2:
vari.Status = 2;
profileArray[2] = 2;
break;
case 3:
vari.Status = 3;
profileArray[2] = 3;
break;
}
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request1.data = vari;
request1.method = URLRequestMethod.POST;
loader.load(request1);
}
}
}
这是 fla 测试文件:
import Game;
var manager:Game = new Game();
另外,如果对我的组织方式或制作此代码的方式有任何建议,请在此处发布,因为我是初学者。
So, I'm making a game and when I test my class into a file I get four errors of the same type '1046: Type was not found or was not a compile-time constant: Stage and TextField'. I've imported everything, please take a look:
Game.as
package {
import flash.display.Stage.*;
import flash.filter.GlowFilter.*;
import flash.text.TextField.*;
import flash.net.URLLoader.*;
import flash.net.URLRequest.*;
import flash.net.URLRequestMethod.*;
import flash.net.URLLoaderDataFormat.*;
import flash.net.URLVariables.*;
public class Game {
public static const STATUS_MENU:int = 1;
public static const STATUS_SURVIVAL:int = 2;
public static const STATUS_MULTIPLAYER:int = 3;
public static const GAME_RUN:int = 1;
public static const GAME_PAUSE:int = 2;
public static var palco:Stage;
public static var profileName:Array; //Name, status, pass
public function Game():void {
trace("Class Game is online.");
}
public function transStage(sender:Stage):Stage {
palco = sender;
palco.align = StageAlign.BOTTOM_LEFT;
palco.scaleMode = StageScaleMode.EXACT_FIT;
palco.displayState = StageDisplayState.FULL_SCREEN;
return(palco);
}
public function makeGlow(txt:TextField):void {
var glow:GlowFilter = new GlowFilter();
glow.color = 0xFFFFFF;
glow.alpha = 1;
glow.blurX = 4.5;
glow.blurY = 4.5;
glow.quality = BitmapFilterQuality.HIGH;
txt.filters = [glow];
}
public function removeGlow(txt:TextField):void {
txt.filters = [];
}
public function setStatus(current:int):void {
var request1:URLRequest = new URLRequest("http://www.url.com/");
var loader:URLLoader = new URLLoader();
var vari:URLVariables = new URLVariables();
vari.Profile = profileArray[1];
switch (current) {
case 1:
vari.Status = 1;
profileArray[2] = 1;
break;
case 2:
vari.Status = 2;
profileArray[2] = 2;
break;
case 3:
vari.Status = 3;
profileArray[2] = 3;
break;
}
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
request1.data = vari;
request1.method = URLRequestMethod.POST;
loader.load(request1);
}
}
}
And here's the fla test file:
import Game;
var manager:Game = new Game();
Also, if have any suggestions about the way I organize or the way I made this code please post here, because I'm a beginner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你所有的进口都是错误的。
All your imports are wrong.
.* 表示“加载该文件夹中的每个类”,但 flash.display.Stage 已经是一个类,因此您不需要 .*
使用 import
flash.display.Stage;
或import flash.display.*;
我建议使用第二个,因为您可能需要 flash.display 中更多的类
与 import
flash.text.TextField;
和其他相同.* means "load every class in that folder" but
flash.display.Stage
is already a class so you don't need the .*Use either import
flash.display.Stage;
orimport flash.display.*;
I suggest the second because you're likely to need more classes in flash.display
Same thing with import
flash.text.TextField;
and the others