Skip to content

Instantly share code, notes, and snippets.

@RichardMarks
Created January 7, 2011 01:13
Show Gist options
  • Save RichardMarks/768945 to your computer and use it in GitHub Desktop.
Save RichardMarks/768945 to your computer and use it in GitHub Desktop.
FlashPunk and AIR - How to obtain the Window Dimensions
package
{
import flash.desktop.NativeApplication;
import flash.events.Event;
import flash.events.NativeWindowBoundsEvent;
import net.flashpunk.Engine;
import net.flashpunk.FP;
import net.flashpunk.Screen;
/**
* ...
* @author Richard Marks
*/
public class FPDemo extends Engine
{
public function FPDemo() { super(800, 600); }
override public function init():void
{
FP.engine.addEventListener(Event.ACTIVATE, OnActivate);
super.init();
}
private function OnActivate(e:Event):void
{
if (NativeApplication.nativeApplication.activeWindow)
{
trace("Window Dimensions:", NativeApplication.nativeApplication.activeWindow.width + "x" +
NativeApplication.nativeApplication.activeWindow.height);
FP.stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, OnResize);
}
}
private function OnResize(e:Event):void
{
if (NativeApplication.nativeApplication.activeWindow)
{
trace("Window Dimensions:", NativeApplication.nativeApplication.activeWindow.width + "x" +
NativeApplication.nativeApplication.activeWindow.height);
// resize flashpunk to handle the new window size
FP.width = NativeApplication.nativeApplication.activeWindow.width;
FP.height = NativeApplication.nativeApplication.activeWindow.height;
FP.screen = new Screen;
FP.bounds.width = Number(FP.width);
FP.bounds.height = Number(FP.height);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment