2009-06-23 3 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); 



     } 
    } 
} 

I 버튼이 표시되어 있지 않을 경우 실행합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

1

ActionScript3 그래픽은 표시 목록 개념을 기반으로합니다. 본질적으로 그래픽 요소를 표시하려면 표시 목록에 추가해야합니다.

표시 목록의 루트 노드 (실제로는 트리입니다)는 기본 클래스 인 Client2입니다. 화면에 표시 할 결과적으로 아무것도과 같이이 요소의 자식으로 추가 할 수 있습니다 마찬가지로

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

, 당신의 버튼을

addChild(myButton); //inside of LoginInterface 
LoginInterface

의 인스턴스에 추가되어야 할 것이다