Detecting if fullscreen is allowed in ActionScript 3.0?
Asked Answered
S

8

6

I would like to remove a fullscreen button if the allowfullscreen param is false.
      param value="true" name="allowfullscreen"

Does anyone know if its possible to detect that value? It doesn't come with other flashvars on loaderInfo.parameters.

Subcommittee answered 18/3, 2009 at 17:4 Comment(0)
V
-3

EDIT: This is obsolete now (was a hack for FP 8.5 / 9)

The following will detect if your player has fullscreen availability (thx @mrdoob) :

var hasFullscreen:Boolean = (stage.hasOwnProperty("displayState"))
Vannesavanness answered 14/4, 2009 at 15:51 Comment(2)
This solution does not work as the displayState property is always available, even when allowFullScreen=false, tested in Flash 10.0.Sold
I know, as you can see this was posted 2 years ago while the issue was to detect if the player version actually supported this feature... kthxVannesavanness
T
2

The member you want is

stage.displayState

It can be assigned like so:

import flash.display.StageDisplayState;

....

stage.displayState = StageDisplayState.FULL_SCREEN;
stage.displayState = StageDisplayState.NORMAL;

I recommend reading:

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000352.html

[Edit:

Oh man, totally misread your question.]

After a little test it looks like you can just use the exception mechanism to test for it without any perceptable flicker:

try
{
    stage.displayState = StageDisplayState.FULL_SCREEN;
    stage.displayState = StageDisplayState.NORMAL;
} catch ( error:SecurityError ) {
// your hide button code            
}
Tonatonal answered 18/3, 2009 at 20:10 Comment(2)
Actually running in the browser, under the flash player plugin, you can't even do this code unless it's attached to a user initiated event like MouseEvent.CLICK.Spikes
That's just a matter of information design. It's hardly going to inhibit the testing process to any great degree.Tonatonal
J
2

SOLUTION FOR AS3

you can check if full screen is allowed via the stage properties, example for my case

try {
    if (btn.stage["allowsFullScreen"]) { // if this fails, then its not allowed
        // do full screen allow code here
        btn.alpha = 1; // show since its allowed
    }
} catch (error:Error) { // full scrren not allowed
    btn.alpha = 0.5; // dim since it cant be used
}
Judithjuditha answered 21/9, 2011 at 17:10 Comment(1)
stage.allowsFullScreen was added in 10.2 so this won't work for older players, but this is the best solution I've found. I use: stage.hasOwnProperty("displayState") && stage.hasOwnProperty("allowsFullScreen") && stage["allowsFullScreen"]Strident
S
0

Actually the docs are unclear as to how full screen mode being allowed or not can be detected in ActionScript 3.

The only thing they mention is that if you do try to switch to full screen mode and it is disallowed, then you'll get an exception, which you can catch. This won't easily allow you to hide or show a full screen mode button.

There may be a way, but the "livedocs" are notoriously incomplete or brief.

You might be able to read the "fullscreen" param's value which defaults to false by looking at the root object's paramters with:

var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
//do something with this information
}

Edit: you noted that it doesn't come back in the flashvars.

Spikes answered 18/3, 2009 at 20:25 Comment(3)
"This won't easily allow you to hide or show a full screen mode button" - why not? If you catch a SecurityException while toggling full screen mode, it's not allowed.Fiddlewood
The question says "It doesn't come with other flashvars on loaderInfo.parameters".Fiddlewood
Logic. What if you don't get an exception? Now you're switching modes BEFORE you drew the button and before anyone clicked on it. Except of course: the security model says you can't assign stage.displayState unless initiated by a user event. Yes I missed the flashvars bit when editing in more.Spikes
V
0

You cannot detect if the embed has the allowfullscreen set to false/true.

Unfortunately you will need to wait until the user clicks on the button to catch the eventual error and thereby disable the button.

Still ... You must be in a very special context to require flashplayer evaluate this value itself as you probably edited it. In case the embed is handled by a third-party that needs to be able to decide whether the fullscreen mode should be allowed or not. If this is the case, just add an extra flash-var (e.g. fullscreenButton=false).

Vannesavanness answered 19/3, 2009 at 9:39 Comment(0)
W
0

The only method i can think of would be to call a JavaScript function via ExternalInterface. You can easily read the flash embed parameters from JavaScript, but I'm thinking if you could insert a JS into the HTML your movie is embedded, you'd have rather changed the parameter than try to find out what it is.

Other than that, Jotham's solution seems ok, aside from the fact that stage.displayState = StageDisplayState.FULL_SCREEN; can only be triggered by a user event.

Full-screen mode is initiated in response to a mouse click or key press by the user; the movie cannot change Stage.displayState without user input. (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Stage.html#displayState)

You should have a second button that when pressed, runs Jotham's code. I'd go for a login button or any other button the user would press anyway.

Willson answered 24/3, 2009 at 12:2 Comment(0)
H
0

Sadly, the above post does not work. A swf with:

package {
    import flash.display.Sprite;
    import flash.display.StageDisplayState;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class Tester extends Sprite {
        public function Tester() {
            trace("Display States: Full="+StageDisplayState.FULL_SCREEN+"; Normal="+StageDisplayState.NORMAL);
            trace( "- Display State? "+stage.displayState);
            trace( "- Full Screen Enabled? "+(stage.hasOwnProperty("displayState")) );
            stage.addEventListener( MouseEvent.CLICK, function(evt:Event=null):void {
                trace("Attempting to change to FullScreen...");
                try {
                    stage.displayState = StageDisplayState.FULL_SCREEN;
                    trace("Success!");
                    stage.displayState = StageDisplayState.NORMAL;
                } catch(e:*) {
                    trace("Fail! "+e);
                }
            });
        }

    }
}

Will trace when FullScreen is disabled:

Display States: Full=fullScreen; Normal=normal
- Display State? normal
- Full Screen Enabled? true
Attempting to change to FullScreen...
Fail! SecurityError: Error #2152: Full screen mode is not allowed.

The problem being the Full Screen Enabled? true part.

Hejira answered 7/7, 2009 at 17:13 Comment(0)
G
-1

I believe we could check this capability with the try to listen to the

_root.stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreenListenter);

From my test on trying to allow for full screen mode in tight security set host, it will return null exception. I guess because of FullScreenEvent is not exist.

Girardo answered 14/6, 2011 at 22:3 Comment(0)
V
-3

EDIT: This is obsolete now (was a hack for FP 8.5 / 9)

The following will detect if your player has fullscreen availability (thx @mrdoob) :

var hasFullscreen:Boolean = (stage.hasOwnProperty("displayState"))
Vannesavanness answered 14/4, 2009 at 15:51 Comment(2)
This solution does not work as the displayState property is always available, even when allowFullScreen=false, tested in Flash 10.0.Sold
I know, as you can see this was posted 2 years ago while the issue was to detect if the player version actually supported this feature... kthxVannesavanness

© 2022 - 2024 — McMap. All rights reserved.