How to make a Flash Lite application running in any screen orientation
Article Metadata
Compatibility
Platform(s): Flash Lite 2.x
Article
Created: soueldi
(01 Jun 2007)
Last edited: hamishwillee
(05 Oct 2011)
Some S60 3rd edition devices permit to switch between portrait and landscape orientations, natively (like N93, N95) or using a third party application.
By default, Flash Lite applications only support one screen size (defined in the Document Properties dialog box).
If an application is launched in a screen size other than that defined, flash player will resize the document and add borders on two sides of the application.
Using external SWF files
- Create two SWF files, one is your application optimized for portrait orientation, the other for landscape orientation.
In this example, we will call them myApp_portrait.swf (240x320) and myApp_landscape.swf (320x240)
- Create a new Flash Lite application (myApp.swf)
- Change the document length and width to their possible maximum value (here 320x320) using the Document Properties dialog box
- In the first keyframe of your myApp.fla file add this code:
stop();
fscommand2("FullScreen", true);
/* Set scaleMode to "noScale" setting: the SWF will not be scaled
when the size of the screen device changes*/
Stage.scaleMode = "noScale";
//Set the current alignment of the Flash movie to "Top Left"
Stage.align = "TL";
// Create a new movie Clip
this.createEmptyMovieClip("container",this.getNextHighestDepth());
container._x = 0;
container._y = 0;
//Detect the screen size and load the correct file
if (Stage.width == 240) {
container.loadMovie("file://E:/Others/myApp_portrait.swf");
} else {
container.loadMovie("file://E:/Others/myApp_landscape.swf");
}
- Launch myApp.swf, your application will be adapted to the current screen orientation.
In your two swf's files, don't refer to the _root level. Change all your references to _root by the movie clip instance name given in the main SWF (here container)
Using a single SWF file
This method is similar to the preceding one, but instead loading external SWF files, it will load internal movie clips.
- Create a new Flash Lite application (myApp.swf)
- Change the document length and width to their possible maximum value (here 320x320) using the Document Properties dialog
- In the first keyframe, add this code:
stop();
fscommand2("FullScreen", true);
/* Set scaleMode to "noScale" setting: the SWF will not be scaled
when the size of the screen device changes*/
Stage.scaleMode = "noScale";
//Set the current alignment of the Flash movie to "Top Left"
Stage.align = "TL";
//Detect the screen size and load the correct movieclip
if (Stage.width == 240) {
_root.attachMovie("portrait_mc","portrait",10);
} else {
_root.attachMovie("landscape_mc","landscape",10);
}
- Create a movie clip:
- Select Insert -> New Symbol... -> Select Movie Clip and give it a name
- Select Export for ActionScript and set identifier to portrait_mc
- In this movie clip create a layer called background. This layer have to be always in background.
- In the first keyframe of the background layer, Draw a rectangle with this properties:

The fill color have to be the same as the document background color. (You can fill it with an another color during development, in order to see their borders.) - Create your application optimized for portrait orientation mode in this movie clip. Don't draw anything beside the background rectangle.
- Repeat all this operations with a "landscape_mc" movie clip and a 320x240 size rectangle.
- Launch myApp.swf, your application will be adapted to the current screen orientation.






I think it's better to use the width/height ratio instead of the exact pixel size. If not for any other reason, then to avoid rewriting the code for every resolution there might be ;o)
Cheers -Ruikku
Contents
it does not work on my N95
I tried this code on my N95 but it doesn't work properly: it doesn't switch from a resolution to another if I change the resolution using the sliding keyboard. I also tried the example files :( Could anyone help me, please? thanks Antonio
Unfortunately no
The thing is, the screen capabilities are always set to portrait. I'm working on a workaround myself...
a dirty solution
I solved this issue using a dirty solution: I put the function inside a setInterval function (with 100 as interval value). Basically it continuously checks the orientation value and then switch from a movieclip to another one.
I hope it can help...
does not
Since as I mentioned earlier you always get the same orientation (tried it myself as well ;o)
My idea for the same will be like
Take a variable which maintain current status of application
I mean to say,
Initially application will start with noScale mode.
Stage.scaleMode = "noScale";
So that you can get proper height and width of screen due to fullScreen mode.
then after change Stage mode to normal mode means
Stage.scaleMode = "exactFit";
Using this you can code your elements and height as well width ratio.
For initial loading this thing will enough, I think :).
Then after,
You have to place a timer where mentioned function will return Stage height and width,
Using same, changing mode.
We can’t handle stage resize event because that event will work only in noScale stage scale mode.
Ravindra Suthar
Retrieved from Flash Lite : Auto resize Flash Lite application