flex 4 air app在新的模态窗口中打开模块

时间:2012-05-27 01:22:25

标签: flex module window

我是flex的新手,我正在尝试在新窗口模式中打开模块。 我已经设法加载并在容器(vbox)中添加一个模块,但我真正需要的是在单独的窗口中打开它们。 我能找到的所有帖子都是关于如何加载模块的示例,但没有关于如何显示它们的示例。 我在这里发了一个帖子 Modules and Panels issue 它看起来就像是我正在寻找的截图。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我找到了一种方法。 感谢所有指针

这是我为大家看到和使用的方式。如果您有更好的建议,请不要犹豫。

我正在使用一个组件:collapsabletitlewindow

mainapp.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"
   xmlns:components="de.aggro.components.*">
<fx:Script>
<![CDATA[

import de.aggro.components.*;

private function createWindow():void{
var w:window = new window;
w.title = "Window " + container.numChildren;
container.addChild(w);
}
]]>
</fx:Script>
<components:CollapsableTitleWindowContainer id="container" width="100%" height="100%" >
</components:CollapsableTitleWindowContainer>
<s:Button buttonDown="createWindow()" label="Create Window" />
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>

window.mxml

<?xml version="1.0" encoding="utf-8"?>
<components:CollapsableTitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
   xmlns:s="library://ns.adobe.com/flex/spark" 
   xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:components="de.aggro.components.*"     layout="absolute" width="400" height="300"
   creationComplete="initApp()" >
<fx:Script>
<![CDATA[
import mx.events.ModuleEvent;
import mx.modules.ModuleManager;
import mx.modules.IModuleInfo;        
import mx.core.IVisualElement;

public var info:IModuleInfo;

private function initApp():void {
info = ModuleManager.getModule("mod.swf");
info.addEventListener(ModuleEvent.READY, modEventHandler);           

/* Load the module into memory. Calling load() makes the
IFlexModuleFactory available. You can then get an
instance of the class using the factory's create()
method. */
info.load(null, null, null, moduleFactory);
}

/* Add an instance of the module's class to the display list. */        
private function modEventHandler(e:ModuleEvent):void {

this.addElement(info.factory.create() as IVisualElement);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

</components:CollapsableTitleWindow>

mod.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Module xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:LinkButton x="131" y="124" label="Module link"/>
</s:Module>