Solved

Need help with AC3 Jpeg Encoder

Posted on 2011-02-28
8
434 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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 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.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now