AS3 Running an External Program - actionscript-3

So I am making something for a bit of fun but I was just wondering if it was possible to run an external program for example opening Chrome (and maybe even searching on it) by pressing a button.

You should be able to launch an external program by wrapping your .swf file. There are multiples ways to do that:
You can use the Flash to create a projector which will allow to use fscommand() with the exec argument: fscommand("exec","/path/to/your/installed/Chrome");
You can create an AIR application and use NativeProcess
Use a 3rd party wrapper (such as mProjector, zinc, etc.)
First option should be easiest to test. Keep in mind that this feature has been coming and going with various versions of Flash. In older versions of Flash you simple used the Standalone Flash Player and Create Projector option from the File Menu. As long as you can use this feature, this is the simplest, but you won't have a lot of options.
If you plan to have more control over the application you're launching from as3, consider using AIR as you get access to the filesystem and processes.
The 3rd party tools may be outdated now and for a simple app launch may be overkill, but it's good to know they're there (in case you may need some otherwise unsupported feature)

Basically, flash can't call external programs without AIR.
But if this case allows to use ActiveX, it's possible to run some external programs.
Needless to say, it works on IE only.
JS Code
function openChrome(url){
wshshell=new ActiveXObject("WScript.Shell");
wshshell.run("chrome.exe --new-window " + url);
}
function openExcel(path){
wshshell=new ActiveXObject("WScript.Shell");
wshshell.run("excel " + path);
}
AS Code
ExternalInterface.call("openChrome", "http://www.google.com");
ExternalInterface.call("openExcel", "C:\\foo\\bar.xlsx");

Related

Can we use wxWidget to save a webpage onto the disk

I was using wget with system call (c++) to save a webpage from internet to my HD in a program. Now I want to use wxWidget to do the same. Is there anyway I can do that and still have the generic behaviour of wget? (i.e. i give a link to a pdf file n then a pdf file is saved)
I found this link http://wiki.wxwidgets.org/Download_a_file_from_internet
but I have no idea how to convert wxString to a pdf/mp3 file according to the url entered.
Could anyone help please. I am working on an open source project for the first time and I encountered this wxWidget just now
If you are happy using wget with a system call, then why not continue to do so?
wxWidgets is a GUI framework, with a lot of extra convenience functions included. You don't HAVE to use them. You can still use whatever C++ features, utilities and packages that your are familiar with.
Here is a link to Wget for Windows
You can use wxHTTP (as described here) or use wxURL and GetInputStream()

Adobe Air - Open app in fullscreen

I created an Air desktop app with Flash CS 5. Usually Windows (XP) is opening an application (like Firefox) with the latest set size and position.
For my installed Air app it's always just the default one.
How to start it with the latest used size and position?
Thanks.
Uli
hope this will work for you:
http://cookbooks.adobe.com/post_Using_the_FullScreen_functionality_in_AIR-8004.html
http://blog.ochodurando.com/2010/04/adobe-air-e-fullscreen/
You need to save a record somewhere that remembers the window's size, and possibly position. If your app has a preferences file, this would be an ideal place to store that information. Then, whenever your app starts, it checks for this information and resizes the window if any values are found.
Most popular programs include this feature (and don't even mention it, since it's pretty basic UI), but it's done intentionally and not as a default for every application. Thus if you want it, you have to program it in.
You can read and write to application.xml. You'll find there and nodes.
file = new File( File.applicationDirectory.nativePath + "/META-INF/AIR/application.xml" );
Adobe restrict writing access to application diractory but this trick is useful if you don't want to create a separate config file in app-storage:/ folder, which is of course prefered.

How do I add an event to URLLoader Class?

Keeping into consideration the Actionscript 3 event HTTPStatusEvent:HTTP_RESPONSE_STATUS, which is ONLY AVAILABLE for AIR (and not Flash 9/10)
Quote from site:
Language Version: ActionScript 3.0
Runtime Versions: AIR 1.0, Flash Lite 4
I would like to add the same EVENT by extending the HTTPStatusEvent Class of Actionscript 3 for Flash (9/10).
I'm working on Adobe Flash CS3 and I'm trying to get the "last" location of a URL loader (I'm calling a php with a header("Location: ..."); ) so I need the location after it changes. This should be made directly by flash and I cannot use php proxies not other.
Also, I cannot find the source code of the AIR HTTPStatusEvent Class, which I need to get the event (specifically, the responseHeaders and responseURL properties that the AIR class has).
Of course, if you know of any other way to accomplish this, feel free to share it.
You can't do it this way.
Think about it: You are trying to add behavior to the URLLoader class by extending an event class that is thrown from there. Figuratively speaking, it's a bit like changing the paper size when you've only written letters to your next door neighbor, and now you want them to go overseas - unless you also give them to the mail main, that's not going to be very successful...
I've stumbled across a number of forum threads discussing this, and most of them seem to agree that Adobe prevented access to response headers in Flash versions prior to FP10 / AIR due to some sort of security issue. I'm not sure how much of this information is accurate, but I am quite confident that there is no way to get around this - you can't get the Location:header in older Flash versions.
You will have to find some other workaround. For example, if you have access to the PHP script, you could add an HTML comment containing the redirect location, and parse that value in ActionScript.
<!-- Location: http://google.com/ -->

Possible to natively create hidden file or directory using AS3 / AIR?

Am I blindly missing a method for creating a hidden file or directory in an AIR / AS3 desktop app? Re-combing the docs, all I see is the File.isHidden read-only property. I know I could do this via NativeProcess and native code, but I'm hoping to avoid creating native code.
Thanks!
In Mac and Linux you only need to put a dot (".") in front of the file/folder name.
For Windows is a little bit more complicated since it is a property of the file. I've done it in the past by calling the "attrib" command, but yeah, you would need NativeProcess for that AFAIK.
Juan

Can an AIR app be programmed to handle a URL protocol?

I'm writing what is essentially a browser in Adobe AIR (ActionScript, not AJAX). A great bit of functionality to implement would be protocol handling. iTunes, for instance, handles itms protocols; when your friend sends you a link beginning with "itms://", it's going to launch iTunes as long as it's installed. Is there a way to write an AIR app (requiring AIR 2 would be fine) that can be the "handler" for a protocol in this way?
There is no way, programatically speaking, to specifically handle a particular protocol. However, there is InvokeEvent. InvokeEvent will be fired when the application is "invoked", either when it's explictly launched or if an associated file or URL is activated.
The process of associating your app with a particular file type or protocol scheme is separate and application-dependant. In iOS, for example, you would need to specify the protocol in Info.plist under CFBundleURLTypes/CFBundleURLSchemes.
Yes. You can use the URLLoader class to download data in binary form (URLLoader.BINARY) and then parse this as appropriate. See this CS3 documentation on working with external data.
http://www.patrick-heinzelmann.de/labs/lastfm/
I'm not sure exactly how it works and I don't see a way to download the app, so I can't even test it, but maybe it will help...
Check out this page. I am trying to find out the same thing, but I haven't found any solution to do it with just Air yet. Seems like you might need a custom installer to setup the correct registry entries, and a proxy application to "wash" the input to a correct format that then can start your application with the correct command line parameters. Hope this can be of any assistance.