Solved

Need help with AC3 Jpeg Encoder

Posted on 2011-02-28
8
438 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

820 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