execute media files from AIR 3 - actionscript-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.

Related

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

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);

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

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.

AS3 FLASH AIR - Loader not finding url

I'm having an issue with loading an image using the Loader class.
Can someone see what I'm doing wrong?
// get file folder location
var file = new File(File.applicationStorageDirectory.nativePath);
// convert to string
var fileString:String = file.url.toString();
// remove string characters
fileString = fileString.split('file:///').join('');
// create loader
var loader:Loader = new Loader();
// create request
var urlReq:URLRequest = new URLRequest(fileString+'/logo.jpg');
// load request
loader.load(urlReq);
When I test it gives me a 'Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.' If I use a loader.contentLoaderInfo to check IOERROR.IO_ERROR it gives me '1119 Access of possibly undefined propety IOERROR through a reference with static type flash.display:Loader'
Any thoughts to what I'm doing wrong? I've also tried just loading the .jpg from the same folder
var urlReq = new URLRequest('logo.jpg');
that the test app is in but still get the "URL Not Found"
Any help would be greatly appreciated.
Thank you.
This is simple: Don't use Loader, use FileStream instead. Since the file is saved into the app storage dir (or I assume it is, at least), you can read it directly rather than using a Loader.
var file:File = File.applicationStorageDirectory.resolvePath( "logo.jpg" );
var fs:FileStream = new FileStream();
fs.open( file, FileMode.READ );
var bmp:Bitmap = fs.readObject();
fs.close();
this.addChild( bmp );
You should avoid using Loader as much as possible. There is a lot of extra weight in the Loader class that adds can be a drain on performance. Use Bitmap instead, which is the lowest level way of display an image, and wrap it in a Sprite (or use Image instead of Bitmap and Sprite if using Flex) if you need to give it interactivity.

Actionscript 3 does not work .. it didn't give errors

I am creating a clock using this code:
var date:Date = new Date();
var time:Timer = new Timer(1000);
time.addEventListener(TimerEvent.TIMER, actualiser);
time.start();
function actualiser(e:TimerEvent){
date = new Date();
var s:uint = date.seconds;
var m:uint = date.minutes;
var h:uint = date.hours;
sec_mc.rotation =(s * 6);
min_mc.rotation =(m * 6);
heur_mc.rotation =(h * 30) +m/2;
}
But, it seems that the code is not executing, I can’t even trace anything written in constructor of my document class. When I run it nothing happens and when I try to debug I get the alert message saying:
You cannot debug this SWF because it does not contain ActionScript
What can be wrong?
Try to check the code in a new fla. Write the following in your 1st frame action panel. This does give proper output and you can see the traces in the output panel. There is no issue with the code logic. Might be some issue with the movieclip being used.
var date:Date = new Date();
var time:Timer = new Timer(1000);
time.addEventListener(TimerEvent.TIMER, actualiser);
time.start();
function actualiser(e:TimerEvent){
date = new Date();
var s:uint = date.seconds;
var m:uint = date.minutes;
var h:uint = date.hours;
trace(h+":"+m+":"+s);
}
In case of CS5 , try the following steps :
WINDOWS:
1. Quit Flash
2. In a text editor, open the jvm.ini file from the following location:
2.1. Windows XP: System Hard Disk\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash CS5\language\Configuration\ActionScript 3.0\jvm.ini
2.2. *Windows Vista or Windows7:* System Hard Disk\Users\user\AppData\Local\Adobe\Flash CS5\language\Configuration\ActionScript 3.0\jvm.ini
(You might need to turn on “show hidden files”)
3. Change -Xmx128m to -Xmx256m and save the file.
EDIT: Uhm. Is that all you have? Because you need to import the needed packages, etc. Also, are you sure you linked everything up?