For a smaller project, I needed to find a way to restart my Adobe AIR application, this had to be invoked by itself …
After some research I found a working examples, thanks to Flex Internals.
import mx.core.Application;
import mx.core.WindowedApplication;
import adobe.utils.ProductManager;
public function restart():void
{
var app:WindowedApplication = WindowedApplication(Application.application);
var mgr:ProductManager = new ProductManager("airappinstaller");
mgr.launch("-launch " + app.nativeApplication.applicationID + " " + app.nativeApplication.publisherID);
app.close();
}
import mx.core.WindowedApplication;
import adobe.utils.ProductManager;
public function restart():void
{
var app:WindowedApplication = WindowedApplication(Application.application);
var mgr:ProductManager = new ProductManager("airappinstaller");
mgr.launch("-launch " + app.nativeApplication.applicationID + " " + app.nativeApplication.publisherID);
app.close();
}
Just make sure your “allowBrowserInvocation” option is turned on (value to true) in AIR application descriptor template
true
Also interesting reads:
Hi man, cheers for the code it worked a treat for me. I had to change it slightly for flash and thought it maybe useful for some people. Heres what i did.
the code is basicly the same, only dif is you wont have the “mx.core.WindowedApplication” libray to import. so instead do this:
mgr.launch("-launch " + NativeApplication.nativeApplication.applicationID + " " + NativeApplication.nativeApplication.publisherID);
NativeApplication.nativeApplication.exit();
you will need to include:
in your imports.
Then look were your airfiles are being created and you will see a file called ["name of your air file"]-app.xml . open this and as mentiond before make sure that false is set to true:
Insert Code here
Insert Code here
This may be obvious to some, but it’s important:
Put this in the mxml/main of the application; it won’t work if you use that block of code in an external actionscript custom class you create.
Works for me on both osx 10.6.8 and windows 7 with an air app from flash pro using the above code from Luke…
…UNLESS… an flvplayback component loads a video! After that, it will only close and not restart. I’ve tried everything under the sun to destroy the video/component before the restart to no avail. Any suggestions are very appreciated, thanks.
same for me it works in both 10.6 and windows 7. hopefully it works on XP??
I’ve tried to get this going 10 thousand different ways, it won’t work. I can get it to work if run from a button click event from my main.mxml. But if I dispatch and event from a sub.mxml, my main.mxml listens for that, then runs a function in main.mxml it will close the app, but not restart.
The button click runs the exact same function, so I know the function code works. Any help?