How to executes a .bat file on local machine from adobe animate application? - actionscript-3

I build a button on adobe animate project and I want to import a (.bat) file but it's open with browser. how does it open with Cmd ????
import flash.net.URLRequest;
var batURL:URLRequest=new URLRequest("71.bat")
function btnDown(event:MouseEvent):void{
navigateToURL(batURL,"_self");
}
button.addEventListener(MouseEvent.CLICK,btnDown)

In order to access the local computer, you'll have to compile your application using the Adobe AIR SDK.
Using Air, you can start a native process to execute your bat file on Windows.
var file:File = new File("C:\windows\system32\cmd.exe");
var processArgs:Vector.<String> = new Vector.<String>();
processArgs.push("/c C:\path\to\bat\71.bat");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = processArgs;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);

Related

How to share the image in the application as3

I am using the Android-Sharing-Extension-ANE.
How to share an image as result from my application code?
This code does not work
var bitmap:Bitmap = ...;
// encoding image by native encoder (availible on FP 11.3/AIR 3.3 or newer)
var bitmapBytes:ByteArray = bitmap.bitmapData.encode(new Rectangle(0, 0, bitmap.width, bitmap.height), new JPEGEncoderOptions(70)));
var file:File = File.documentsDirectory.resolvePath("image_for_share.jpg");
var stream:FileStream = new FileStream(); // write file to local memory
stream.open(file, FileMode.WRITE);
stream.writeBytes(fileBytes);
stream.close();
SharingExtension.shareImage(file, "Choser title", "Message"));
"How do I share an image with this ANE I use Animate CC?"
From the "Read Me" of that ANE:
How to use:
Connect com.illuzor.extensions.SharingExtension.ane file to your
Android AIR project.
Import com.illuzor.sharingextension.SharingExtension;
Since it's not clear what your exact problem is (because not enough information given)...
(1) Did you import the required Class files?
import com.illuzor.sharingextension.SharingExtension;
btn_Share.addEventListener (MouseEvent.CLICK, shareAndroid);
function shareAndroid (event: MouseEvent): void
{
//# If this works then replace with bitmap code (use shareImage)
SharingExtension.shareText ("AS3 Test", "This text is from AS3 code");
}
(2) Did you add (connect) the ANE to your project (in Settings)?
Read this for advise on adding an ANE: https://www.adobe.com/devnet/air/articles/using-ane-in-flash.html

Zipping a file and saving it to local disk using Actionscript 3 & FZip

i made a flash desktop application that requires the user to save a file to his computer, in this case i have a lot of images and i want the user to save them on his computer, the images are on a folder called "imgs", i'm using one image in this case, i tried to do the following using FZip:
import deng.fzip.*;
import flash.filesystem.*;
import flash.filesystem.File;
//retrieve the image from the "imgs" folder
var myfile:File = new File("C:/Users/User/Desktop/zip/imgs/myimage.png");
//zipping the image
var zip:FZip = new FZip();
zip.addFile(myfile.name, myfile.data);
//saving the image to the user's desktop
var ba:ByteArray = new ByteArray();
zip.serialize(ba);
ba.position = 0;
var finalZIP:File = File.desktopDirectory.resolvePath("myfile.zip");
var fs:FileStream = new FileStream();
fs.open(finalZIP, FileMode.WRITE);
fs.writeBytes(ba);
fs.close();
the result is a zip file in the desktop, named "myfile.zip", with and image named "myimage.png", but when i unzip the file the image is empty, i tried to do the same with a text file, the text file is there zipped, but with nothing inside it.
Any idea what might cause this problem?

Flash .fla embed banner add

I need to create a Flash web banner. The .swf file size needs to be >40k so I made a .fla video and tried to stream it into the file however I'm getting no luck.
I can't find anything on the internet so I thought I'd ask here.
Im using Flash CC AS3
When I run the file through the
https://flashval-temp.appspot.com/validator/
the .swf uploads but the .fla doesn't play at all.
The code I was using was:
var vid:Video;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
ns.client = customClient;
ns.play("300x250.flv");
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace(event.text);
}
function metaDataHandler(infoObject:Object):void {
vid.width = infoObject.width;
vid.height = infoObject.height;
}
It seems to work fine offline, the files are in the same directory too.
Without knowing the full environment it's hard to tell you what's wrong, but you may want to check these:
(1) upload your video file to a server and grab the full url to the file, then update your code with it:
ns.play("http://www.YOUR_DOMAIN.com/300x250.flv");
(2) add the following as3:
Security.allowDomain("*");
(3) If that still doesn t work, look into crossdomain.xml at the root of your server hosting the video.
But (1) is likely to be the issue.

how to export movieclip as swf?

I have a movieclip loaded I modify and show in swf loader in flash builder 4.5 project,
I want the user to be able to save the movieclip to his disk as swf is there a straight
forward way to do that?
I searched for suggestions and found this but nothing seems to work
completed the project finally thanks to the "AS3SWF" class
here is how I save my files after importing the library to my project
import com.codeazur.as3swf.SWF;
var swf:SWF = new SWF(mySwfMc.loaderInfo.bytes);
var ba:ByteArray = new ByteArray();
swf.publish(ba);
var C:ByteArray = new ByteArray();
C.position = 0;
C.writeBytes(ba);
var f:FileReference = new FileReference ;
f.save(C,"demo.swf");

execute media files from AIR 3

I know that since AIR 2.0 it is possible to execute applications (.exe) like this:
if(NativeProcess.isSupported)
{
var file:File = File.desktopDirectory;
file = file.resolvePath("StyleLookupold.exe");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);
}
But is it possible to open a video in system's default player? For example executing Windows Media Player with command line parameter being the path to the video to play?
http://cookbooks.adobe.com/post_Open_file_with_Default_Application_AIR_2_0-16745.html Use openWithDefaultApplication method on the File object available in AIR 2 and greater.