gotoAndPlay(label) stop all other actions on the page - actionscript-3

I am actually at UNI doing bachelor of multimedia and we are creating a Flash movie for an assignment.
In all my fixing up, I have wrecked some code and I can't see why it won't work, because it is exactly the same as in the file that does work.
I have several buttons on one page that when clicked just go to other pages, they are working fine with functions. I have some buttons that go to a name label at a certain frame, it works for the first button, then it seems that once that button is clicked, it some all other functions on the page and no other buttons can be clicked.
Here is the code:
phonebtn.addEventListener(MouseEvent.MOUSE_UP, goPhone);
function goPhone(evt:Event):void{
gotoAndStop("phone");
}
emailbtn.addEventListener(MouseEvent.MOUSE_UP, goEmail);
function goEmail(evt:Event):void{
gotoAndStop("email");
}
addressbtn.addEventListener(MouseEvent.MOUSE_UP, goAddress);
function goAddress(evt:Event):void{
gotoAndStop("address");
}
If I put in gotoAndPlay(), it plays too long and goes to the next page.

i noticed one mistake in your function statement . that
function goEmail(evt:MouseEvent):void{
gotoAndStop("email");
}
you need to write MouseEvent whenever you are writing event for Mouse. and this is not an issue. try this. And gotoAndStop will stop on that frame. If there is any frames under that particular target frames or movieclip it will play that only not on currentTarget frames. So without seeing your frames code it is little difficult to identify your problem because you have asked on frames code. I hopes it wuld help*

Related

Adobe Animate Actionscript 3.0 "clicktogotonextscene" code not working

So I have the following code for a button called "n2" and as you can see it's supposed to take me to the next scene when I click it, but it isn't working. It is inside Scene 2 and I'm trying to get to the next one and whenever I test the scene and click it, I don't even get an error, it just doesn't work.
Btw, it's a GIF defined as a movie clip and then as a button. Could that be causing the problem?
n2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextScene);
function fl_ClickToGoToNextScene(event:MouseEvent):void
{
MovieClip(this.root).nextScene();
}
If you put a trace in the function and comment out "MovieClip(this.root).nextScene();" you could then see if the function gets called on a button click.
I've not used animate before, but in flash you have to name your button/movieclip and then also name the instance. This allows you to create the object twice with two seperate names to be referred to by actionscript.
Not sure if this helps but thought I'd give you some things to try, good luck

Why does one of my AS3 event handlers only work once?

I am building an SWF panel with support for English and Japanese, and a button to toggle between them. The English is on frame 1, the Japanese on frame 2. On the first frame there is this relevant AS3:
btnLangToggle.addEventListener(MouseEvent.CLICK, onLangToggle);
...
this.stop();
...
function onLangToggle(e:MouseEvent):void {
if (MovieClip(root).currentFrame == 1) {
MovieClip(root).gotoAndStop(2);
} else {
MovieClip(root).gotoAndStop(1);
}
trace(MovieClip(root).currentFrameLabel);
}
I click the button and the event handler function runs fine, once. If I click it again, nothing happens. Why?
Edit: Here is what my two frames and timeline look like.
If I click it again, nothing happens. Why?
Because It's a MovieClip and they are designed for animation, not for application states. Objects on the scene in first frame isn't accessible in the second key frame.
I assume in your case you have button for toggling language with different instances of MovieClip(Different languages). In second frame apply again event listener for the Japanese version of the language button:
btnLangToggle.addEventListener(MouseEvent.CLICK, onLangToggle);
Also, please read about Document Class, It's pretty simple create application with only 2 states, like you have (with 2 frames...)
I assume you are using key frames for the button, right?
You must be sure that the button is the same on both frames. Which means you must not use key frames - instead use separate layer for the button with a single keyframe and two normal frames. This way your code will work as it's the same button.

Actionscript 3: How to have a keyboard Keystroke "Button" go to specific Frame FROM a specific Frame?

I'm Super New to Programming in general and very New to Actionscript 3. It's been a rough but fun ride.
Anyway For the work I am doing I have my animation Play up to a certain point and it asks the viewer a question, The viewer has 3 choices, and each of those choices are connected to a button on the keyboard. A B C or D.
After searching for someone with a similar problem, My solution so far is this:
stage.addEventListener(KeyboardEvent.KEY_DOWN, cNote);
function cNote(event:KeyboardEvent):void {
trace(event.keyCode);
if (event.keyCode==67) {
gotoAndPlay(21);
}
I have this repeated 4 times each for the different Keys.
This works and allows me to move the viewer to the Frame with their response, however Any time during the animation they can press the button and it will move them to the Frame of the corresponding button (in this case Frame 21). How do I set it so that the keypress will only respond and move them to Frame 21 when they are on Frame 20 for example? (I suspect it has something to do with the "stage" part in the code but I cant get it to work without it.)
I also have the audio for the animation on a separate Layer and even though the visuals change as it goes to the correct frame, the audio continues as if the key was not pressed. Is there also a way to connect the key to make it stop the current audio and then play the new audio? Or is there a better way to do this?
Sorry if this is confusing. Thank you for your help :)
It has been quite awhile since I touch flash. From what I remembered, you can click on the frame at your movieclip, insert a keyframe by pressing f6, and press f9 to insert the listener at that frame and that frame only, after an input has been pressed, you remove it. for example:
if (event.keyCode==67) {
gotoAndPlay(21);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, cNote);
}
For the audios, I usually plays them using code, but I'm quite sure there's a way to drag and drop the audio from library to the movieclip. so I can do sound1.play(), when a button is pressed, I can do sound1.close() and sound2.play()
For more reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html

My flash menu going crazy. AS3

I have a menu with 4 button, for switch to other content page, and all of it had this code:
function chuyenhome(e:MouseEvent):void{
homect.addEventListener(Event.ENTER_FRAME, nexttohome);
btn_home.gotoAndStop(15);
if (btn_about.currentFrame == 15){
btn_about.gotoAndPlay(16);
}
if (btn_menu.currentFrame == 15){
btn_menu.gotoAndPlay(16);
}
if (btn_contact.currentFrame == 15){
btn_contact.gotoAndPlay(16);
}
homect.gotoAndPlay(31);
}
function nexttohome(e:Event):void{
if (homect.currentFrame>=homect.totalFrames){
MovieClip(root).gotoAndStop(4);
}
}
This is menu HOME. 3 other menu ABOUT, BLOG, CONTACT button is using the same code, but renamed function. It work fine if I click only 2 menu button. But when I try to click the third menu, it's going crazy. For example, when I click at HOME and ABOUT, it switch to HOME page and ABOUT page with no problem, no matter if I click it for thousand times. It work fine, but when I try to click at CONTACT, then... it show up HOME page, I re-click CONTACT, it show up ABOUT... and so on. It's crazy. Sorry about my English. I'm using Flash CS4 and AS3. Thanks!
You have to not add multiple event listeners to one MC. See, if all the other functions are this one copypasted with altered frames, then each of them adds an enter frame listener. These are cumulative, thus calling homect.addEventListener(Event.ENTER_FRAME, nexttohome); twice will result in two calls to nexttohome per frame. Probably you can avoid this listener altogether by putting code to the timeline of homect movie clip on the last frame, to call stop(); MovieClip(root).gotoAndStop(4);

AS3 Button stops working after random amount of click

I have a movieclip being used as a button. After a random amount of clicks the button stops working. In other words, the mouse will become a hand when hovering over the button but no clicks are registering to fire the function. I've even clicked it 40 times and it will work but then suddenly, bang!, it stops working. Heres the function that adds the btn, listener, animates it into the screen and also adds text.
function makeButton():void{
addChild(myBtn);
myBtn.mouseChildren=false;
myBtn.buttonMode=true;
myBtn.x=(stage.stageWidth/2)-(myBtn.width/2);
myBtn.y=-300;
myBtn.addEventListener(MouseEvent.MOUSE_DOWN, btnClicked, false, 0, true);
myBtn.btn_text.text="The string goes here";
TweenLite.to(myBtn, 0.5,{x:(stage.stageWidth/2)-(myBtn.width/2),y:(stage.stageHeight/2)-(myBtn.height/2)});
}
And then here's the function that animates the button outside the screen:
function btnClicked(e:MouseEvent):void{
myBtn.removeEventListener(MouseEvent.MOUSE_DOWN, btnClicked);
TweenLite.to(myBtn, 0.5,{x:(stage.stageWidth/2)-(myBtn.width/2),y:-300});
}
Strange thing is, I added a trace("listener added") into the 'makeButton()' AT THE VERY END, AFTER THE ADD EVENT. And it traces everytime, even on the times the button stops working. SO i can only assume there are no errors with listener being added. But then why is it not working?
I'm stumped. I thought it could be an event propagation problem. In other words the listener was being added to the target (myBtn) but somehow it was capturing or bubbling wrong but..... then why does it work at all? And for so many clicks?
The truth is out there. Or maybe in here, your insights will be much appreciated.
Where does myBtn get created? I can see right at the beginning of makeButton() that you are adding it the display list but can't see where it actually gets created? Is it already on the stage?
Adding a trace statement in the makeButton function will only tell you that a button is created, it won't say much about the functionality of your button. If you want to check if your button reacts to a click , you need to add your trace statement in the click listener.
According to your description , it sounds like you keep adding the same button to the stage rather than actually clicking the same button.
How often do you call the makeButton function before it stops working? This function looks like it should only be called once. As for the btnClicked function , why do you remove the listener, if you wish to click the button again?
Practically it looks like you should only have your Tweening functionality in your functions, I mean , once the button is created , you need one function to tween the button, then instead of adding the button again, simply call a function to tween the button back in place.
All the rest shouldn't be repeated.
I've fixed the code and the problem hasn't occurred again. The problem must have been that I was running the addChild every time the function called and that was doing something odd to the MC in the display list. I haven't pursued the error by clicking the buttons many times in a row for a minute or two, as I did to make the error happen originally. I think i'll let sleeping dogs lie.
With that said, my code is a lot cleaner with the addChild and other crap running in the initialization function and just sitting above the stage - and then being tweened into position in the 'makeButton' and 'btnClicked' functions (which are now fittingly named 'tweenBtnIn' and 'tweenBtnOut').
Thanks again