esadude
esadude

Reputation: 47

Does fullscreen event trigger resize in as3?

I'm trying to set up a fullscreen toggle and implement elements of fluidity however am uncertain if I have to include a dispatch event in the toggle for screen resize or will this be something that will be detected by the previous eventListener when the fullscreen toggle is activated?

Furthermore having looked online for several days on the subject, I'm still uncertain where it's optimal to place the resize control of my stage elements.

public function Main():void {
    addEventListener(Event.ADDED_TO_STAGE, init);

    stage.addEventListener(Event.RESIZE, resizeListener);
    stage.addEventListener(FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED, fullScreenRedraw);
}

private function resizeListener (e:Event):void {

    // - Do I put my resize control options here to cater for general resize or see below?
myMovie.width = stage.stageWidth; // etc
}
private function fullScreen(e:MouseEvent):void {
    try {
    switch (stage.displayState) {
        case StageDisplayState.FULL_SCREEN_INTERACTIVE:
            /* If already in full screen mode, switch to normal mode. */
            stage.displayState = StageDisplayState.NORMAL;

        break;
        default:
            stage.fullScreenSourceRect = null;
            // If not in full screen mode, switch to full screen mode.
            stage.dispatchEvent(new Event(Event.RESIZE));
            stage.displayState = StageDisplayState.NORMAL;
            stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        break;
        }
    } catch (err:SecurityError) {
        // ignore
    }
}
private function fullScreenRedraw(event:FullScreenEvent):void { 
    if ( event.fullScreen ) {
        // FULLSCREEN TRUE

        // - Or do I put my resize control options here to cater for the fullscreen as well?
        myMovie.width = stage.stageWidth; // etc

        var fScrField:TextField = new TextField();
        fScrField.y = 480;
        fScrField.text = "Redraw : True";
        addChild(fScrField);
    } else {
        // NON FULLSCREEN
        fScrField.text = "Redraw : False";
        addChild(fScrField);
    } 
}

** Amended handlers as mentioned on adobe. But conflicting info on what goes where and why?!

private function activateHandler(event:Event):void {
    trace("activateHandler: " + event);
}
private function fullScreenRedraw(event:FullScreenEvent):void { 
    if ( event.fullScreen ) {
        // Add additional panels if set/sizes 
        var fScrField:TextField = new TextField();
        fScrField.y = 480;
        fScrField.text = "Redraw : True";
        addChild(fScrField);
    } else {
        // Remove additional panels etc
        fScrField.text = "";
        fScrField.text = "Redraw : False";
        addChild(fScrField);
    } 
} 

Now I've been able to get it working in all manner of ways using the code above with variations but having spent days online googling there seems to be no efficiant or clear explanation which is best.

Any help on where this could be better optimised and made more efficient as I've kind of just crowbar'd it together from what I can work out.

Thanks in advance.

Upvotes: 0

Views: 1590

Answers (1)

mika
mika

Reputation: 1451

I think you're over-complicating it. Try that way:

// in your constructor:
fullScreenBtn.addEventListener(MouseEvent.CLICK, toggleFullScreen); 
stage.addEventListener(FullScreenEvent.FULL_SCREEN, refreshStage); 
stage.addEventListener(Event.RESIZE, refreshStage);
// then handle stage resize:
private function refreshStage(event:Event = null):void
{
  if ( stage.displayState == StageDisplayState.NORMAL ) {
    // handle stage in normal mode

  } else {
    // handle stage in full screen mode

  }
}
// handle stage state toggle:
private function toggleFullScreen(event:Event = null):void
{
  if ( stage.displayState == StageDisplayState.NORMAL ) 
    stage.displayState = StageDisplayState.FULL_SCREEN;
  else
    stage.displayState = StageDisplayState.NORMAL;
}

Upvotes: 1

Related Questions