I'm trying to create a simple Air/Flex app which loads in user selected image and then resizes the window so that the selected image fits into it. If I have understood correctly, I need to set stage.scaleMode = StageScaleMode.NO_SCALE. However, when I call this I just get Error #1009 "Cannot access a property or method of a null object reference." Below is my default application mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init();"
applicationComplete="complete();"
xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:MenuBar id="myMenubar" width="832" itemClick="menuHandler(event);" labelField="@label" depth="0">
<fx:XMLList xmlns="">
<item label="File">
<item label="New" id="new"/>
<item label="Open" id="open"/>
<item label="Save" id="save"/>
<item label="Save As" id="saveas"/>
<item label="Quit" id="quit"/>
</item>
<item label="Edit">
<item label="Undo" id="undo"/>
<item label="Redo" id="redo"/>
<item label="Preferences" id="preferences"/>
</item>
<item label="Level">
<item label="New Room" id="newroom"/>
<item label="Properties" id="properties"/>
</item>
<item label="Objects">
<item label="Clickable" id="clickable"/>
<item label="Character" id="character"/>
<item label="Door" id="door"/>
<item label="Treasure" id="treasure"/>
</item>
</fx:XMLList>
</mx:MenuBar>
<s:SpriteVisualElement id="flashpunk" depth="-2">
</s:SpriteVisualElement>
<fx:Script>
<![CDATA[
import mx.collections.*;
import mx.controls.Alert;
import mx.core.IUIComponent;
import mx.events.MenuEvent;
import flash.display.StageScaleMode;
public var Maini:Main = new Main;
private function init():void
{
flashpunk.addChild(Maini);
}
private function complete():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
}
private function menuHandler(evt:MenuEvent):void
{
// Don't open the Alert for a menu bar item that
// opens a popup submenu.
Alert.show("Label: " + evt.item.@label + "\n" +
"Data: " + evt.item.@data, "Clicked menu item");
Maini.foo();
}
]]>
</fx:Script>
</s:WindowedApplication>
What I'm doing wrong?
Also, after I have set scalemode, how exactly I can set the window size to a new size? My debug player doesn't seem to recognize even [SWF(width = "1200", height = "600")] or attempts to set stage width and height. I'm using Flash builder 4.6.