2009-06-23 32 views
0

私は非常に新しいフラッシュです。私は単純なフラッシュアプ​​リケーションのための単純なボタンを表示しようとしています(アドビフレックスビルダー3)。AS3 SimpleButtonが表示されないのはなぜですか?

メインプロジェクトファイル、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); 



     } 
    } 
} 

私はボタンが表示されていない、それを実行します。私は間違って何をしていますか?

答えて

1

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

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

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

、あなたのボタンがLoginInterface

addChild(myButton); //inside of LoginInterface 
のインスタンスに追加しなければならないであろう
関連する問題