欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

flex 模块动态加载

程序员文章站 2022-04-29 20:22:17
...

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import flash.utils.setTimeout;
			
			import mx.controls.Alert;
			import mx.core.IVisualElement;
			import mx.events.FlexEvent;
			import mx.events.ModuleEvent;
			import mx.modules.IModuleInfo;
			import mx.modules.ModuleManager;
			
			import spark.components.Button;
			private var mInfo:IModuleInfo=null;
			protected function application1_initializeHandler(event:FlexEvent):void
			{
				mInfo=ModuleManager.getModule("M.swf");
				mInfo.addEventListener(ModuleEvent.READY,modulReady);
				mInfo.addEventListener(ModuleEvent.ERROR,modulError);
				mInfo.addEventListener(ModuleEvent.PROGRESS,modulProgress);
				mInfo.load();
			}
			private function modulError(e:ModuleEvent):void{
				Alert.show('modulError');
			}
			private function modulProgress(e:ModuleEvent):void{
				log.text=e.bytesLoaded+'%'+e.bytesTotal;
			}
			private function modulReady(e:ModuleEvent):void{
				var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo;
				var b:IVisualElement=e.module.factory.create() as IVisualElement;
				g.addElement(b);
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<s:Group width="500" height="500" id="g">
		<s:Label x="72" y="249" text="标签" width="313" id="log"/>
	</s:Group>
</s:Application>