AIR > browseForSave strange behaviour - actionscript-3

I just noticed something weird in my app.
I have a "save" button that triggers this function:
var saveFile:File = File.desktopDirectory.resolvePath(nameOfProject+".uct");
saveFile.browseForSave("Save as");
saveFile.addEventListener(Event.SELECT, saveFileToSystem);
When clicked, it display the "browse for save" window with a suggested name file.
Now I've noticed that when exporting, installing and running the app, when I click the button for the first time everything it's ok, but when I clicked again the location looks like this:
The "where" field is the same file....? And even if I click save, it doesn't save. The strange stuff is that this is not happening while testing my app in Flash Builder.
Any hint?

I did the workaround above, and it seems to do the trick. Code is something like this:
var saveFile:File = File.documentsDirectory.resolvePath("output.file");
var tempMovedAway:File = File.applicationStorageDirectory.resolvePath("temp.temp");
currentFileRenamedForAirBug = picker.clone();
currentFileRenamedForAirBug.moveTo(tempMovedAway), true);
saveFile.addEventListener(Event.SELECT, function():void {
tempMovedAway.deleteFile();
} );
saveFile.addEventListener(Event.CANCEL, function():void {
tempMovedAway.moveTo(currentFileRenamedForAirBug);
});
saveFile.browseForSave("save file");
// MUST be sure to call saveFile.browseForSave, or you risk losing an existing file.
You can wrap this lot in checks for the Air runtime (NativeApplication.nativeApplication.runtimeVersion) and Mac-only, to avoid doing this any more than necessary.
Also, if your file save code could rely on making changes to an existing file (rather than creating an entirely new one), you'll need to tweak this a bit.

Related

ZoomWindow extension breaks without GUI?

Using v2.13 of the viewer, the ZoomWindow extension relies on having the default GUI enabled. Is there a way around this? The load method is:
proto.load = function() {
var viewer = this.viewer;
var toolbar = viewer.getToolbar(true);
//var toolbar = viewer.getToolbar ? viewer.getToolbar(true) : undefined;
// Init & Register tool
this.tool = new namespace.ZoomWindowTool(viewer);
viewer.toolController.registerTool(this.tool);
// Add the ui to the viewer.
this.createUI(toolbar);
return true;
};
which fails because getToolbar is undefined.
It seems from the commented out line that this has been considered, but not implemented.
What is the best way to implement a work around - should I copy the entire extension with a new name, or can I replace the load method at runtime?
Edit: was looking to use the headless viewer, but it seems easiest just to hide the UI with css.
It's not clear to me if you are using the GuiViewer3D or want to use the Viewer3D, the viewer without Autodesk custom UI. If you use GuiViewer3D, you can simply wait for the toolbar to be loaded before loading the ZoomWindow extension, which requires the toolbar controls to be created in order to add a button to it.
viewer.addEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, function () {
viewer.loadExtension('Autodesk.Viewing.ZoomWindow')
})
Here is a blogpost I wrote a while ago about using events in the viewer. It is not up-to-date with the current version but remains valid:
http://adndevblog.typepad.com/cloud_and_mobile/2015/10/event-watcher-extension-for-view-data.html
Now as Zhong mentioned, if you want to use the headless viewer with no UI and still use the extension, you may have to copy and customize it as you suggested. But an easier workaround could be to use GuiViewer3D and simply hide the existing toolbar with css, so the the js code remains valid. Set display:none on div id="guiviewer3d-toolbar", for example, or on the adsk-control class.
Hope that helps

display only a specific content in AS3 code using webStage View

I'd like to display, in my app, only a part of a web page.
On this website, I'd like to display, in my app, only the div id "MovieCart".
What should I write in my as3 code in order to do so ?
For now, I have this line :
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
But, of course, it's displaying the fullwebpage.
EDIT
So, I've tried this :
webView.addEventListener(Event.COMPLETE,onComplete);
var res : String = ExternalInterface.call("function(){return document.getElementById('movieCart').outerHTML}");
var urlOfMovie: URLRequest = new URLRequest("http://www.cinecity.nc/Cinecity/Film/40567");
var loaderMovie:URLLoader = new URLLoader();
loaderMovie.load(urlOfMovie);
webView.loadString(res);
But, as it's an AIR app, ExternalInterface.call can't be call. Any idea ?
Here is one easy way you can accomplish this:
//First, load the full page as you're currently doing:
webView.addEventListener(Event.COMPLETE, webLoadComplete); //listen for when the load is finished
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
//runs when the load finishes
function webLoadComplete(e:Event):void {
webView.removeEventListener(Event.COMPLETE, webLoadComplete); //stop listening
//second, invoke the following Javascript on the page which assigns the `MovieCart` element as the html for the whole document body
webView.loadURL("javascript:document.body.innerHTML = document.getElementById("MovieCart").outerHTML");
}
Disclaimer:
Keep in mind that scrapping content from websites is generally frowned upon and you may be infringing on peoples work/copyrights by doing so.

Copy an Image from Flex Application (Web) and paste it outside the application

I have a requirement that we should be able to copy an image displayed in our application, to Clipboard and paste it outside (Like on Excel).
I was trying the below code snippet (Inside a button Click).
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT,
byteArray, false);
The dataLoaded object is true, however it does not paste anything when tried on Excel or MsPaint.
Do we have any way to achieve this?
Thanks.
The code you are showing is not enough in itself to get a successful transfer. Like many other operations within the security sandbox of a FP app (web) this code can only respond to a direct user interaction. So your code without any valid context cannot work of course but if called within a mouse down listener for example (a true user generated mouse event, creating a fake mouseevent would still not work) it should respond correctly:
private function handleMouseClick(event:MouseEvent):void
{
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT, byteArray, false);
}

Frame Load Interrupted: Safari won't download a linked zip file from my Flash site

First of all I am a total noob so I apologize if this is a dumb question. I am building a Flash site that is designed to be used offline, on a private network. I have successfully linked PDF files, which Safari opens in the browser. This is fine because the file can still be saved from there. However, now I am trying to link .zip files and .mp4/.mov files and am encountering some issues.
Firefox and Safari both try to play the movie files in the browser, but I would prefer for the Open/Save dialog box to appear. As far as .zip files, Firefox prompts the dialog box, which is what I want; in Safari, a new window appears yet nothing happens. The activity window says "Frame Load Interrupted." I have researched this issue and tried tinkering with Safari settings but nothing has worked, nor am I sure it's solely a Safari issue, or if there is something I can do with the Actionscript to prompt the download dialog box. I have seen some different code options for file downloads but wasn't sure how to implement them correctly, or if that was even necessary in my case. Right now I am most familiar with URLRequest and have successfully used the two following configurations:
1)
var zipURL:URLRequest = new URLRequest("../Folder/Folder/Folder/Folder/Archive.zip");
function launchdownload(event:MouseEvent):void
{
navigateToURL(zipURL, "_blank");
}
btn_name.addEventListener(MouseEvent.CLICK,launchdownload);
2)
var request:URLRequest;
var localRef:FileReference;
btn_name.addEventListener(MouseEvent.CLICK,downloadFile);
function downloadFile (evtObj:Event):void
{
var Location:URLRequest = new URLRequest
("../Folder/Folder/Folder/Folder/Archive.zip");
navigateToURL (Location, "_new");
}
If anyone can help me to get around the Frame Load Interrupted issue and/or show me how to properly code my download button such that I can force the Open/Save dialog in all browsers, I would greatly appreciate it! Thank you so much!
You could also let ActionScript do the downloading.
If you add the following code you get a dialog box that lets you select a location to download your file and downloads it.
btn_name.addEventListener(MouseEvent.CLICK,downloadFile);
function downloadFile (evtObj:Event):void
{
var Location:URLRequest = new URLRequest();
Location.url = "http://www.example.com/image.jpg";
var fr:FileReference = new FileReference();
fr.download(request);
}

File Drag & Drop in Firefox (v10)

I'm trying to get file drag and drop in firefox and am taking baby steps to start. Right now, I'm just trying to drag some files in to a dropzone and get a list of the files dropped. At this point, I don't want to do anything with the files yet.
When I drag a file (in this case an image, but the same thing happens regardless of the file type) from finder to the dropzone, I can see the dragenter and dragexit events firing. When I drop the file in to the dropzone, the drop event is not firing. What happens instead is that the browser opens the image on it's own (e.g, the address is showing file://path/to/my/image.png).
My javascript looks like this:
dropbox = document.getElementById("standard_file_dropzone");
dropbox.addEventListener("dragenter", function(){console.log('standard enter');}, false);
dropbox.addEventListener("dragexit", function(){console.log('standard exit');}, false);
dropbox.addEventListener("dragover", $.noop, false);
dropbox.addEventListener("drop", function ( event ) {
console.log('standard dropped');
event.stopPropagation();
event.preventDefault();
if(( typeof event.dataTransfer.files !== 'undefined' ) &&
( event.dataTransfer.files.length > 0 )) {
console.dir( event.dataTransfer.files );
}
return false;
}, false);
My HTML looks like this:
<div id="standard_file_dropzone" style="height:150px; width:150px; border:solid;">
Standard Drop Files Here
</div>
So I'm wondering what I'm doing wrong here? There doesn't seem to be anything (at least obvious to me) wrong with the above code. The dragenter/exit events are firing, why isn't the drop event? Why is the browser trying to open the file itself?
One thing to note, when I open my page in Chrome, this is working as expected so this is a Firefox specific issue.
thnx,
Christoph
The issue was using $.noop as the dragover handler. Replacing it with a function which actually stops propagation and the bubbling, it started working as expected.
I'm such an idiot sometimes. :p