PDA

View Full Version : ModuleLoader Issues


Hockey13
12-25-2008, 11:13 PM
Hello everyone. I suspect this is a relatively simple problem, but I can't figure out what is going on. Here's the scenario:

- I have a simple TabNavigator with three tabs: Home, Transactions, Positions
- Home is empty, Transactions and Positions each have a ModuleLoader that call separate modules. Each module is relatively complex and contains multiple components, custom components, and functions, both public and private.
- When a tab is clicked, this code is run:

private function loadTranModule():void {
if (mainnavigator.selectedIndex == 1) {
if (tranloader.url != "modules/MainTransactionsModule.swf") {
tranloader.url = "modules/MainTransactionsModule.swf";
tranloader.loadModule();
return;
} else {
return;
}
} else if (mainnavigator.selectedIndex == 2) {
if (posloader.url != "modules/MainPositionsModule.swf") {
posloader.url = "modules/MainPositionsModule.swf";
posloader.loadModule();
return;
} else {
return;
}
}
}

Now here's the problem:

When I load the transactions module, it works fine. However, if I load the positions module after the transactions module is already loaded, many of the functions simply do not work. If I load the positions module first, all functions work perfectly, but then if I load the transactions module after that, many of the functions in the transactions module don't work.

For example, I have a pie chart in the positions module. If I load the positions module first, you can hover over individual slices and it pops up the DataTips. If I open the transactions module first and the positions module second, you can only see the DataTips if you click the slices of the pie.

Another example: if I load the positions module first and then the transactions module, a function I have that calls an HTTPService object doesn't fire.

Can somebody please help? :confused:

EDIT:

Other examples that may help you in your quest to help me:

- ComboBoxes don't drop down when clicked in the second-loaded module.
- DateChoosers don't pop up with the calendar when selected in a DateField.
- Individual rows in DataGrids are selectable, but selecting the column headers does nothing (normally sorts by that column)
- Mouse hover events seem not to be firing, though click events seem to be firing at times.
- States aren't changing properly.

For reference, all of these things function perfectly when the module is loaded first in the application, but fail when it is loaded second.

drkstr
12-27-2008, 11:24 PM
I was hoping someone else could give you better advice on what you did wrong, but in lieu of that, I can show you how I do it and say that it works fine for me.

In some kind of view state changer (such as a TabNavigator), I have something like this:

<con:FlashContentTab width="100%" height="100%"
contentSource="ModuleOne.swf" />

<con:FlashContentTab width="100%" height="100%"
contentSource="ModuleTwo.swf" />

FlashContentTab.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
currentState="loadContent" horizontalScrollPolicy="off" >

<mx:Script>
<![CDATA[
import mx.controls.Alert;

[Bindable]
private var myContentSource:String;

public function get contentSource(): String {
return myContentSource;
}

public function set contentSource( data:String ): void {
myContentSource = data;
}

]]>
</mx:Script>

<mx:states>
<mx:State name="loadContent">
<mx:AddChild position="lastChild">
<mx:ProgressBar label="Loading..." labelPlacement="bottom" id="idLoadingProgress"
indeterminate="true" enabled="true" verticalCenter="0" horizontalCenter="0"/>
</mx:AddChild>
<mx:SetStyle name="horizontalAlign" value="center" />
<mx:SetStyle name="verticalAlign" value="middle" />
</mx:State>
</mx:states>

<mx:ModuleLoader id="idModuleLoader" url="{myContentSource}" ready="currentState = null;"
horizontalScrollPolicy="off" width="100%" height="100%"/>

</mx:Canvas>

I think your modules are bugging out because you are sharing the ModuleLoader instance between your modules without calling unloadModule() first. This is just a guess though, since I've never done it the way you are. I prefer to use seperate instances so each module only has to load the first time it's requested.


Best Regards,
~Aaron

Hockey13
12-29-2008, 07:03 AM
Thanks for the reply Aaron. I didn't use your suggestion (it replicated the error), but you got me thinking about alternatives. I then took a good look at the ModuleManager, and it does exactly what I need it to do.

http://lowpitch.com/blog/modulemanager-and-imoduleinfo-loading-flex-modules-dynamically/#more-19

Now all of my modules load properly. Thanks for your help.

Hockey13
12-30-2008, 08:59 PM
I figured it out. It turns out that you need to do this at the top of your AS code in your main application to get the ModuleLoader to work properly with multiple modules:

<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.managers.DragManager;
private var dragManager:DragManager;
private var popUpManager:PopUpManager;

etc etc etc

]]>
</mx:Script>

I'm not sure why you have to create a var for each of these managers, but doing this makes the modules work. Now my main application is back down to around 300kb, with each module at around 250-300kb....which is exactly where I wanted it. Using the ModuleManager seems to kick up the size of the main application, which can become quite problematic with a very large project size. Using the Manager in accordance with the instructions on the website I listed above, each module will be around 40kb, but the size of the main application grows and grows and grows, even though I think the sum size of all swfs in the project is slightly smaller than the sum while using the ModuleLoader.

For anyone coming across this solution, if it still doesn't work, try changing the "creationPolicy" of the main application to "auto" or "all." Using "queued" or "none" doesn't seem to work. I'll update here if I run into any more issues.

Blackened
09-16-2010, 01:54 AM
Guys, iīm having the same problem with ModuleLoader.

I have two modules, which uses RPC to gather data from the database to fill some comboboxes.

When i run one of the modules for the first time, it works fine.... if i try to reload, or load the other module, the comboboxes are not filled... and my clock cursor keeps running forever...

Please, i really need some help here.... i tried the Hockey suggestion but it didnīt solve my issue...

Thanks a lot!

Blackened