AS3: Print Job without Print Dialog Box/Print Setup Dialog - actionscript-3

Is there a way to print a job without the print dialog box.It will look for the default printer then it will also print all pages.After I click the print button, inside of the movieclip will be print all. Then how can I do it? I don't need AS3 swf not Air if possible..
Here's the code I'm using..
print_btn.addEventListener(MouseEvent.CLICK,printContent);
function printContent(evt:MouseEvent) {
var printJob:PrintJob = new PrintJob();
if (printJob.start()) {
if (content_mc.width>printJob.pageWidth) {
content_mc.width=printJob.pageWidth;
content_mc.scaleY=content_mc.scaleX;
}
printJob.addPage(content_mc);
printJob.send();
}
}
NOTE:
I already used the start2() but this code is for AIR.

It appears there's an answer out there just did some googling:
http://forums.adobe.com/thread/854070
var pj:PrintJob = new PrintJob();
var started:Boolean = pj.start2(null, false);
if(started)
{
pj.addPage(this);
pj.send();
};
pj = null;

Related

Actionscript: SWF file does not record data to txt, while the compiler does

I am trying to create a psychological experiment in ActionScript. The performance of the participants is to be stored in a separate .csv file. I have written this code (apparently, instead of "This is the text to write" there is going to be a data array, but the problem appears with this code on equal parts)
import flash.net.FileReference;
import flash.events.Event;
var hint:String = "Please give a name for the file";
var labelling:String;
experiment_label.addEventListener(KeyboardEvent.KEY_UP, enter_pressed)
function enter_pressed (event:KeyboardEvent):void{
if (event.keyCode == 13) {
labelling = experiment_label.text;
addEventListener(Event.ENTER_FRAME,saveFile);
var ss:String = "this is text to write";
var fileRef:FileReference;
fileRef = new FileReference();
function saveFile(event:Event):void
{
fileRef.save(ss, labelling+".csv");
removeEventListener(Event.ENTER_FRAME, saveFile);
}
}
}
The problem I am facing is as follows: when I run it in from under Flash, it operates perfectly, and the save window does pop up. However, if I run an .swf file separately, it just ignores saving command.
Could you kindly suggest, what can I do? Or maybe I should use a different approach to saving altogether?
You current code will give you an Error #2176 (use a try ... catch to catch it) because FileReference.save()
is not called in response to a user action, such as a mouse event or keypress event.
To avoid that, you have to remove the Event.ENTER_FRAME event listener, even you don't need it :
function on_KeyUp(event:KeyboardEvent):void
{
if (event.keyCode == 13)
{
save_File();
}
}
function save_File():void
{
try
{
var fileRef:FileReference = new FileReference();
fileRef.save('some text here', 'my_file.csv');
}
catch (e:Error)
{
trace(e.toString());
}
}
Hope that can help.

How to run JavaScript dynamically in a Flex AIR application?

What is the easiest way I can run JavaScript dynamically in a Flex or ActionScript AIR application?
This is what I have so far. It does not work yet and htmlComponent.domWindow is so far null:
if (htmlComponent==null) {
htmlComponent = new HTML();
htmlComponent.htmlText = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlComponent.addEventListener("complete", function(e:Event):void {trace('html load complete');});
IInvalidating(htmlComponent).validateNow();
}
if (htmlComponent.domWindow && htmlComponent.domWindow.validateXML) {
result = htmlComponent.domWindow.validateXML(value);
}
Your issue, is likely that you do not wait for the loading of the content to actually load. So when your code runs, the DOM is still empty.
var htmlText:String = "<html><script>"+myJavaScript+"</script><body></body></html>";
htmlLoader = new HTMLLoader();
htmlLoader.loadString(htmlText);
// add a complete handler and don't reference the DOM until it's complete
htmlLoader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete(e:Event):void {
if (htmlLoader.domWindow && htmlLoader.domWindow.myFunction){
//...do what you need to with the domWindow
}
}

How do you add a link in a swf file?

I am using HTML and I want to embed it and link it to my other webpages. It is in offline mode and I've been searching a lot and found this:
MyClickTagButton.addEventListener(
MouseEvent.CLICK,
function():void {
if (root.loaderInfo.parameters.clickTAG.substr(0,5) == "http:" || root.loaderInfo.parameters.clickTAG.substr(0,6) == "https:") {
navigateToURL(
new URLRequest(root.loaderInfo.parameters.clickTAG), "_blank"
);
}``
}
);
But what I don't understand is how to put my link. Because my website links are only "person.html", "welcome.html", etc. If you know how, please help me. I'll really appreciate it.
You need to open it in Adobe Flash builder (or other swf (Shock Wave Flash) editors) and add the Actionscript 3 to create an event handler for the movie clip and add the URL:
<pre>
ACTIONSCRIPT 3 CODE:
var mySWF:String = "Your SWF movie clip name here";
mySWF.addEventListener(MouseEvent.CLICK, goToUrl);
function goToUrl:void {
var url:String = "Your URL here";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
</pre>

Open external .swf in another frame or window

I am trying to link to an external .swf file, which I have done, but it opens as a popup within the main .swf. What I want to do is either have it navigate to a blank frame with the external .swf there or have it open in a new window. How do I achieve this?
Here is the code I have which opens the external .swf:
private function openSWF():void {
cSWFLoader = new Loader();
cSWFPopup = addChild(cSWFLoader);
cSWFLoader.x = cPopX;
cSWFLoader.y = cPopY;
try {
cSWFLoader.load(new URLRequest(cSourceFile));
cSWFLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, SWFLoaded);
}catch (err:Error){
trace("YOU DONE GOOFED", cSourceFile);
trace("Error: ", err);
cSourceFile = null;
}
}
private function SWFLoaded(evt:Event):void{
cSWFLoader.addEventListener(MouseEvent.MOUSE_DOWN, dragSWF);
cSWFLoader.addEventListener(MouseEvent.MOUSE_UP, dropSWF);
cSWFPopup.content.gotoAndStop(cFrameLabel);
cSWFPopup.content.closeBtn.addEventListener(MouseEvent.CLICK, closeSWF);
cSWFLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, SWFLoaded);
}
Thanks in advance

after loading a flash movie the form stops working

I'm a total begginer in flash and action script, I do have some knowledge in other programming languages.
By trying to help a friend I added a contact form in his company website, that was made by someone else.
his site is full flash with a index frame that loads several pages.
After I built the new contact.swf and tested locally and also hosted by accessing it straight from the browser and embeded I tried to replace it with the old contact.swf that had no contact form.
During the tests, everything was fine but when included in the site the form is not functioning.
The form has a few rules that prevent empty fields with a green text warning. when I access it embeded separatelly in a web page it works, when I access it loaded by index.swf it does nothinh even if I press the submit button.
So I assume the problem is in the index.swf action script.
the button that loads the contact page has this code:
on (rollOver) {
gotoAndPlay(2);
}
on (rollOut) {
gotoAndPlay(11);
}
on (release) {
_root.main.secondary.loadMovie("contact.swf");
_root.main.logo.gotoAndPlay("s1");
}
I assume that is either the way the movie is loaded either there is something like a mask in the index movie that blocks the contact form.
If required I can submit also the fla of the index or the contact.
thanks
LE:
I tried to add to my contact.swf _lotroot=true; and i get compilation erros.
the action script for contact.swf is this:
stop();
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
// ----------------------------------------------------------------
var variables:URLVariables = new URLVariables();
// Be sure to change this URL to the PHP parse file on your site server
var varSend:URLRequest = new URLRequest("http://www.mydomain.tld/form.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
status_txt.text = "";
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
function ValidateAndSend(event:MouseEvent):void{
//validate form fields
if(!name_txt.length) {
status_txt.text = "Introduceti numele dvs.";
} else if(!companie_txt.length) {
status_txt.text = "Introduceti numele companiei.";
} else if(!telefon_txt.length) {
status_txt.text = "Introduceti numarul de telefon.";
} else if(!email_txt.length) {
status_txt.text = "Introduceti o adresa de email.";
} else if(!validateEmail(email_txt.text)) {
status_txt.text = "Introduceti o adresa de email corecta.";
} else if(!message_txt.length) {
status_txt.text = "Introduceti mesajul.";
} else {
status_txt.text = "Multumim " + name_txt.text + ", mesajul a fost trimis!";
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = message_txt.text;
variables.companie = companie_txt.text;
variables.telefon = telefon_txt.text;
varLoader.load(varSend);
}
}
function validateEmail(str:String):Boolean {
var pattern:RegExp = /(\w|[_.\-])+#((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(str);
if(result == null) {
return false;
}
return true;
}
The code you have provided for the original site is in AS2, but the code from your contact SWF is in AS3. You cannot load AS3 into AS2, so you will have to rewrite your contact form using AS2.