as3导入类

时间:2012-07-21 08:29:32

标签: actionscript-3

我在导入课时遇到问题。我可以创建类的实例,但我不能使用公共静态成员。当我将所有文件放在同一个包中时,我没有任何问题,但是当我必须导入时,我得到这个错误:1119:通过带有静态类型Class的引用访问可能未定义的属性MAIN_MENU。

这是主要课程的开头:

import flash.display.Sprite;
import flash.events.Event;

import classes.gameStates.MainMenuScreen;

public class DocumentClass extends Sprite
{
    private var mainMenuScreen:MainMenuScreen;

    public function DocumentClass()
    {
        displayMainMenu();
    }

    private function displayMainMenu():void
    {
        mainMenuScreen = new MainMenuScreen();
        mainMenuScreen.x = 0;
        mainMenuScreen.y = 0;
        mainMenuScreen.addEventListener(MainMenuScreen.START_GAME, onStartGame);
        mainMenuScreen.addEventListener(MainMenuScreen.CREDITS, onCredits);
        addChild(mainMenuScreen);
    }

这是MainMenuScreen类

package classes.gameStates
{   
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;

public class MainMenuScreen extends Sprite
{   
    public static const START_GAME:String = "startGame";
    public static const CREDITS:String = "credits";

    public function MainMenuScreen()
    {
        startGameButton.addEventListener(MouseEvent.CLICK, onStartGame);
        creditsButton.addEventListener(MouseEvent.CLICK, onStartCredits);
    }

    public function Destroy():void
    {
        startGameButton.removeEventListener(MouseEvent.CLICK, onStartGame);
        creditsButton.removeEventListener(MouseEvent.CLICK, onStartCredits);
    }

    private function onStartGame(e:MouseEvent):void
    {
        dispatchEvent(new Event(MainMenuScreen.START_GAME));
    }

    private function onStartCredits(e:MouseEvent):void
    {
        dispatchEvent(new Event(MainMenuScreen.CREDITS));
    }
}
}

1 个答案:

答案 0 :(得分:0)

你怎么能做这个工作?或者你已经截断了你的代码?首先,MainMenuS中的按钮不受限制。其次,onStartGame和onCredit()是PRIVATE,DocumentClass无法访问它。

首先尝试更改其修改器。