如何在ActionScript 3.0中更改屏幕背景颜色?

时间:2010-11-29 10:49:23

标签: actionscript-3 actionscript

如何在ActionScript 3.0中更改屏幕背景颜色?以及如何在ActionScript3.0中将一个屏幕导航到另一个屏幕; 我在项目中使用了一个按钮,当我点击按钮时,当前屏幕应该是不可见的,另一个屏幕应该来了

在onclick方法中我称之为:

presentscree.visible = false; nextscreen:NextScreen = new NextScree(); nextscreen.visible = true;

但没有结果;任何人都可以帮我吗?

2 个答案:

答案 0 :(得分:3)

您需要将屏幕添加到DisplayList,否则根本不会显示。

var nextScreen : NextScreen = new NextScreen();
addChild(nextScreen);

您可以像这样更改屏幕的背景颜色:

graphics.beginFill(0xBBBBBB, 1);
graphics.drawRect(0, 0, 800, 600);
graphics.endFill();

或者,如果要更改SWF背景颜色:

package
{

    [SWF( frameRate="30", backgroundColor="0xFFFFFF", width="800", height="600" )]
    public class MyDocumentClass extends Sprite
    {
        public function MyDocumentClass()
        {
            super();
        }
    }
}

答案 1 :(得分:0)

只要您想要更改背景颜色

,就可以调用此功能
 private function backgroundColor( color:uint ):void
 {
   with( this.graphics )
   {
    clear();
    beginFill( color );
    drawRect( 0 , 0 , Capabilities.screenResolutionX, Capabilities.screenResolutionY);
    endFill();
   }
 }

  //example
  backgroundColor( 0x990000 );

要更改屏幕,您可以将所有屏幕添加到数组

private var screens:Array = [screen1 , screen2 , ...screenN];

//Assuming that all the screens have been added to the DisplayList 
private function selectScreen( index:int ):void
{
      //Ensure that the index is within bounds
      if( index >= screens.length )
         return;

      for( var i:int ; i < screens.length ; ++i )
      {
          if( i != index )
            screens[i].visible = false;
          else
            screens[i].visible = true;               
      }
 }

 //You could also add your screens with this 
 public function addScreen( screen:DisplayObject ):void
 {
       if( screens == null )
          screens = [];

      //add the screen to the Array
      screens.push( screen );

      //hide the screen
      screen.visible = false;

      //add the screen to the Display List
      addChild( screen ); 

  }