My application has a couple of modules which am loading as thus in my application.
<local:moduleloader url="Module1.swf" id="modulel" />
<local:moduleloader url="Module2.swf" id="module2" />
Then while loading each module I am showing the progress bar. The progress bar shows but does not go away. It remains above the whole frame of the application. The module loader is as follows:
(Also note that in Flex 3 the same works, but am using Flex 4 and in Fx 4 it does not)
<mx:ModuleLoader 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="*"
creationComplete="initTheModuleLoader()">
<fx:Script>
<![CDATA[
import mx.core.Application;
import mx.core.FlexGlobals;
private var ParentApp:* = FlexGlobals.topLevelApplication;
private var standin:DisplayObject;
private function initTheModuleLoader():void {
addEventListener("loading", onLoading);
addEventListener("progress", onProgress);
addEventListener("setup", onSetup);
addEventListener("ready", onReady);
addEventListener("error", onError);
standin = panel;
}
private function onUrlChanged(event:Event):void {
if (url == null) {
if (contains(standin))
removeChild(standin);
} else {
if (!contains(standin))
addChild(standin);
}
progress.indeterminate=true;
}
import mx.controls.Alert;
private function onLoading(event:Event):void {
//progress.label=languageXml.lastResult.progress.progressonLoading +' ' + url;//Loading module
progress.label = "Loading module" + ' ' + url;//Loading module
if (!contains(standin))
addChild(standin);
progress.indeterminate=true;
}
private function onProgress(event:Event):void {
//progress.label=languageXml.lastResult.progress.progressonProgress; //Loaded %3%%...
progress.label = "Loaded %3%%..."; //Loaded %3%%...
progress.indeterminate=false;
}
private function onSetup(开发者_Python百科event:Event):void {
//progress.label=String(languageXml.lastResult.progress.progressonSetup).replace('###',url)
progress.label = "on SetUp";
progress.indeterminate=false;
}
private function onReady(event:Event):void {
//progress.label= String(languageXml.lastResult.progress.progressonReady).replace('###',url);
progress.label = "onReady";
if (contains(standin))
removeChild(standin);
}
private function onError(event:Event):void {
//progress.label=languageXml.lastResult.progress.progressonError + " " + url;
progress.label = "Error";
}
private function onUnload(event:Event):void {
if (url == null) {
if (contains(standin))
removeChild(standin);
} else {
if (!contains(standin))
addChild(standin);
}
progress.indeterminate=true;
progress.label="Module " + url + " was unloaded!";
}
]]>
</fx:Script>
<mx:Panel id="panel" width="100%" borderStyle="none" >
<mx:ProgressBar width="100%" id="progress" source="{this}" />
</mx:Panel>
</mx:ModuleLoader>
Anybody could help on this?
Your onReady handler removes the standin, but not the progress bar.
I got it.
Firstly in Flex 3 putting the InitModuleLoader function in creationComplete works but in Flex 4 this method has to be specified in initialize.
Secondly the does not show in Flex 4 (it does in Flex 3), so I replaced mx:Panel by mx:HBox or s:Group
Thats all and it work.
But as J_A_X suggested above its better to use the Fx 4.5 as it has a new moduleLoader thats skinnable which might render it pretty cool.
精彩评论