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

时间:2011-10-31 22:31:47

标签: flash actionscript-3 oop error-handling

所以,我正在制作一个游戏,当我将我的类测试到一个文件中时,我得到了四个相同类型的错误'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();

另外,如果对我的组织方式或制作此代码的方式有任何建议,请在此发帖,因为我是初学者。

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:1)

。*表示“加载该文件夹中的每个类”,但flash.display.Stage已经是一个类,因此您不需要。* 使用导入flash.display.Stage;import flash.display.*; 我建议第二个,因为你可能需要更多的flash.display类 导入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;