How to change screen background color in ActionScript 3.0 ? and how to navigate one screen to another screen in ActionScript3.0;
i have used a button in my project, when i click the button the present screen should be invisible and another screen should come
in the onclick method i called like this :
presentscree.visible = false;
nextscreen:NextScreen = new NextScree();
nextscreen.visible = true;
But no result; can any one help me on this ?
You need to add the screen to the DisplayList otherwise it will not be visible at all.
var nextScreen : NextScreen = new NextScreen();
addChild(nextScreen);
You can change the background color of your screen like this:
graphics.beginFill(0xBBBBBB, 1);
graphics.drawRect(0, 0, 800, 600);
graphics.endFill();
Or, if you want to change the SWF background color:
package
{
[SWF( frameRate="30", backgroundColor="0xFFFFFF", width="800", height="600" )]
public class MyDocumentClass extends Sprite
{
public function MyDocumentClass()
{
super();
}
}
}
Call this function anytime you want to change the backgroundColor
private function backgroundColor( color:uint ):void
{
with( this.graphics )
{
clear();
beginFill( color );
drawRect( 0 , 0 , Capabilities.screenResolutionX, Capabilities.screenResolutionY);
endFill();
}
}
//example
backgroundColor( 0x990000 );
To change the screen , you can add all your screens to an Array
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 );
}