Adobe Animate Actionscript 3.0 "clicktogotonextscene" code not working - actionscript-3

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

Related

Flash CS4 AS3 Event not working

I can't attach a simple event handler to a lousy movie clip. Not a single tutorial worked for me and I followed them carefully. Over an hour wasted for nothing... again! Here's what I did:
Layer1: created a symbol(movie clip). Added a rectangle. Draged it onto the layer. Added a name 'obj' in the Properties window. Exported it for ActionScript.
Layer2: Open Action Panel and wrote the following:
obj.addEventListener(MouseEvent.CLICK, move);
function move(event:MouseEvent):void {
obj.x = 200;
obj.y = 200;
}
I don't know what I might be overlooking. I tried with the import flash.events.Event; at the top. Although it wasn't present in the tutorials I've watched(on youtube).
P.S. Needless to say, I'm just starting with ActionScript 3.0 but I am reading about the basics on adobe.com
I think I got it. Adding a name for the movie clip symbol is one thing. But when we drag it onto the stage, then we have to click it. And THEN, in the properties tab of the object on the scene, we give it a (class) name. So that ActionScript can see and use it. Right-clicking on the movie clip in the Library tab and selecting Properties is NOT the properties we're looking for.
Edit: Thanks, akmozo. I just found that out. Took me long enough!
Edit2: Just wanted to point out something - when I save a project in Flash CS4 which has an event handler. The handler didn't work. The code itself, that is. I tried the same project in CS3 and it worked fine. So part of the problem was the program itself(Flash CS4).

How to turn a shape into a button AS3

I have started making an advent calendar using the adobe flash professional software. I have drawn each 'door' individually with the draw tool on separate layers. I need to know how to use action script to wait for a click on one of the doors and then goto a specific layer and stop. I have tried different methods such as
button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
but it throws up errors.
Any ideas would be appreciated.
Thanks
If you drew the door it's still just a vector drawing that you can't really do anything with yet - you'll need to convert it to a MovieClip or a Sprite or a Button. The simple way to do this in the interface is:
Use the pointer to select everything you want to be contained in your MovieClip.
Press F8 OR choose "Modify" from the top menu and then "Convert to Symbol."
From there, you'll get a dialog box that looks like this:
You'll need to give it a name. This name will be the Class Name so call it something like "Door" or something descriptive like that. Leave the type as MovieClip and click "Ok."
Now you have the class so you'll have to give it an instance name. Select the object that you just created on the stage. In your properties it should look something like this:
Where it shows "instance name" delete that and give your object a name. In your code example you called it button so call it button here. Now you have an object that can listen for event listeners. Inside your handler you can write something like this.gotoAndStop(2) to get where you need to go.
Hope this helps!

gotoAndPlay(label) stop all other actions on the page

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*

Adobe flash can't run code in a frame

Ok, I'm fairly new to Flash, and I was trying to code some ActionScript now for the last two days. I can't a simple piece of code to work:
stop();
So... pretty simple right? ;)
I have a 10 frame animation, and I'm trying to make the animation stop at frame 5. So I select frame 5 from my timeline and then I open the action menu and I simply write stop(); in the window. When I run it I get the following error message:
In ActionScript 3.0 code cannot be placed directly on objects. Please select an object or use the Code Snippet panel to apply code to the current selection on stage.
I totally understand this is a simple question and the answer might be obvious, but I can't find it...
Thanks
EDIT:
I tried debugging it, and it works when in the debugger but not when in flash...
You're putting the code "on" the object, not allowed in AS3 (thx god).
To avoid it, create a new layer and name it "code" (or whatever you want), and put the code in it

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!
star1.addEventListener(MouseEvent.CLICK,gotstar);
function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}
Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.
you need to remove it from the stage if I understand.
try this instead of star1.x = -500;
stage.removeChild(star1);
star1.removeEventListener(MouseEvent.CLICK,gotstar);
star1.parent.removeChild(star1); in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding