Flex中解决Parsley框架中注入窗口

<?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:parsley="http://www.spicefactory.org/parsley"
					   xmlns:v="com.sununion.mobile.seller.view.*"
					   creationComplete="windowedapplication_creationCompleteHandler(event)"
					   addedToStage="addedToStageHandler(event)"
					   minWidth="800" width="800"
					   minHeight="600" height="600"
					   >
	<fx:Declarations>
		<parsley:ContextBuilder>
			<parsley:FlexConfig type="{MyConfig}"/>
		</parsley:ContextBuilder>
		<parsley:Configure  />
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import com.sununion.mobile.seller.view.LoginView;
			
			import mx.core.Window;
			import mx.events.CloseEvent;
			import mx.events.FlexEvent;
			import mx.managers.PopUpManager;
			
			import spark.components.TitleWindow;
			
			import org.spicefactory.parsley.core.context.Context;
			
			private var win:TitleWindow = new TitleWindow();
			
			[Inject]
			public var context:Context;
			
			private function showPopup() : void {				
				// set properties
				win.addEventListener(CloseEvent.CLOSE, titleWindow_close);   
				context.viewManager.addViewRoot(win);
				PopUpManager.addPopUp(win, this, true);  
				PopUpManager.centerPopUp(win);   
			}
			
			private function titleWindow_close(evt:CloseEvent):void {   
				PopUpManager.removePopUp(win);   
			}   
			
			[Init]
			public function init():void{
				showPopup();
				
				var authWindow:Window = new Window();
				authWindow.title = "Authenticate";
				authWindow.systemChrome = NativeWindowSystemChrome.STANDARD;
				authWindow.type = NativeWindowType.NORMAL;
				authWindow.width = 600;
				authWindow.height = 800;
				
				context.viewManager.addViewRoot(authWindow);
				
				var auth:LoginView = new LoginView();
				authWindow.addChild(auth);
				authWindow.open(true);
			}
			
			protected function windowedapplication_creationCompleteHandler(event:FlexEvent):void
			{
			}
			
			protected function addedToStageHandler(event:Event):void
			{
			}
			
		]]>
	</fx:Script>
</s:WindowedApplication>

在parsley框架下使用Flex的弹出窗口和原生的AIR窗口时,需要做一些处理使框架知道这些窗口的存在,如上述代码所示。原因是它们和主程序模块下的视图层次树是分离的。Flex Popup一般是在SystemManager下面的某个地方。而Native AIR Window甚至来自于自己的SystemManager。


参考:http://www.spicefactory.org/parsley/docs/2.0/manual/?page=roadmap&section=intro


你可能感兴趣的:(Flex中解决Parsley框架中注入窗口)