我的目标是在主应用程序窗口的单独子窗口中显示通过URLLoader获取的文本。最初,我使用了NativeWindow并运行良好,但是我需要实现Scrollbars,所以我一直在尝试将以前在NativeWindow类中显示的内容包装到sparks标签中,但是我遇到的问题很少。我的代码基于Adobe的示例:
//open a new instance of the document window called from main window
docWindow = new DocumentWindow();
docWindow.open();
DocumentWindow代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- aircomponents/src/myComponents/DocumentWindow.mxml -->
<s:Window 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="550" height="450">
<s:Label text="This is a document window."
horizontalCenter="0" verticalCenter="0"/>
</s:Window>
所以我创建了从主窗口调用的这段代码:
var reqString:String = Global.serverURL+"imports/tkw/loginfo.jsp?InfoId="+infoId;
var date:Date = new Date();
var logWindow:ContentWindow = new ContentWindow()
logWindow.title=Tr.phrase("Common","Import log wykonany ") + date.toUTCString();
logWindow.open();
logWindow.loadContent(reqString);
这是ContentWindow.mxml的代码:
<s:Window
preinitialize="init()"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:s="library://ns.adobe.com/flex/spark"
width="{_width}" height="{height}" backgroundColor="#FFFFFF"
>
<mx:Script>
<![CDATA[
import mx.controls.MenuBar;
import mx.controls.menuClasses.MenuBarItem;
import spark.components.Window;
[bindable]
public var _urlString:String;
[bindable]
public var _width:Number=600;
[bindable]
public var _height:Number=400;
[Bindable]
public var _ownerWindow;
private var _text:String="test";
private var _menu:MenuBar = new MenuBar();
private var _menuItem:MenuBarItem = new MenuBarItem();
private var nw:NativeWindow = new NativeWindow(new NativeWindowInitOptions());
private function init():void
{
_menu.addChild(_menuItem);
}
public function loadContent(urlString:String, contentType:String="text", urlMethod:String=URLRequestMethod.GET):void
{
//if(contentType=="text")
loadTextContent(urlString, urlMethod);
//if(contentType=="HTML")
//loadHTMLContent(urlString, urlMethod);
}
private function loadTextContent(urlString:String, urlMethod:String):void
{
var urlReq:URLRequest = new URLRequest(urlString);
urlReq.method=urlMethod;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onTextLoaded);
loader.load(urlReq);
}
private function onTextLoaded(e:Event):void
{
var loader:URLLoader = e.target as URLLoader;
_text=e.target.data;
_menuItem.data=_text;
// logText.text=_text;
_menuItem.addEventListener(MouseEvent.CLICK,saveTextContent);
}
private function saveTextContent(e:Event):void
{
var file:FileReference = new FileReference();
file.save(e.target.data as String, "log.txt");
}
]]>
</mx:Script>
<mx:Label id="te" text="a"/>
<mx:VBox id="t">
<s:TextArea id="logText" >
</s:TextArea>
</mx:VBox>
当前结果是创建了窗口,但其中没有显示任何内容。当我调试时,我发现其中包含的元素根本没有初始化(这就是为什么“ logText.text = _text被注释掉)的原因,这就是我试图至少显示标签的原因。我也尝试使用此标签.stage.addChild(oneOfTheComponentsHere),但它也没有做任何更改。 任何建议将不胜感激,在此先感谢。