?
Solved

Need help with AC3 Jpeg Encoder

Posted on 2011-02-28
8
Medium Priority
?
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

752 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