0

私はフラッシュが初めてです。シンプルなフラッシュアプ​​リ(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);



        }
    }
}

実行すると、ボタンが表示されません。私は何を間違っていますか?

4

1 に答える 1

1

ActionScript3 のグラフィックは、表示リストの概念に基づいています。基本的にグラフィック要素を表示するには、表示リストに追加する必要があります。

表示リストのルート ノード (実際にはツリーです) は、メイン クラスの Client2 です。したがって、画面に表示したいものはすべて、次のようにこの要素の子として追加する必要があります。

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

同様に、ボタンを LoginInterface のインスタンスに追加する必要があります。

addChild(myButton);  //inside of LoginInterface
于 2009-06-23T21:22:56.387 に答える