Solved

Need help with AC3 Jpeg Encoder

Posted on 2011-02-28
8
435 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Software Restriction Policy 8 854
Adobe Flash Free Transform Tool 2 128
FlashBuilder allocate more memory using FlashBuilder.ini 18 245
IE11 stops playing video on a certain website 10 68
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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 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.

947 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

18 Experts available now in Live!

Get 1:1 Help Now