Print button in as3 adobe animate - actionscript-3

I have two keyframes in the main timeline I want to print when the user clicks a button on frame 1. I am trying to do this with the code below but although I get the print dialogue to come up it doesn't see to add the pages. Not sure if I am targeting the right thing. Any help is greatly appreciated. Thanks in advance.
print_bu.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_190);
function fl_MouseClickHandler_190(event:MouseEvent):void
{
var myPrintJob:PrintJob = new PrintJob();
var result:Boolean = myPrintJob.start();
if (result) {
this.myPrintJob.addPage(MovieClip(root), null, {printAsBitmap:true}, 2);
this.myPrintJob.addPage(MovieClip(root), null, {printAsBitmap:true}, 3);
myPrintJob.send();
} else {
//User does not have printer or user canceled print action
}
}

Related

How could I animate an instant message conversation in Flash Professional using AS3?

I'm creating a large "movie" using flash professional CC and AS3. In one scene I want my character to be IMing his friend. The scene is already animated and shows the back of his head and the viewer can read his screen.
I want the user to be able to type for my character, so whatever the user types shows up in the bottom of the chat box, and then when the user presses enter the same text appears in a different place on the screen.
Unfortunately I haven't even gotten CLOSE to making that happen. So far I'm stuck on getting the text from the input box to appear in a dynamic textbox elsewhere, so I've been watching tons of tutorials. This code runs without errors but does not output the text like I want.
var outputString = outputBox.text; //get key presses only when textfield is edited
inputBox.addEventListener(KeyboardEvent.KEY_DOWN, handler);
function handler(event:KeyboardEvent) { //13 is enter key
function handler(event:KeyboardEvent) { //13 is enter key
if(event.charCode == 13) {
outputBox.text = "UserName: " + outputString;
}
}
(Please ignore the bad indentation, that's more of an issue with me not understanding how to paste code here haha.)
Anyways does anyone know what's wrong? I have been trying to figure this out for days so if anyone could share some example code for how to get what I described working properly it would be immensely appreciated. All I really need to be able to do is save the user input so I can display it whererever I want. Thanks for reading!
Simple enough. Just set the text value of your output to your input after the keypresses.
import flash.text.TextField;
import flash.events.KeyboardEvent;
var input:TextField = new TextField();
addChild(input);
input.type = "input";
input.text = "Type Here!";
input.addEventListener(KeyboardEvent.KEY_UP, handler);
var output:TextField = new TextField();
addChild(output);
output.text = "other text";
output.alpha = 0.5;
output.y = 25;
function handler(e:KeyboardEvent):void {
output.text = input.text;
}

The best method to create typewriter effect?

Hey everyone so I am creating a game that focuses on character to character interactivity. So when you interact with a character a chat box opens and the characters start talking to one another. I have the text setup like an old school typewriter effect one letter at a time. As of now I create it by typing each letter on separate frames and have them play through. When it gets to then end of the sentence in order for the user to go on to the next sentence I have a button that they tap Here is the code:
private function nextConvo(e:MouseEvent):void
{
nNext += 1;
trace(nNext);
if (nNext == 1)
{
conversation.gotoAndPlay(1);
}else
if (nNext == 2)
{
conversation.gotoAndPlay(117);
}
}
As you can see i set it up to play the next frame with the new conversation so on and so on. I have a lot more text to do I realized it will be really time consuming and wonder if there is a easier way.
A method to where it types the string in the text box and I can still use my button so when the user wants to see the next conversation they can press the next button.
I saw a video here of someone showing the code way of doing it but Not sure how I would implement the button without having to add a lot of new mouse listeners and timers. Code Method
Please any help would be appreciated.
Omg, yes, you will go nuts if you show one character per frame :)
The idea is to have a function to handle this for you that you have ONCE somewhere (for example, on your main timeline). Then you can call it from everywhere and just pass the text, textfield to type into and a button.
private var _myText:String;
private var _myTextField:TextField;
private var _myButton:Button;
private var _currentCharacterPosition:int;
public function typeText(text:String, myTextField:TextField myButton:Button):void
{
_myText = text;
_myTextField = myTextField;
_myButton = myButton;
_myButton.visible = false;
_currentCharacterPosition = 1;
typeNextCharacter();
}
private function typeNextCharacter():void
{
_myTextField.text = _myText.substr(0, _currentCharacterPosition);
if (_currentCharacterPosition == _myText.length)
{
// all text is typed out, show your button
myButton.visible = true;
}
else
{
// type next character. 0.2 is the delay between letters (200 ms)
_currentCharacterPosition++;
setTimeout(typeNextCharacter, 0.2);
}
}
Assuming you have the textfield and button in the same place (same frame), you could then do this in that frame:
_root.typeText("This is my text to type out", myTextField, myButton);

AS3 - how to best use variables to effect functionality on different frames

I'm currently building a 50 button interactive display, it needs on a specific frame to log 3 button clicks then save a variable or something that 2 slides later will relay whether the user has chosen the correct 3 buttons. This warning is a simple movie clip. Below I listed the 2 frames that need to relate to each other. Please keep in mind I am fairly new to programming Flash and still struggle correct syntax and utilization.
I appreciate any or all input on how I can better accomplish this using Actionscript 3
The below is hiding 3 boxes that will surround the correct answer once clicked. The fl_check36 needs to somehow in the else section send a variable or something i can reference that would let me show the error box movie clip to the user. (I already have a reset button working for that page)
[Frame 36]
MDI_07_box_mc.visible = false;
MDI_08_box_mc.visible = false;
MDI_14_box_mc.visible = false;
// Boxes to be clicked
MDI_07_btn.addEventListener(MouseEvent.CLICK, fl_ClickToShow_14a);
function fl_ClickToShow_14a(event:MouseEvent):void
{
MDI_07_box_mc.visible = true;
}
MDI_08_btn.addEventListener(MouseEvent.CLICK, fl_ClickToShow_14b);
function fl_ClickToShow_14b(event:MouseEvent):void
{
MDI_08_box_mc.visible = true;
}
MDI_14_btn.addEventListener(MouseEvent.CLICK, fl_ClickToShow_14c);
function fl_ClickToShow_14c(event:MouseEvent):void
{
MDI_14_box_mc.visible = true;
}
// Check for boxes correct and go to next frame
MDI_18_btn.addEventListener(MouseEvent.CLICK, fl_check36);
function fl_check36(event:MouseEvent):void
{
if (MDI_14_box_mc.visible && MDI_08_box_mc.visible && MDI_07_box_mc.visible)
gotoAndStop(37);
else
Feedback_07_Wrong_mc.visible = false;
}
This frame just needs to check if the user got the information correct on frame 36 and show or hide the Feedback based on that.
[Frame 38]
stop();
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_2);
function fl_EnterFrameHandler_2(event:Event):void
{
if (globalVar = 1)
Feedback_07_Wrong_mc.visible = true;
Feedback_07_Wrong_mc.gotoAndPlay(2);
}
Reset_Btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);
function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
gotoAndPlay(1);
}
Thanks in advance!
What #Karma said is true. When you declare any variable on frame 36, it is accessible to any other frames that preceed it. You can also do the same by creating another layer called "Variables" with no keyframes in between which stores all your variables. This way, you would have confidence that the variable is acceccible to all the keyframes of the other layer.

Actionscript 3: Back History Button

Sorry in advance. I am new in Actionscript and trying to implement a history back button, not a go to previous frame button; in a flash movie, not in a flash web page). My approach is to use an array and push the currentframe to it on any visited frame. My code is not working and it is giving back an error #1502.
Please help me to fix the code I have by now:
var back:Array = new Array(); //global variable
stop();
back.push(MovieClip(this.root).currentFrame); // in every visited frame
back.addEventListener(MouseEvent.CLICK, backGoTo);
function backGoTo(event:MouseEvent):void
{
switch (currentLabel)
{
case "framelabel":
for (var i:int = 0; i < back.length; i++)
{
gotoAndStop(back[i]); // expected to go to the last visited frame.
}
break;
}
}
thanks a lot in advance.
To get the last element of an array, use back[back.length-1], or if you want to remove the last element and get it back at the same time then back.pop();. So in your case, that for cycle has no use, it's all wrong.. nonsense to check all the elements of an array in this case.
function Softkey3GoTo(event:MouseEvent):void
{
switch (currentLabel)
{
case "m_1":
case "m_2":
case "reply":
case "messages":
gotoAndStop(back[back.length-2]); // -2 because the current one is -1, the previous frame is -2.
break;
}
}
After exploring the Array .pop method I could find the solution to my back button. here is my code for a global back history button. in every frame you must push it to the array. call the last element of the array and delete it at the same time:
var back:Array = new Array(); //global variable
stop();
back.push(MovieClip(this.root).currentFrame); // in every visited frame
back.addEventListener(MouseEvent.CLICK, backGoTo);
function backGoTo(event:MouseEvent):void
{
switch (currentLabel)
{
case "framelabel":
back.pop();
gotoAndStop(back.pop());
break;
}
}

Flash/AS3: Type was not found or was not a compile-time constant

it's been several years since I've touched AS3, but have a project requiring a bit of scripting.
I'm trying to have a Table of Contents menu slide down, then slide up, depending on a generic Open/Close button. The concept is the same as using .slideToggle() in jQuery.
I've created a MovieClip, given it an Instance Name and have Exported it for ActionScript in my Library, but for some reason, when I try and run a method to just shift it down 325px, I keep getting this error:
1046: Type was not found or was not a compile-time constanc: toc.
I realize that the library is missing a reference for something, but since the MC has an Instance Name and has been exported for AS, I'm a little puzzled as to what it could be. All of my scripts are in Frame 1, and I'm not using any external classes. Any help/pointers would be greatly appreciated!! I'm also having the same issue when I try to create the Email link, towards the bottom of my code.
Again, any help would be greatly appreciated!! Thanks!!
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
// Initial load elements
gotoAndStop("Frame1");
UpdateFrame();
// Mouse events
btnNextSlide.addEventListener(MouseEvent.CLICK, NextSlide);
btnPrevSlide.addEventListener(MouseEvent.CLICK, PrevSlide);
btnTOC.addEventListener(MouseEvent.CLICK, ShowToC);
//btnDifferenceLink.addEventListener(MouseEvent.CLICK, Email);
// Various Methods
function NextSlide(event:MouseEvent):void
{
// find current slide, go to next slide
var currentFrame = this.currentFrame;
var nextFrame = currentFrame + 1;
if (int(nextFrame) == this.totalFrames)
{
// stop
gotoAndStop("Frame" + this.framesLoaded);
}
else
{
// go to next slide
gotoAndStop("Frame" + nextFrame);
}
// go to and stop at the next frame
UpdateFrame();
}
function PrevSlide(event:MouseEvent):void
{
// find current slide
var currentFrame = this.currentFrame;
var prevFrame = currentFrame - 1;
if (int(prevFrame) == 1)
{
// stop
gotoAndStop("Frame1");
}
else
{
// go to next slide
gotoAndStop("Frame" + prevFrame);
}
// go to and stop at the next frame
UpdateFrame();
}
function UpdateFrame():void
{
txtCurrentSlide.text = this.currentFrame.toString();
}
function Email():void
{
var email:URLRequest = new URLRequest("mailto:emailaddress");
navigateToURL(email, "_blank");
}
function ShowToC():void
{
// slide Table of Contents down
toc.y = 325;
}
function HideToC():void
{
// slide Table of Contents up
toc.y = -325;
}
I have just found the solution!
curtismorley.com/2007/06/20/flash-cs3-flex-2-as3-error-1046
In his first paragraph, he mentions objects on your stage and in your library cannot have the same name. In my case, I had an asset called "toc" in the library, and was referencing "toc" via Instance Name. By changing this, the problem has been solved. I've been searching for a day and a half on this stupid error..