Link to home
Start Free TrialLog in
Avatar of SreeramojuPradeep
SreeramojuPradeepFlag for India

asked on

Reloading a complete air application

Hi,

I am developing an air application....

I have login and logout buttons in application...

Once the user logout of  the application i would like to reload the complete air application how can i do it... or on click of button also

I am  using flex4 SDK

i am using the below code snippet but not working at all....


 
import flash.desktop.NativeApplication;
			import adobe.utils.ProductManager;
			private function lawpadAppRestart():void{
				var app:WindowedApplication = WindowedApplication(FlexGlobals.topLevelApplication);
				var mgr:ProductManager = new ProductManager("NeuronLawPAD");
				mgr.launch("-launch " +
					app.nativeApplication.applicationID + " " +
					app.nativeApplication.publisherID);
					app.close();
			}

Open in new window

Avatar of dgofman
dgofman
Flag of United States of America image

You can use either

ExternalInterface.call("history.go", 0);

or
                              
ExternalInterface.call("document.location.reload", true);
Avatar of SreeramojuPradeep

ASKER

Not reloading.................. my application is stand alone i.e desktop application
I get the below error...
 
Error: Error #2067: The ExternalInterface is not available in this container. ExternalInterface requires Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime.
	at Error$/throwError()
	at flash.external::ExternalInterface$/call()
	at ClipBoard/button1_clickHandler()[D:\AdobeFlash45_WorkSpace\ClipBoard\src\ClipBoard.mxml:33]
	at ClipBoard/___ClipBoard_Button3_click()[D:\AdobeFlash45_WorkSpace\ClipBoard\src\ClipBoard.mxml:48]

Open in new window

i would like to know how to reload the complete air application....on click of a button...

I.e from preinitialize...
Have you set allowBrowserInvocation to true in the AIR descriptor file?



ASKER CERTIFIED SOLUTION
Avatar of SreeramojuPradeep
SreeramojuPradeep
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Let me give you another solution, base on your req.
If I understood you want to reload / reset all default components settings
So, instead reloading whole application I will suggest to split by main MXML and module MXML
You can add Module file from Flash Builder. File->New->MXML Module
All your containers and children move to this file leave in the main only ModuleLoader code and global reload function. In my example I create Module MXML file and gave name "MyModule" its genereting MyModule.swf file every time when I modified any code in this class or class component attached from my Module class

Main.MXML

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:mccune="com.dougmccune.containers.*"
					   xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx">
	<fx:Script>
		<![CDATA[
			private static const MODULE_URL:String = "MyModule.swf";

			public function reload():void{
				loader.unloadModule();
				loader.loadModule(MODULE_URL);
			}
		]]>
	</fx:Script>
	<mx:ModuleLoader id="loader" width="100%" height="100%" url="{MODULE_URL}"/>
</s:WindowedApplication>

Open in new window


MyModule.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Module 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="100%" height="100%">
	<fx:Script>
		<![CDATA[
			import mx.core.FlexGlobals;

			private function onReload():void{
				//Call reload function in main MXML
				FlexGlobals.topLevelApplication.reload();
			}
		]]>
	</fx:Script>
	<s:Button label="Reload" click="onReload()"/>
	<s:TextArea text="Override a default text. I will reset after reloading"/>
</mx:Module>

Open in new window

I implemented the solution....its reloading properly but once i perform the same actions that was performed previously..... i get the below error............

 
TypeError: Error #1034: Type Coercion failed: cannot convert mx.managers::HistoryManagerImpl@bfd45e1 to mx.managers.IHistoryManager.
	at mx.managers::HistoryManager$/get impl()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\HistoryManager.as:101]
	at mx.managers::HistoryManager$/register()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\HistoryManager.as:149]
	at mx.containers::ViewStack/commitProperties()[E:\dev\hero_private\frameworks\projects\mx\src\mx\containers\ViewStack.as:741]
	at mx.containers::TabNavigator/commitProperties()[E:\dev\hero_private\frameworks\projects\mx\src\mx\containers\TabNavigator.as:566]
	at mx.core::UIComponent/validateProperties()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:8209]
	at mx.managers::LayoutManager/validateProperties()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597]
	at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\LayoutManager.as:813]
	at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]

Open in new window


I have a carousel with local connection from which i move between different views.......
I don't have such errors from my example I can click Reload button million times
No i implemented the solution in my application....

where the module contains...
 
<mx:ViewStack id="mainView" width="100%" height="100%" creationPolicy="auto" initialize="init(event)" change="viewChangeHandle(event)">
		<mx:Canvas>
                        ...............
		</mx:Canvas>
		<mx:Canvas>
                        ................
		</mx:Canvas>
		<mx:Canvas>
                       ....................
		</mx:Canvas>
	</mx:ViewStack>

Open in new window


The child contains tab navigators also....

Only reload function in main.mxml where module is included using module loader.....

Is this happening i am using viewstack....tab navigators....
I checked the same using simple example...
pls run this we get the same above mentioned error...

MyModule.mxml
 
<?xml version="1.0" encoding="utf-8"?>
<s:Module 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="100%" height="100%">
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.core.FlexGlobals;
			
			private function onReload():void{
				//Call reload function in main MXML
				FlexGlobals.topLevelApplication.reload();
			}
		]]>
	</fx:Script>
	<s:VGroup>
		<s:Button label="Reload" click="onReload()"/>
		<s:TextArea text="Override a default text. I will reset after reloading"/>
		
		<mx:ViewStack width="100%" creationPolicy="auto">
			<mx:Canvas>
				<mx:Text text="Hi gud morning"/>
			</mx:Canvas>
			<mx:Canvas>
				<mx:Text text="Hi gud afternoon"/>
			</mx:Canvas>
			<mx:Canvas>
				<mx:Text text="Hi gud evening"/>
			</mx:Canvas>
		</mx:ViewStack>
	</s:VGroup>
	
</s:Module>

Open in new window


When we use viewstack we come across the same error...
I already gave you answer on this question let me repeat my solution again you may accept finally form my post

https://www.experts-exchange.com/questions/26946951/History-Management-for-desktop-application.html

This example working for me without any problems. I can type text in ViewStack children and changing back and for using Numstepper, all values will cached until I will not select Reload button in this case selected child container will reload

<?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">
	
	<fx:Script>
		<![CDATA[
			import mx.core.Container;

			protected function doReload():void
			{
				var child:Container = viewStack.getChildAt(viewStack.selectedIndex) as Container;
				if(child.childDescriptors != null){
					var n:int = child.childDescriptors.length;
					for (var i:int = n - 1; i >= 0; i--)
					{
						var component:DisplayObject = child.removeChildAt(i);
						var oldVisibility:Boolean = component.visible;
						component = viewStack.createComponentFromDescriptor(child.childDescriptors[i], false) as DisplayObject;
						component.visible = oldVisibility;
						child.addChild(component);
					}
				}
			}
		]]>
	</fx:Script>
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<s:NumericStepper id="ns" minimum="0" maximum="2"/>
	<mx:ViewStack id="viewStack" width="100%" selectedIndex="{ns.value}">
		<mx:Canvas>
			<mx:TextInput text="Hi gud morning" minWidth="300"/>
		</mx:Canvas>
		<mx:Canvas>
			<s:TextInput text="Hi gud afternoon" minWidth="300"/>
		</mx:Canvas>
		<mx:Canvas>
			<mx:TextInput text="Hi gud evening" minWidth="300"/>
		</mx:Canvas>
	</mx:ViewStack> 
	<mx:Button label="Reload" click="doReload()"/>
</s:Application> 

Open in new window


k,,,
But since i am using creationpolicy for viewstack has auto.....
and on initialise if using

 
private function init(event:Event):void 
			{ 
				var vs:ViewStack = event.target as ViewStack;
				for(var i:uint = 0; i < vs.numChildren; i++){
					var containerChild:INavigatorContent = vs.getChildAt(i) as INavigatorContent;
					if (containerChild && containerChild.deferredContentCreated == false){
						if(i < 1) //add only children 0, 1, 2 on initialize
							containerChild.createDeferredContent();
					}
				}
			}

Open in new window


While reloading the viewstack children will it not be a problem since i have to use creation policy has auto......

Also
I am using model locator also....i would like the application gets preinitialised again so that the model locator will be initialised again ....or should we call a method explicitly which sets the values to null manually......

Pls make me clear on these two points

You can reset manually or use ModuleLoader inside your ViewStack (each canvas is new Module/SWF)  is guaranteed will reload SWF file and run preinitialize function