Solved

Need help with AC3 Jpeg Encoder

Posted on 2011-02-28
8
437 Views
Last Modified: 2013-11-11
We have a flash-driven online quiz, that creates a certificate of completion when the user gets to the end. We need the user to be able to save the certificate to the desktop before the certificate is then queued for printing within the browser. The printing works fine, but the save functionality does not. I am using the Snapshot class to take a jpg of a specific movieclip that contains the certificate, but it doesn't appear to be functioning correctly.

I modified the Print functioon line 191 in the attached script to first create a jpg export, but the 'Save' dialogue box isn't appearing and no image is being created. I need another set of eyes to take a look and let me know if you spot any problems, or causes as to why it isn't working. EOSInteractiveService.as
0
Comment
Question by:James_Avery
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:ute_arbeit
ID: 35005752
The code for your class com.tbgdn.snapshot.Snapshot is not attached so I can just guess what you are doing in the save method.
One thing you should have in mind is that for security reasons the file save dialogue box in Flash is only displayed as a direct reaction after a user event likea  mouse click, key press and so on.
So if you want to save the snapshot without user interaction coming first this will not work. In the debugging version of Flash Playeran error is thrown in this case.
0
 

Author Comment

by:James_Avery
ID: 35007641
I have attached the Snapshot class to this message. So, a dialogue box cannot be triggered unless it is triggered by user interaction?
Snapshot.as
0
 

Author Comment

by:James_Avery
ID: 35008046
I believe you are correct in this. I am not using a button to trigger the save, and am trying to do it without user interaction

Is there a simple piece of code I can insert into this function on 191 that will create a basic 'Create Snapshot' alert box with a yes or no button? Clicking yes would save the image.

Is this possible? If so, what would be this best implementation?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 4

Expert Comment

by:ute_arbeit
ID: 35008128
Yes, the FileReference::save (and the FileReference::browse as well) dialogue box cannot be triggered without user interaction. The user has to click a button or something like that, and when handling the event you are allowed to trigger the save dialogue box.

You should always listen on your Snapshot object for SnapshotEvent.ERROR events that are thrown if saving does not succeed. In line 202 of EOSInteractiveService.as before calling the save() method add the line
s.addEventListener(SnapshotEvent.ERROR, snapshot_errorHandler); 

Open in new window

and implement the method snapshot_errorHandlerlike() like this:
protected function snapshot_errorHandler(event:SnapshotEvent):void
{
	trace (event.details);
}

Open in new window

0
 
LVL 4

Expert Comment

by:ute_arbeit
ID: 35008345
You can use the following line to display a basic alert box in line 200 of your code:
Alert.show("Take snapshot?", "Serious question", Alert.OK | Alert.CANCEL, this, alertListener, null, Alert.OK);

Open in new window


As Alert is asynchronous (will not stop the execution of your application) you then have to remove the next part
var s:Snapshot = new Snapshot(certificate, 85, "jpg_encoder_download.php");
s.addEventListener(SnapshotEvent.SAVED, snapshot_savedHandler); 
s.addEventListener(SnapshotEvent.ERROR, snapshot_errorHandler); 
s.save("sketch.jpg");
printPage();

Open in new window

from your printCertificate() method and move it to the handler where you handle the user's reaction to the alert:

private function alertListener (event:CloseEvent):void 
{
	if (event.detail == Alert.OK)
	{
		// take snapshot
		var s:Snapshot = new Snapshot(certificate, 85, "jpg_encoder_download.php");
		s.addEventListener(SnapshotEvent.SAVED, snapshot_savedHandler); 
		s.addEventListener(SnapshotEvent.ERROR, snapshot_errorHandler); 
		s.save("sketch.jpg");
		printPage();
	}
}

Open in new window

0
 

Author Comment

by:James_Avery
ID: 35008600
Thank you so much for the help. I have followed the instructions above, but am receiving the following error when compiling. Any thoughts? Attached is the modified script.

"/Users/jamesavery/Desktop/Eos Interactive 2.0/EosInteractive_src/classes/com/orcamedia/eos/EOSInteractiveService.as, Line 204      1046: Type was not found or was not a compile-time constant: CloseEvent.
"
EOSInteractiveService.as
0
 

Author Comment

by:James_Avery
ID: 35011552
It looks like your approach is requiring some kind of Flex capability that I don't think it currently part of the code.

I have created a button and gave it an instance name, and have it set to export for actionscript. How can I write the button click event correctly to trigger the snapshot function? My button instance name is 'saveButton'.
0
 
LVL 4

Accepted Solution

by:
ute_arbeit earned 500 total points
ID: 35016145
Sorry, the alert box and closeEvent was indeed Flex stuff.

You can define a function that is called when your button is released. Put this code on the Flash timeline:
saveButton.onRelease = function() { 
	// take snapshot
	var s:Snapshot = new Snapshot(certificate, 85, "jpg_encoder_download.php");
	s.addEventListener(SnapshotEvent.SAVED, snapshot_savedHandler); 
	s.addEventListener(SnapshotEvent.ERROR, snapshot_errorHandler); 
	s.save("sketch.jpg");
};

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question