567 posts
    Has been part of the Envato Community for over 5 years Has referred 10+ members Has sold $10,000+ on Envato Market Has collected 10+ items on Envato Market
+4 more
iamdok says

I’m trying to differentiate between an “exit from Fullscreen Mode” called by a button or by other means. (esc key, ctrl+W on windows, click other window, etc etc)

I’m listening for the FullScreenEvent on the stage and can’t seem to figure out a way to check what exactly triggered the “exit”. The tagret of the event is the stage object in all cases.

It seems pretty simple, but I’m drawing a blank today! The code looks like the following:

function fullScreenHandler(e:FullScreenEvent):void
{
    //check to see if returning from fullscreen
    if(!e.fullScreen)
    {
        //check what triggered the event
        //if its the button - do something
        //if not - do something else
    }
}

Any Ideas? Donagh

8231 posts Community Moderator
    Has referred 10+ members Has sold $1,000+ on Envato Market Has collected 50+ items on Envato Market Attended one of our Meetups around the world
+9 more
MSFX Volunteer moderator says

I’ve never tried to do that but you could listen for KEY _DOWN and if its ESC set a boolean that is then used in your FullScreenEvent handler…?

567 posts
    Has been part of the Envato Community for over 5 years Has referred 10+ members Has sold $10,000+ on Envato Market Has collected 10+ items on Envato Market
+4 more
iamdok says

Hey Matt,

It seems that detecting the escape key press is not working inthe browser. Its fine in the IDE but once in the browser the KEY _DOWN event doesn’t fire when using the escape key to return to normal display more. I’ve had this problem before too.

That time I used the resize event, which worked for me but it won’t suffice here. Nor will the FullScreenEvent. Flash Fullscreen and the escape key hjave a buggy relationship.

I’m still trying….

3072 posts
    Has referred 50+ members Has sold $40,000+ on Envato Market Has collected 10+ items on Envato Market Had an item featured on Envato Market
+5 more
wickedpixel says

Use a proxy function when triggering the Fullscreen event. All the buttons should first call a function that sets a parameter like user_triggered = true; .. and you can use that when you do re-size calculation or what jobs you need. Set it back to false at the end of resize actions.

1161 posts
    Has referred 10+ members Has sold $40,000+ on Envato Market Has collected 50+ items on Envato Market Had an item featured in an Envato Bundle
+4 more
FlashTang says
Use a proxy function when triggering the Fullscreen event. All the buttons should first call a function that sets a parameter like user_triggered = true; .. and you can use that when you do re-size calculation or what jobs you need. Set it back to false at the end of resize actions.
fs_btn.addEventListener(MouseEvent.CLICK,mh)
fs_btn1.addEventListener(MouseEvent.CLICK,mh)

stage.addEventListener(Event.RESIZE,resizeHandler)
var user_triggered :Boolean
var _target
function mh(e:MouseEvent):void{
    _target=e.currentTarget
     if(e.currentTarget==fs_btn){
         user_triggered=true
     }
    toFull() 

}

function toFull(){
    stage.displayState==StageDisplayState.NORMAL?
    stage.displayState=StageDisplayState.FULL_SCREEN:
    stage.displayState=StageDisplayState.NORMAL
}
var memory:Boolean=false
function resizeHandler(e:Event):void{
    if(!memoey){
        if(stage.displayState==StageDisplayState.FULL_SCREEN){
            //your code
            memory=true
        }
    }else{

        if(stage.displayState==StageDisplayState.NORMAL){
            //your code
            if(user_triggered){
                //dosomething()
                user_triggered=false
            }else{

                    //...

            }
            memory=false
        }

    }
}

5322 posts The Dude Abides
    Located in United States Elite Author: Sold more than $75,000 on Envato Market Has sold $125,000+ on Envato Market Has been part of the Envato Community for over 5 years
+9 more
CodingJack says

function fullScreen(event:Event):void {

    if(event is FullScreenEvent) {

        // triggered by escape key

    }
    else {

        // event is MouseEvent
        // triggered by button

    }

}

567 posts
    Has been part of the Envato Community for over 5 years Has referred 10+ members Has sold $10,000+ on Envato Market Has collected 10+ items on Envato Market
+4 more
iamdok says

Thanks guys for your input.

Finally solved it. The problem was that the esc key was retarded so I couldn’t rely on that. Also I couldn’t use the FullScreenEvent because it was fired even if the user clicked a button to exit fullscreen mode and the target was always the stage. I also didn’t want to use the resize function as it was a bit too messy for me.

What I did was create 2 functions, 1 to toggle fullscreen mode and 1 to be triggered by the fullscreen event. I only add the fullscreenEvent listener when the fullscreen mode was entered (by user click always) therefore it will only be handling the return event and not the enter event. Then if the user clicked to exit, I quickly removed the fullscreen Event listener in the first function so as not to trigger the fullscreenEvent function, then dealt with the button’s state change. So if the user exited fulllscreen mode using any other means the fullscreenEvent’s function would run and handle the button state.

Simplified code:

function linkClick(e:TextEvent):void
{
    toggleFullscreen();
    modifyBtn();
}

//toggle fullscreen
function toggleFullscreen():void
{ 
    //remove fullscreen event listener
    stage.removeEventListener(FullScreenEvent.FULL_SCREEN, fullScreen);

        //toggle 
    if (fullsOn == false) 
    {
        stage.displayState = StageDisplayState.FULL_SCREEN;
        fullsOn = true;
        stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreen);
    } 
    else 
    {  
        stage.displayState = StageDisplayState.NORMAL;
        fullsOn = false;
    }

}

//called on fullscreen exit
function fullScreen(e:FullScreenEvent):void
{
    //user exited fullscreen using keyboard
    fullsOn = false;
    modifyBtn();
    stage.removeEventListener(FullScreenEvent.FULL_SCREEN, fullScreen);
}

So this now covers exiting fullscreen mode by any means. (Ctrl+W on windows, Esc key, click another window eg. on a dual monitor setup, user mouse click etc.)

If you’re wondering what the TextEvent is in the first function – my fullscreen button isn’t a button but a hyperlink in a body of html text. Which has it’s own targeting problems :)

So thanks again. Hopefully I won’t be annoying everyone here on the forums again with this fullscreen nonsense !!

Donagh

by
by
by
by
by
by