【问题标题】:Why is my AS3 SimpleButton not showing?为什么我的 AS3 SimpleButton 没有显示?
【发布时间】:2009-06-23 21:15:13
【问题描述】:

我对 Flash 很陌生。我正在尝试为我的简单 Flash 应用程序(使用 adobe flex builder 3)显示一个简单的按钮。

主工程文件Client2.as:

package
{
    import flash.display.Sprite;

    [SWF(width="600", height="600", frameRate="31", backgroundColor="#00FFFF")] //set project properties

    public class Client2 extends Sprite
    {   
        public function Client2() {
            trace("Client launched.");
            var loginGui:LoginInterface = new LoginInterface(); //load the login interface object
            loginGui.init(); //initialize the login interface
        }
    }
}

然后是LoginInterface.as类文件:

package
{
    import flash.display.Sprite;
    import flash.display.SimpleButton;

    public class LoginInterface extends Sprite
    {
        public function LoginInterface()
        {
            trace("LoginInterface object loaded.");
        }

        public function init():void
        {
            trace("LoginInterface init method was called.");

            var myButton:SimpleButton = new SimpleButton();

            //create the look of the states
            var down:Sprite = new Sprite();
            down.graphics.lineStyle(1, 0x000000);
            down.graphics.beginFill(0xFFCC00);
            down.graphics.drawRect(10, 10, 100, 30);

            var up:Sprite = new Sprite();
            up.graphics.lineStyle(1, 0x000000);
            up.graphics.beginFill(0x0099FF);
            up.graphics.drawRect(10, 10, 100, 30);

            var over:Sprite = new Sprite();
            over.graphics.lineStyle(1, 0x000000);
            over.graphics.beginFill(0x9966FF);
            over.graphics.drawRect(10, 10, 100, 30);

            // assign the sprites
            myButton.upState = up;
            myButton.overState = over;
            myButton.downState = down;
            myButton.hitTestState = up;

            addChild(myButton);



        }
    }
}

当我运行它时,按钮没有显示。我做错了什么?

【问题讨论】:

    标签: flash actionscript-3 simplebutton


    【解决方案1】:

    ActionScript3 图形基于显示列表概念。基本上图形元素必须添加到显示列表中才能被看到。

    显示列表的根节点(实际上是一棵树)是您的主类Client2。因此,您希望在屏幕上显示的任何内容都必须添加为该元素的子元素,如下所示:

    addChild(loginGui);  //inside of your main class
    

    同样,您的按钮也必须添加到您的 LoginInterface 实例中

    addChild(myButton);  //inside of LoginInterface
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-12
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多