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

Apache Flex

Avatar of undefined
Last Comment
SreeramojuPradeep

8/22/2022 - Mon
dgofman

You can use either

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

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

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

ASKER
SreeramojuPradeep

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

I.e from preinitialize...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Fuzzy_Logic_

Have you set allowBrowserInvocation to true in the AIR descriptor file?



ASKER CERTIFIED SOLUTION
SreeramojuPradeep

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
dgofman

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

ASKER
SreeramojuPradeep

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.......
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
dgofman

I don't have such errors from my example I can click Reload button million times
ASKER
SreeramojuPradeep

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...
dgofman

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/Web_Development/Web_Languages-Standards/Flex/Q_26946951.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


Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
SreeramojuPradeep

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

dgofman

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
ASKER
SreeramojuPradeep

good
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.