AS3:错误 1046:未找到类型或不是编译时常量:Stage 和 TextField

发布于 2024-12-13 04:01:09 字数 2439 浏览 0 评论 0原文

因此,我正在制作一个游戏,当我在文件中测试我的类时,我收到四个相同类型的错误“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

前事休说 2024-12-20 04:01:09

你所有的进口都是错误的。

//Change
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.*;


/ to
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;

All your imports are wrong.

//Change
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.*;


/ to
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;
假装不在乎 2024-12-20 04:01:09

.* 表示“加载该文件夹中的每个类”,但 flash.display.Stage 已经是一个类,因此您不需要 .*
使用 import flash.display.Stage;import flash.display.*;
我建议使用第二个,因为您可能需要 flash.display 中更多的类
与 import flash.text.TextField; 和其他相同

import flash.display.*;
import flash.filters.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;

.* 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; or import 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

import flash.display.*;
import flash.filters.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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文