Showing posts with label FullScreen. Show all posts
Showing posts with label FullScreen. Show all posts

Tuesday, March 6, 2007

Error on adding FullScreenListener in creationComplete handler

This is an issue i hit upon while i was doing the Full Screen App (you can see it here). I wanted to add a listener to listen for the FullScreenEvent (package flash.events.FullScreenEvent) in my Application. So i put that onto my creationComplete handler on the Application, i.e.

mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="initStuff()"

and

private function initStuff():void{
stage.addEventListener(FullScreenEvent.FULL_SCREEN, handleFullScreen);
}

But, this threw a real time error (RTE) saying...

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at JustFullScreen/::initStuff()
at JustFullScreen/_Application1_creationComplete()

The above error means that the "stage" object is null when it is trying to set the listener. What perplexes me is that if i put this addListener code in a later part of the application, it works. Which means that the stage is getting intitialized between the Application's creationComplete and the place in the code where i'm calling it. Is this a bug or does the stage get initialized later, dispatching a different event? I'm still digging.

Addendum (half hour later): I observed now that including the SystemManager class (mx.managers.SystemManager) and then using the following code in the creationComplete handler works.

import mx.managers.SystemManager;

private function initStuff():void{
systemManager.stage.addEventListener(
FullScreenEvent.FULL_SCREEN, handleFullScreen);
}

So why is the systemManager object required if it is in the creationComplete handler and not if it is in a later part of the code... I'm confused now!!! Gotta tread back to the Flex Gurus :)
The code is here...
Addendum again (the next day) - Thanks Joan for the info. Thanks to her, i found the solution for the above problem...

It seems that the stage is available only after the updateComplete or applicationComplete Events. Read the post that demystified things for me...

Monday, March 5, 2007

My Full Screen Video App - Ver 1.0

I wrote about full screen support in flash, a long time back in Nov '06 (see that post here). I have been planning to write one myself. So finally i got myself down to write it. Before i put you through the app, some details on the API.

To make your application have a fullscreen support you need to do the following things.

1) Have the latest Flash Player (get it here)

2) Use the new Full Screen API
import flash.display.StageDisplayState into your Application and set the displayState of the stage. I have the following function toggling the FullScreen feature. "fsChk" is a CheckBox, based on which I'm toggling the functionality

private function toggleFullScreen():void{

stage.addEventListener(FullScreenEvent.FULL_SCREEN, handleFullScreen);


if(fsChk.selected) {
stage.displayState = StageDisplayState.FULL_SCREEN}


else {
stage.displayState = StageDisplayState.NORMAL}

}

3) Update the html-template in which you have the flash App

In the object & embed parts of the html code of the page in which the flash app is inserted, you need to add a new parameter allowFullScreen to true. You can refer the source of the app and view the html for details.

If you want to know more about this feature, refer the Adobe DevCenter article on the same or view the PDF that i have created, collating all that information.

Now the Application. This is just a small video player which can go full screen by checking a Flex CheckBox. This is written in Flex2.0 and you can find all the source files here...

Click here to view the Application
(confirm that you have the latest Flash player)

P.S - I have muted the video to start with, un-mute it if it pleases you :)