Getting an error in FileReference.save method - actionscript-3

I am currently working in Flex 3.0 I am getting an error(screen shot is given below). I am using Flash Player Version 10.0
Currently I am calling the HTTPService and in the resultHandler of that HTTPService i am getting an error in method filereference.save() . because this method is called only when the MouseEvent or Keyboard event is occured.
Is there any solution to overcome this situation or in other words calling the filereference.save method in ResultHandler.

The reason for this is that you are no longer allowed to automatically trigger the display of file saving popups, except in the event of the user actually requesting this, via an event generated by the user. Here is some more info on the subject: http://www.bogdanmanate.com/2010/05/12/flex-error-2176-when-using-filereference/
I got around this problem using the solution described in the post, namely by using a Yes/No alert, to indicate to the user that the file has finished loading and it is ready for download and finally by asking him to confirm that he wants to save it locally. You might consider thins user-unfriendly, but it's really about security. And once you know how to trigger the event, you can figure out ways of bypassing this UI issue.
Have a great day!

You cannot. You need a click button of the user to get it done. Dispatching a MouseEvent is useless. Romi approach coud help you. But you need for security reasons to made it for a button click.
What I did.. was in the result retrive the file location and open it like an html page. Then you can download it. I see no other solution than forcing the user to click a button like Romi said.
var u:URLRequest = new URLRequest(event.result);
navigateToURL(u, "_blank");

An alternative solution might be to send the file to the server, then have the server send it back to the client which should trigger the browser's save/open dialog box. But if the file is created by flex then this is not ideal bandwidth-wise.

Related

How to add an HTML button

I'm building a web app (well at least one page on it) that shows the results of pings to different IPs.
I have no probs on Go displaying them on an HTML page. The simple thing I can't do (and I read so many tuto/threads that I'm lost and don't know what to do....) is to create a button "Refresh" that could just call back the "pingip" function i created in Go file.
Anyone has a concrete/"easy" example on how I could do this?
Assuming you have a HTTP Handler for your Go program, which is what is serving the page - then you can have the button simply do a window.reload() through JavaScript, which will reload the page in the browser and re-invoke the Go script.
If you want this to happen without a reload, then you'd have to create a different HTTP Route and use AJAX (look up the fetch method in JavaScript), get the results over the network (maybe as JSON) and then update the data in the frontend.

Unwanted Output In Console

I've started to get some strange output in my developer console. I was wondering if there was a way to turn it off.
Net state changed from IDLE to BUSY
That outputs whenever anything server side is called, you can imagine that it might cause a lot of clutter.
I was faced out with this issue also, tried to google, but no results.
Do not worry. This output appears when you call add-on back-end by calling google.script.run. It is default output for debugging the state of a connection.
Probably you have a loop that gets information from the add-on backend infinitely.
I'm assuming the messages are coming from warden source.
To solve this, you can simply right click (Windows) or double click (Mac) to bring up the help menu. Then access Filter and click the source of the element you want to filter out of your console. It should then disappear.
Let me know how that works

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.
I have tried the following approaches -
Create a nocache function and call the decorator in the page function
I have tried putting headers in my HTML
Using Command + Shift + R in Chrome for MacOS for a "hard" refresh
No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.
Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!
EDIT:
I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.
I finally found another post on Stack Overflow regarding my question.
Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

Flex Security Sandbox Violation just started happening

I have an http handler built and running on my website server. Code in flex generates a http request then navigates to the handler, which generates and streams back file information for the user to download.
Basically the request sends image data and the return result is a pptx stream with the image data in a powerpoint slide.
This worked fantastically this morning until about an hour ago. I have no idea what changed, but every swf I am building which attempts to access this handler is now giving me:
* Security Sandbox Violation *
Connection to https://g1.localhost/Turm/BounceBack.aspx halted - not permitted from https://g1.localhost/Turm/FlashApps/ImageAndExporting.swf?debug=true
I even fully qualified the BounceBack.aspx name (it was a relative url until just now) in case something was confusing the flash player, but as you can see, the url request and the swf are loaded from exactly the same domain (even the same virtual app in the web domain).
I have even added the physical filepath as a 'trusted folder' in my flash player security settings.
What gives? Anyone have any suggestions?
Using the Apache 4.9.1 SDK and latest version of flashplayer.
As mentioned, this worked all day yesterday and this morning. I cannot figure out what has changed, but am having no luck resolving the issue, source code has not changed.
Finally figured out what changed. I move the navigation to my ASPX handler into a seperate method that delays invoation till after a UI update. Becuase I use the same ui components for printing as well as exporting, I tested the updates with the print feature and that worked without error. About an our later, I noticed the handlers were failing. Since the url request is not handled inside a UI interaction event (Like MouseEvent.CLICK) the flash player was preventing the call. Once I moved the navigation back into the event handler, the sandbox violation went away.
If you ask me, not a very good error message due to the actual problem encountered, but ... you learn something every day.

Use airSWF.installApplication() after a URLLoader's callback

I'm trying to use a variation of the Flash Badge to install an AIR application. Here's what needs to happen:
User clicks "download"
Send a request using URLRequest/URLLoader to my web service to retrieve some information
Pass that information into the AIR app using the install/launch arguments
The problem I'm having is getting the airSWF to do anything after URLLoader is done. Since airSWF.installApplication() must be called within the handler of a user-generated event, it doesn't do anything when it's inside the URLLoader Complete event, and the fact that the original event was user generated doesn't seem to pass through the chain of events.
Is there anything I can do so that the above flow will work?
I've solved this by requesting the necessary data from the server (step 2) right away at the application start.
Not that elegant, since there is no guarantee that the user will click on the download button, and i store the just-in-case data anyway, but it works.
So when the user decides to click on the download button, I check air status, and if it's installed on the machine, i just use the already stored values, and download-->install or launch the application.