我正在尝试创建一个简单的 Air/Flex 应用程序,该应用程序加载用户选择的图像,然后调整窗口大小以使所选图像适合它。如果我理解正确的话,我需要设置stage.scaleMode = StageScaleMode.NO_SCALE。但是,当我调用它时,我只会收到错误 #1009“无法访问空对象引用的属性或方法”。下面是我的默认应用程序 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>
我做错了什么?
另外,在我设置了 scalemode 之后,如何将窗口大小设置为新大小?我的调试播放器似乎甚至无法识别 [SWF(width = "1200", height = "600")] 或尝试设置舞台宽度和高度。我正在使用 Flash builder 4.6。