How do I get Air to remember the file path? - actionscript-3

I have tried:
var file:File = File.documentsDirectory.resolvePath('');
and
var file:File = File.applicationStorageDirectory.resolvePath('myFolder');
Which seems to be how people recommend how to do it when searching for this. These work when I am testing the movie but when I publish the Air file it stops working and just defaults to the computer root folder everytime.
If anyone can shed some light on this I would greatly appreciate it.
Additional information
This is getting fustrating now. Here is the code in context. If anyone has any further ideas it would be a big help I just can't work it out it all works fine apart from remembering the file path.
var file:File = File.documentsDirectory.resolvePath(""));
videoselect1_btn.addEventListener(MouseEvent.CLICK, selectVideos);
function selectVideos(evt:MouseEvent):void {
file.addEventListener(FileListEvent.SELECT_MULTIPLE, file_selectMultiple);
file.browseForOpenMultiple("Please select a file or three...");
}
function file_selectMultiple(evt:FileListEvent):void {
for (var i:uint = 0; i < evt.files.length; i++) {
videostr += evt.files[i].nativePath + "\n";
videopath.push(evt.files[i].nativePath);
videoFiles = (evt.files.length);
}
video1output.text = ("You have selected " + videoFiles + " files" + "\n" + "\n" + videostr);
}
I did have file = new File(); in the selectVideos function but removing it meant at least it was going to the documents directory.

Related

HTML to PDF on click convert

I'm busy making a site and would like to know if there's a way to convert HTML to PDF or word file.
Scenario ~
User sees the information that he/she likes clicks on a button that converts the Page/Section to PDF or word and saves it locally (to the person's computer)
Any ideas? Anything would help if I could get some documentation or some direction it would be appreciated.
Thanks in advance.
Edit*
Sorry if it's a silly question still learning here :D
sure there are many ways, i can be helpful in JavaScript, i'm working on a project where client can download the Html files as PDF,please check
<script>
$(".clone-pdf").clone().appendTo(".html-content");
function CreatePDFfromHTML() {
var HTML_Width = $(".html-content").width();
var HTML_Height = $(".html-content").height();
var top_left_margin = 15;
var PDF_Width = HTML_Width + (top_left_margin * 2);
var PDF_Height = (PDF_Width * 1.5) + (top_left_margin * 2);
var canvas_image_width = HTML_Width;
var canvas_image_height = HTML_Height;
var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1;
html2canvas($(".html-content")[0]).then(function (canvas) {
var imgData = canvas.toDataURL("image/jpeg", 1.0);
var pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]);
pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height);
for (var i = 1; i <= totalPDFPages; i++) {
pdf.addPage(PDF_Width, PDF_Height);
pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height * i) + (top_left_margin * 4), canvas_image_width, canvas_image_height);
}
pdf.save("Your_PDF_Name.pdf");
});
}
</script>
and the html to send the request to the script.
<i class="icon-download"></i>
I wish i helps to get the answer you are looking for.

Intermittant DriveWriteVolume rateMax exception

I have been struggling with this error since about a week before DriveApp was released. I have a section of code that fails intermittantly with the error:
Service invoked too many times in a short time: driveWriteVolume rateMax. Try Utilities.sleep(1000) between calls.
Here is the code in question:
for(var a = 0; a<attachments.length; a++){
if(a > 0){
child = "." + (a + 1) + " ";
}
else{
child = ".1 ";
}
var parent = (m + 1);
Utilities.sleep(5000);
var file = attachmentFolder.createFile(attachments[a]);//This is the line that causes the error.
Utilities.sleep(1000);
file.rename(parent + child + attachments[a].getName());
}
I started with 1000ms, then gradually worked up to 5000 and it still throws the error every ~200 iterations. This is using DocsList.
I have had a similar problem in a script I'm working on.
The problem arises when I loop through the attachments to the message and attempt to save them too. If I skip the attachments, I don't have a problem, even with the same number of total file creations and the same sleep time between them. This is the code I'm using. newFolder.createFile(pdfBlob) does not cause a problem. newFolder.createFile(attachmentBlob) does.
// Create the message PDF inside the new folder
var htmlBodyFile = newFolder.createFile('body.html', messageBody, "text/html");
var pdfBlob = htmlBodyFile.getAs('application/pdf');
pdfBlob.setName(newFolderName + ".pdf");
newFolder.createFile(pdfBlob);
Utilities.sleep(sleepTime); // wait after creating something on the drive.
htmlBodyFile.setTrashed(true);
// Save attachments
Logger.log("Saving Attachments");
for(var i = 0; i < messageAttachments.length; i++) {
Logger.log("Saving Attachment " + i);
var attachmentBlob = messageAttachments[i].copyBlob();
newFolder.createFile(attachmentBlob);
Utilities.sleep(sleepTime); // wait after creating something on the drive.
} // each attachment

Embed a video using Google Script

I'm trying to use Google Scripting to embed videos I have stored on my Google Drive into HTML. Here's the code I'm using to generate the HTML:
function GenerateTables() {
var folderz = DocsList.getFolder('SharedVideos');
var contents = folderz.getFiles().sort(function(a,b) {return b.getDateCreated()-a.getDateCreated()});
var file;
var name;
var date;
var url;
var dateModified;
var folder;
var textOutput = "<table>";
textOutput += "<tr><th>File Name</th><th>Create Date</th><th>Modified Date</th></tr>"
for (var i = 0; i < contents.length; i++) {
file = contents[i];
folder = file.getParents()[0];
name = file.getName();
url = "https://docs.google.com/file/d/" +file.getId()+"/preview";
date = Utilities.formatDate(file.getDateCreated(), 'GMT-6', 'MM/dd/yyyy hh:mm:ss aaa');
dateModified = Utilities.formatDate(file.getLastUpdated(), 'GMT-6', 'MM/dd/yyyy hh:mm:ss aaa');
textOutput += "<tr><td>" +name + "</td><td>" + date + "</td><td>" + dateModified + "</td></tr>";
textOutput += "<tr><td colspan='3'>";
textOutput += "<iframe src='"+url+"' height='385' width='640'></iframe>";
textOutput += "</td></tr>";
}
textOutput +="</table>";
return textOutput;
}
function doGet() {
var text = GenerateTables();
return HtmlService.createHtmlOutput(text);
}
The iframe is being converted to
<iframe data-caja-src='[the correct URL]' height="385" width="640"></iframe>
I was hoping it would be a simple process, but the more I got looking into it, the more complicated it seemed to be. Is there an easier way to do what I'm trying to do? I don't have much experience using Caja, but maybe there's a simple way to embed a video using Caja, I just couldn't get anything to work.
There is not yet a way to embed videos inside HtmlService. I think there's a feature request for it on the issue tracker, but regardless it's something we know about.

How to check number of files of same extensions (e.g .txt) inside a folder in Adobe Air 2.0?

Is there any way to find total number of files of same types (e.g. ".txt" files) inside
a folder?
Here, is the solution i found.
//Tested on AIR 2.0
import flash.filesystem.File;
//e.g. Say you want to target documents folder of your OS
var MyFolder:File = File.documentsDirectory.resolvePath("Temp");
var totNumOfFiles:Array = MyFolder.getDirectoryListing();
var numOfSameFileType:Array = [];
for (var i:uint = 0; i < totNumOfFiles.length; i++)
{
if(totNumOfFiles[i].type == ".txt" )
{
numOfSameFileType.push(i);
}else
{
trace("No text files.");
}
}
trace("Total " + numOfSameFileType.length + " text files are available.");

Problems Displaying Profile Picture in Flash swf

I followed this tutorial Loading Facebook Profile Picture Into Flash SWF Using Graph API to get the users profile picture to show in my flash game, but I'm having some issues.
import com.facebook.graph.Facebook;
import com.facebook.graph.data.FacebookSession;
import com.facebook.graph.net.FacebookRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
//place your APP ID here
const APP_ID:String = "app_id";
//Initialize facebbok library
Facebook.init(APP_ID, HandleLogin);
function HandleLogin(response:Object, fail:Object):void
{
if(Facebook.getSession().accessToken)
{
LoadMyInfo();
LoadMyPicture();
}
}
function LoadMyInfo():void
{
Facebook.api("/me", MyInfoLoaded);
}
function MyInfoLoaded(response:Object, fail:Object):void
{
nameTextField.text = response.name;
}
function LoadMyPicture():void
{
debug.text = "Entered loadMyPicture() function ";
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, MyPictureLoaded, false, 0, true);
var request:URLRequest = new URLRequest("facebookProxy.php");
var variables:URLVariables = new URLVariables();
variables.path = Facebook.getImageUrl(String(Facebook.getSession().uid), 'large');
debug.appendText(" \nvariables.path: " + String(variables.path));
request.data = variables;
debug.appendText(" \nrequest.data: " + String(request.data))
loader.load(request);
debug.appendText(" \n" + String(loader.load(request)));
}
function MyPictureLoaded(event:Event):void
{
debug.appendText(" \nEntering MyPictureLoaded");
var loader:Loader = event.target.loader;
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, MyPictureLoaded);
loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, MyPictureLoadError);
var bitmap = Bitmap(loader.content);
bitmap.smoothing = true;
//Note: picturePlaceholder is just a blank movie clip on the Stage
bitmap.x = picturePlaceHolder.x;
bitmap.y = picturePlaceHolder.y;
bitmap.width = picturePlaceHolder.width;
bitmap.height = picturePlaceHolder.height;
picturePlaceHolder.addChild(bitmap);
debug.appendText(" \nBitmap is null: " + String(bitmap == null) +
" \nBitmap X: " + String(bitmap.x) + " Bitmap Y: " + String(bitmap.y) +
" \nBitmap width: " + String(bitmap.width) +
" \nBitmap height: " + String(bitmap.height))
}
function MyPictureLoadError(e:IOErrorEvent):void
{
debug.appendText("Loading Error");
}
This is what my code looks like after following the tutorials on the link above. With the debug I noticed that the function MyPictureLoaded is never called.
They never specified where I would call the function LoadMyPicture. I assumed it would go together with LoadMyInfo so I placed it there. They have a working example but no source code, so I'm hope someone here would shed some light on this.
EDIT 1
Here is what it looks like when I put it up on facebook. The last line debug.appendText(" \n" + String(loader.load(request))); is outputting undefined. I also made a change in the variables.path = Facebook.getImageUrl(String(Facebook.getSession().uid), 'large'); I added (String(), 'large') because in the docs it saying to pass strings into there. Edit: I realized adding String() is pointless.
var request:URLRequest = new URLRequest("facebookProxy.php");
Did you do the part of the tutorial that writes a server-side PHP proxy loader on your server?
If you don't have a file named facebookProxy.php on your server where you run this it won't work (the code is requesting "./facebookProxy.php" which probably doesn't exist). If you want to run this in the debugger on your local machine, you will need to make that file in the same directory as your swf and make sure you have apache/php running on your localhost.
If that's too much work for you, I would suggest following some of the examples from the API' project page: http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Examples_1_6.zip&can=2&q=