Open document function in Windows 7 with AIR App - actionscript-3

Below is the code I'm working on to open a pdf file when a button is clicked.
It all works fine in Windows Vista and Windows 8+, but the pdf file gets opened only once in Windows 7.
By clicking the button again doesn't launch the pdf file the second time.
function openDoc(event: MouseEvent): void {
nsStream.pause();
pausedBtn.visible = true;
mcVideoControls.btnPause.visible = false;
mcVideoControls.btnPlay.visible = true;
var realFile: File = File.applicationDirectory.resolvePath(_myfilename);
//get user's home directory:
var destination: File = File.documentsDirectory;
//copy the original file temponary to user's home directory:
destination = destination.resolvePath(_myfilename);
realFile.copyTo(destination, true);
//open the temponary copy from user's home directory (acrobat or whatever):
destination.openWithDefaultApplication();
}
function onCuePoint(infoObject:Object):void
{
openDocBtn.visible = true;
timer1.start();
if (infoObject.name == "myDocCue"){
_myfilename = "mydoc.pdf"; // = my filename
}

Related

Move files from applicationStorage to Documents in app

I've got an app that, since 5 years now, that displays an offline map by reading from a folder embed in it ("assets").
Since Android 11, it's impossible to read from ApplicationStorage (Error #3001: File or directory access denied), so I'm trying to copy the folder from applicationStorage to "Documents".
What I did :
source = File.applicationDirectory.resolvePath("assets/maps");
destination = File.documentsDirectory.resolvePath("Documents/www");
source.addEventListener(Event.COMPLETE, onMapCopyComplete);
source.copyToAsync(destination, false);
function onMapCopyComplete(e: Event): void {
source.removeEventListener(Event.COMPLETE, onMapCopyComplete);
log("onMapCopyComplete()");
}
I've got a return onMapCopyComplete() but when I'm looking in InternalStorage/Documents of my phone I've got the folders but all are empty... None of the files were copy..
PrintScreen computer vs phone
To read the files, here's what I'm doing :
function startMapsView()
{
var indexFile:File = File.applicationStorageDirectory.resolvePath("www/index.html");
if (!indexFile.exists)
{
log("startMapsView() Index file not found, Please check www/index.html");
return;
}
// Create StageWebView
stageWebView = new StageWebView(isMobile); // Set to TRUE for System's NativeWebView, FALSE is for AIR's WebView
stageWebView.stage = stage;
stageWebView.viewPort = new Rectangle(0, iOSStatusBarHeight + headerBarHeight, deviceStageSize.width, deviceStageSize.height - (iOSStatusBarHeight + headerBarHeight + footerBarHeight));
stageWebView.addEventListener(flash.events.Event.COMPLETE, onStageWebViewLoaded);
stageWebView.addEventListener(flash.events.ErrorEvent.ERROR, onStageWebViewError);
stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, onStageWebViewLocationChanging);
// Load Map URL
stageWebView.loadURL(mapsURL);
}
And mapsURL is define by :
function setMapsURL(doNotEnableButtons: Boolean = false): void {
var indexFile: File = File.documentsDirectory.resolvePath("Documents/www/index.html");
trace("indexFile url is = "+indexFile.url);
if (!indexFile.exists) {
log("setMapsURL() Index file not found, Please check www/index.html");
return;
}
var assetsDir: File;
if (!useOnlineMaps) {
assetsDir = new File(destination.resolvePath("index.html").nativePath);
} else {
assetsDir = new File(destination.resolvePath("onlineMaps.html").nativePath);
mySavedData.data.onlineMapChoosen = false;
}
mapsURL = assetsDir.url;
log("setMapsURL() " + mapsURL);
if (!doNotEnableButtons) enableMapButtons();
}

Find name of app

FlashBuilder Flex
In my reboot code, I have the following line:
var file:File = File.applicationDirectory.resolvePath("app:/playerAir.exe");
It works as long as the app's name doesn't change
I want an automated way to find this app's name to change that "playerAir".
The reasons:
If I change the name, I have to change it in the reboot function too
If a client has more than one versions of the file (playerAir.exe, playerAir1.exe, playerAir2.exe) then it'll launch the wrong one.
How could I make it so it changes accordingly to the name the app has?
The code of the reboot function is as follows:
public function Reboot():void ///
{ ///
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); ///
var app:WindowedApplication=WindowedApplication(FlexGlobals.topLevelApplication); ///
var swf:String=stage.loaderInfo.url.substring(0,stage.loaderInfo.url.lastIndexOf("/")+1); ///get swf's path (- *name*.swf)
swf=swf+app.applicationID; ///adds applicationID after the path. ex: app:/ -> becomes -> app:/m7tvPlayerAir
var d:Array = File.applicationDirectory.getDirectoryListing(); ///get all files in the directory
var exe:String; ///the executable (.exe, .app, .dmg) (multiplatform)
for each(var f:File in d){ ///checks all files in the directory
if(f.url.indexOf(swf)==0 && (f.url.indexOf(".dmg") > -1 || f.url.indexOf(".app") > -1 || f.url.indexOf(".exe") > -1)){///if any of them has the same directory and name, and has 1 of the extensions
exe=f.url; ///found the executable
break; ///stops the loop
}///end If
}///end for
trace(exe); ///
if(exe==null){ ///will just close the application if it doesn't find the file
(FlexGlobals.topLevelApplication).exit(); ///
}else{ ///if it did find a file
var file:File = File.applicationDirectory.resolvePath(exe); ///
nativeProcessStartupInfo.executable = file; ///
nativeProcessStartupInfo.workingDirectory = File.documentsDirectory; ///
var process:NativeProcess = new NativeProcess(); ///
(FlexGlobals.topLevelApplication).exit(); ///
process.start(nativeProcessStartupInfo); ///
}///end else
}///end function
(Hey this is Ohciarob, I forgot my password)
You should be able to determine the application name with the url property of the stage's loaderinfo object.
This will point to the swf file being run, which by default will be the same name as the executable.
So, if you know your app has an extension of .exe, this would likely work:
var path:String = stage.loaderInfo.url.replace(".swf",".exe");
var file:File = File.applicationDirectory.resolvePath(path);
If you are running a multi-platform app, you could walk the application directory looking for the appropriate application extension:
//get the swf path minus the 'swf'
var swf:String = stage.loaderInfo.url.substring(0,stage.loaderInfo.url.lastIndexOf(".") + 1);
//get all the files in the application directory
var d = File.applicationDirectory.getDirectoryListing();
//find your executable (this is just a sample of how to do this, ideally you'd have a compile time constant to indicate the extension of your current build)
var exe:String;
for each(var f:File in d){
if(f.url.indexOf(swf) === 0 && (f.url.indexOf(".dmg") > -1 || f.url.indexOf(".app") > -1 || f.url.indexOf(".exe") > -1)){
exe = f.url; //found the executable path
break; //stop the loop
}
}

Gdrive unable to download and not upload

I am using GDRive insertFile and RevtrieveAllFiles to upload and download files to googledrive.
I created a client secret and Id and modified the credentials.
the code is based on the post in code project http://www.codeproject.com/KB/WPF/488185/GDrive_Uploader_Sample.zip
but it fails debuggin the Utilities.InsertFile
in the file.upload it fails with exceptionvalue cannot be null - uriString .
in the download it fails in FileList files = request.Fetch(); with
// First, create a reference to the service you wish to use.
// For this app, it will be the Drive service. But it could be Tasks, Calendar, etc.
// The CreateAuthenticator method is passed to the service which will use that when it is time to authenticate
// the calls going to the service.
_service = new DriveService(CreateAuthenticator());
// Open a dialog box for the user to pick a file.
OpenFileDialog dialog = new OpenFileDialog();
dialog.AddExtension = true;
dialog.DefaultExt = ".txt";
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
dialog.Multiselect = false;
dialog.ShowDialog();
File body = new File();
body.Title = System.IO.Path.GetFileName(dialog.FileName);
body.Description = "A test document";
body.MimeType = "text/plain";
System.IO.Stream fileStream = dialog.OpenFile();
byte[] byteArray = new byte[fileStream.Length];
fileStream.Read(byteArray, 0, (int)fileStream.Length);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
// Get a listing of the existing files...
List<File> fileList = Utilities.RetrieveAllFiles(_service);
// Set a flag to keep track of whether the file already exists in the drive
bool fileExists = false;
foreach (File item in fileList)
{
if (item.Title == body.Title)
{
// File exists in the drive already!
fileExists = true;
MessageBoxResult result = System.Windows.MessageBox.Show("The file you picked already exists in your Google Drive. Do you wish to overwrite it?", "Confirmation", MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Yes)
{
// Yes... overwrite the file
Utilities.UpdateFile(_service, item.Id, item.Title, item.Description, item.MimeType, dialog.FileName, true);
List<File> allFiles = Utilities.RetrieveAllFiles(_service);
}
else if (result == MessageBoxResult.No)
{
// MessageBoxResult.No code here
File f= Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
}
else
{
// MessageBoxResult.Cancel code here
return;
}
break;
}
}
// Check to see if the file existed. If not, it is a new file and must be uploaded.
if (!fileExists)
{
File file= Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
var list = Utilities.RetrieveAllFiles(_service);
}
System.Windows.MessageBox.Show("Upload Complete");
open gdrive and set sdk to On. that will enable the application to access the gdrive account

Accessing local MP3 id3 properties with ExternalInterface

I need to run a swf inside an Extendscript (java) window in Photoshop. The Extendscript part pops up a Folder Selection dialog and lets user to select a folder. Then it sends the Folder path and the list of the .mp3 files in that folder to the swf file.
The swf can load and play the song
But it can't get the id3 information
The swf is in "Access Network Files Only" mode
I'm pretty sure it is a security issue and wonder if anyone knows of a workaround. Here is my code...
Thanks in advance.
var mp3FileList;
var folder;
var songList;
var songsArray:Array = new Array();
var mp3Array:Array = new Array();
if (ExternalInterface.available) {
ExternalInterface.addCallback("transferSongList", transferSongList);
}
//Extendscript opens a Select Folder dialog
//and sends the folder path and the list of .mp3 files inside the selected folder to this swf
function transferSongList(folder, mp3FileList){
songList=quickReplace(mp3FileList, "%20", " ");
songsArray = songList.split(",");
var mp3File:Sound = new Sound();
mp3File.load(new URLRequest(folder+"/" + songsArray[0]));
mp3File.addEventListener(Event.COMPLETE, parseSound(mp3File));
}
function parseSound(mp3):Function{
return function(e:Event):void {
//IF I REMOVE THE NEXT LINE THE SONG PLAYS
alertbox.text=mp3.id3.songName
mp3.play();
};
}
function quickReplace(source:String, oldString:String, newString:String):String
{
return source.split(oldString).join(newString);
}

how to upload to remote folder saved audio from html5 getusermedia microphone

I have this file thats created with html5, I am just starting to learn.
Basically when I am recording from the microphone and stop the record I am finding it hard to upload the outputted file to a folder on the server.
Here is the page i am testing on.
http://2click4.com/playground.php
You use Blob and createObjectURL in your code on example page. You create ObjectURL, so you can send it by XMLHttpRequest to server:
var blob = new Blob ( [ view ], { type : 'audio/wav' } );
// let's save it locally
outputElement.innerHTML = 'Handing off the file now...';
var url = (window.URL || window.webkitURL).createObjectURL(blob);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'link_to_server', true);
xhr.onload = function (e) {
var result = e.target.result;
};
xhr.send(url);//url is Blob