2009-06-23 114 views
0

我是非常新的闪光灯。我试图为简单的Flash应用程序显示一个简单的按钮(使用Adobe Flex Builder 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 
实例