【问题标题】:How to change screen background color in ActionScript 3.0?如何在 ActionScript 3.0 中更改屏幕背景颜色?
【发布时间】:2011-05-17 05:21:12
【问题描述】:

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

在我这样调用的 onclick 方法中:

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

但是没有结果;有人可以帮我吗?

【问题讨论】:

  • 请检查编辑的代码,才发现我忘记了改变背景颜色的一行!

标签: actionscript-3 actionscript


【解决方案1】:

您需要将屏幕添加到 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();
        }
    }
}

【讨论】:

  • 实现了这两个东西,但是崩溃了,颜色没有改变,甚至导航还没有完成。
  • 属性的东西很好。到目前为止,我总是不得不去 FlashDevelop 中的项目属性。 在精灵上绘制背景颜色我认为是一个糟糕的解决方案。之后就不能动了。 OpenGL 具有设置清晰颜色(背景颜色)的能力。 Flash 也应该有这个!
【解决方案2】:

只要你想改变背景颜色就调用这个函数

 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 ); 

  }

【讨论】:

    猜你喜欢
    • 2021-02-07
    • 2016-09-20
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 2015-03-16
    • 2012-08-17
    相关资源
    最近更新 更多