Last Updated on February 26, 2019
So I used to monitor comments coming in from the CS3 Video Workshop, which contains a few hundred video tutorials on the CS3 products. Some of the comments that came in regarding the Flash videos was how people were having frustrations about how to set up button code with ActionScript 3.0. I thought that’s where I’d start out, with a simple example that compares the two. So I’ll show you how to make a button work in Flash CS3 or Flash CS4 using ActionScript 3.0.
Luckily, the set up is pretty much the same assuming you put code on the Timeline. If you didn’t, it will be a bit of a change and you’ll need to follow the steps below.
When you were using ActionScript 2.0, you would put code on the main Timeline. You’d have a button on the Stage with the instance name myBtn (set in the Property inspector). You would add code to frame 1 that reads:
myBtn.onRelease = function() {
getURL("http://www.flashthusiast.com");
};
In ActionScript 3.0 it looks a bit different. And yes, it’s an extra line of code and it is a bit more complex looking. However – you don’t need to use classes or anything, set up is the same. Here are the steps you’d take to create an interactive button in Flash CS3.
- Create a button, just as you would in Flash 8.
- Select the instance, and add the instance name monkey_btn in the Property inspector.
- Insert a new layer, and rename it actions.
- Open the Actions panel (Window > Actions), select frame 1 of the actions layer, and add the following ActionScript in the Script pane.
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.flashthusiast.com/"));
}
- Choose Control > Test Movie to test your document.
And that’s all there is to creating a clickable button with AS3. All you need to do is change the URL to make it work in your own document. Or, you can change that entire line to be something else, such as go to and play a frame number: gotoAndPlay(6);
You can also change the MouseEvent from MOUSE_DOWN to, say, MOUSE_OVER to change how the interaction works. Search Flash Help for MouseEvent, and look at the Class in the ActionScript 3.0 Language Reference.
Sample File – Button
MORE INFORMATION ON BUTTONS:
- If you have MORE THAN ONE BUTTON and want to add that to your FLA file, please continue on to this post about adding multiple buttons to your file.
- For info on targeting scenes or frames within a single scene, see this post here: http://foundpixel.com/articles/creating-buttons-that-link-to-different-scenes-using-actionscript-30/
- For info on targeting different windows with your button code (such as the same window instead of a new window), see this post: http://foundpixel.com/articles/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
- For information on creating MovieClip buttons in Flash, see this: http://flashthusiast.com/2008/10/19/movie-clip-buttons-in-a-fight-its-as2-vs-as3-again/
- For information on controlling the browser window target that opens when a button is clicked, see: http://flashthusiast.com/2008/10/19/movie-clip-buttons-in-a-fight-its-as2-vs-as3-again/
- For info on creating buttons that go to the next frame or previous frame on the timeline, see: http://flashthusiast.com/2010/05/05/buttons-in-flash-using-actionscript-3-0-going-to-next-frame-and-previous-frame/
Jen, a flashthusiast says
Hey Vlad,
luckily you just need to modify the code above, and it’s pretty much the same as AS2 :) This should hopefully work for you, just swap out the frame number you need to stop at and change the button’s instance name to that of your button —
Vlad says
I probably put a comment in the wrong spot … ups. I just made my first button using CS3 and can’t make it work because scripting 3 is like a whole new moster. I just need to go to the next frame. HELP!
Jen, a flashthusiast says
Hey Chet,
The quickest way would be to make the three functions for the three buttons, and point them at the three frames. So I just renamed the function for the three instances:
Chet says
Soooo… what I have three buttons and want them to go to different frames? I repeated the code you provided for each button but Flash says I can’t use the same function multiple times…
John says
OK, I am pretty much the wettest behind the ears guy around with Flash. I used your tutorial on Flash CS3, and almost understood it, but got all to work. I’m now playing with something else where I want 4 buttons, each re-directing to a new URL. I tried the following to start:
which makes sense to me, but get the following:
my first thought was to add a different action to a different layer, but I can’t figure out how to get more than one layer to appear in the action toolbar (or am I way off?)
HELP!
Thanks,
John
John says
OK, so I can’t even get my code here correctly. It’s more like this:
AND the error is:
Jen, a flashthusiast says
Hi John,
It’s pretty much the same solution as Chets – the functions (function buttonClickHandler) need to have different names. Alsonitced that there was a little typo in the code (the first navigateToURL).
So the below code changes those two things, and it seems to work :)
Hope this helps,
Jen.
Kojin says
Hi there.
I’ve got quite similar example, the only difference is its about gotoandplay/stop action. It looks like this:
First button works fine, but second one doesn’t. Instead of going straight into frame 25 and stopping there, it begins animation from frame 2 and stops at the last frame (because of stop action in frame 30).
Kevin says
hi, i cnt seem to get the hang of this. i got 5 buttons in frame 1, and i want each button to to go to different scenes!! how do i do that.
because i tried to make the buttons go to different frames, but for some reason, the 1st button takes me to frame 20 but then all the rest of the button ALSO keeps taking me to frame 20?? heres the code i used:
Jason says
When you make the function unique you need to changes it call too.
So in:
grinder_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2); <— You add you 2 here as well.
Jen, a flashthusiast says
Thanks Jason! I should have definitely tried my code before typing it into wordpress :) Great catch there.
Jean-Francois says
Hey, Everyone….
I am a newbie to flash cs3 and as3. I’ve been building a flash website for the past week or so and so far things are going ok. However, I have a navigation menu with buttons I’ve as’d to navigate to a new url. Currently when the buttons are clicked they open the url in a new tab in my net browser; I am using the code below for these buttons:
What I need to know is how I get these same button instances to open the new url in the same tab I’m already viewing. Any help would be much appreciated.
Thanks.
Kevin says
Thanks Jason
D says
I have a simpler question…I have a “Scene 1” and a movie clip within the main timeline.
I have a button inside the movie clip and am trying to reference a “home” frame in the main timeline in “Scene 1”.
I have tried a number of things, but just can’t fuigure it out!
Please let me know and thanks in advance.
vips says
Hi I m a newbie to flash cs3. I have worked on flash 5 b4. I need my button to take me to scene 2 from scene 1. Could u please help me with the code?
Thanks a ton!
marieta says
hi jen..Im pretty familiar with flash buttons and movie clips, unfortunately very little on scripting…i could get buttons to work but my question is ‘how to script a movie clip button within a movieclip? like where to include the actionscript whether in the movieclip, button or on the scene where the movieclip is’
enlightenment will be much appreciated…many thanks
Thomas says
Hello hello,
I’m new here so forgive me if I like askin stupid questions ;-) but I could really use some help on CS3 actionscript3 thing I’m tryin to work out.
For the BLOG page of my new website I made the top part in Flash and the thing is I need to get the three buttons that are in there workin…I copied the script:
and followed the instructions, of course I swapped monkey_btn for mixlawax_button and also renamed the url http://www.flashthusiast.com into http://www.mixlawax.com
AND IT WORKS!!!! :-)
Only thing now is I need the other two buttons to go to other URL’s as well and here’s where the problem starts.
When I copy paste:
into the ‘actions’ pane and add it to the first frame and then press TEST MOVIE I get the following error:
I hope there is someone who can help me out, and yes I know I’m not Einstein hehe
Thanks in advance.
Thomas
PS: In fact my question is how do I make three buttons get three different URL’s in actionscript3??
Thomas says
Consider my last post as not sent, got it fixed :-) thanks to Flashthusiast > categories ‘buttons’ duh sorry for my stupidity ;-)
All buttons work now, nice and easy :-)
Thanks!
Peace
Thomas
Mark says
Does anyone know how to code the following:
If I want one button to control which frame to go on depending on 2 different selections. Basically, if I choose the color red in one drop down then yellow in the other drop down, when I select the go button, how would I make it go to frame 4 which has the mixed color. I am having a brain fart.
Thanks
Jason says
D,
I had this same issue and this is what I assigned to my button and it worked for me. This takes my movie to the first frame outside the movie clip.
Chad says
I’m a Newbie to Actionscript 3.
I’m trying to do a photo viewer, each photo is on it’s own frame in order, 50 photos total.
I have two buttons, advance and rewind, and can’t figure out how to simply go to next frame with the advance button and go to previous frame with the rewind button.
This is the direction I’m going with the code, it doesn’t work right and I can already see that there must be a much simpler way but I can only find examples where a button goes to a specified frame not simply to next or previous.
Chad says
Sorry I just noticed the second event listener was wrong.
jennicandance says
Get advice Jen!! Thanks soooo much, I’ve been looking for these answers everywhere!
Lou says
HI ! a newbie to Flash and AS3. I want to control the LABEL on my button but I can not get the syntax correct.
works to make it visible … but the same code doesn’t work for .enabled or .label.
I get the following error:
Tried to IMPORT the class:
but then I get the error:
Any help greatly appreciated! THANKS MUCH!!
Carl says
Add a button to your stage and then delete it. This will add a button to your library.
Ruby says
I have five text buttons linking to 5 different states on a website(home, about, news etc).
i have added the following script:
i have the following problem:
When i click a text button(doesn’t matter which one) it works fine. Then none of the buttons work after that. Assumedly because the script has not been added to the other states on the timeline. When i add the script to the five corresponding states on the timeline, i get compiler errors (duplicate script).
what’s the correct action to take?
Ingrid says
I was having the same trouble as Ruby above me, I could get to one page but after that the script went nowhere. I tried changing my MouseDown handlers to increment by one and double-checked my button names and that fixed it for me. My layers are set up so that the action covers all of the frames.
Hope that helps.
Scripting confuses me but this article is great. I’m almost there! Thanks :)
Edo says
Hi guys i’m new to the flash cs3.
After i press the button I don’t want the url to open in a new window ( want to keep it in the same window) how can i do that.
I been trying to add “_parent” but i’m getting an error msg
Tnx
jennicandance says
What if I wanted to change the rollover state:
This doesn’t work, but I’m confused on how to get it to work. Can anybody help me?
Esben Boye-Jacobsen says
I was wondering if it is possible to somehow get the name of the instance from which the action came?
If I press the thisButton_btn, then it could be nice to get the instance name passed as an argument or something – is there some way to do that?
Thanks in advance :)
Jen, a flashthusiast says
Hi Braylon – make sure your mouseDownHandler’s match each other. For example for your last button it would be
More information in this post: http://flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/
Braylon says
Braylon says
What is wrong with this? I just want to simply move down the damn timeline! Thanks
Sam Browne says
Hey i am an absolute noob at actionscript 3.0, and i want to make a button that works and links to another scene. Thankyou
Mary Anne says
I really appreciate the lesson you have been giving here. I teach a section of a digital imaging class in which I teach students how to build animation, portfolios, and websites in Macromedia Flash. I use MX since that is what is available. I have a student in the class that uses Macromedia CS3. Is there a way to go into normal mode to add actions from preset action scripts like in Flash MX and 8? Also, we are having a hard time finding movie controls under Flash CS3. Any help on this would be greatly appreciated.
David Stephenson says
Thanks for putting up this tutorial Jen, I was struggling for over an hour trying to figure out how to create the previous and next buttons for a Flash CS3 presentation.
Jen, a flashthusiast says
Hi Jay – Check that your publish settings are set to AS3. You would see that error message if its set to AS2. If that doesn’t do the trick, please let us know :) Thanks, Jen.
Ja says
Trying to get my buttons to work in CS3 using the new action script to no avail, my button code is this and it doesn’t for whatever reason move to frame 39.
Please help.
Jay says
Oh and I get this error message
Jay says
When I use this code the button has no effect.
this is the error message I get
jc says
hey im a total newbie with flash cs3 and i am trying to make multiple buttons to link to several different sites i have tried the tutorial for the one monkey button to no avail seeing as the button didnt link at all i copyed everything word for word
i changed where the button would link to here is my actionscript:
let me now any problems i have with it and any and all tips would be appreciated
jkern says
I can’t find anywhere that explains how to program a button to fast-forward 5 seconds or rewind 5 seconds with AS3. I get the logic (from what I’ve seen similar to this,) that you somehow call the current frame “n,” and you make a function akin to gotoAndPlay(n+5) seconds. I just don’t know the code to do this.
This is the best thing I have found for AS2:
Can anyone AS3-ify this?
Jrose says
For those of you who are having problems jumping to difference scenes with a button, here’s how you do it.
obviously, you can also replace the frame number with a frame label as long as you use quotes, like this:
so you must use both the frame number and scene name with AC3.
JohnB says
It tried this script and other variations but they do not work on Firefox, Opera on Windows, or Safari on Mac (and probably windows). I rolled back to Actionscript 2 (GETURL script) to get it to work, which it did except on Safari.
Is there a fix for this? I’ve done tons of research and have found none.
Turtle says
If I use AS2 – the first image in the slideshow works, the rest do not:
http://www.houstgrandopera.org
cornelius says
to the flash gods,
i am using 2.0 and i am trying to link a drop down menu to my web pages.
my drop down menu is 4 buttons that i would like to use to load a movie clip into the main
contentMC
. i have been trying to figure this out for myself but i am a little confused. i am using 2.0 and all the tutorials teach you how to link to an outside urlso my question…
menuBack
is the movie clip name for the drop down menu.resumeBtn
is the button inside the movie clip.contentMC
is the movie clip that is on stage displaying the swf file.the code that i have does not work. the buttons drop own but do not allow the swf files to load into
contentMC
.when i have the proper working code do i.? put the code into the page actions or the movie clip (
menuBack
) actions?any help would be greatly appreciated, i really want to do this on my own but i have hit a road block and i need to get around it.)
cornelius says
ignore the above comment.. i got it! unles
i was not using the proper instance name… duh!
the above code is correct just make sure that the instance names are correct,
Jayson says
I’ve been trying to get these buttons to work with no luck at all haha.
I’m using this code
I’m getting this error
please somebody help lol I am totally lost as to whats going on…thanks a bunch
B1 says
I too am also a nOOb – especially AS3.
Have a simple 7 frame project – where we start with frame one, and after frame one is finished by clicking ENTER, the movie shoud got to frame two via: nextFrame ();
It does it for going to frame 2 and 3 and 4 and 5 – but it always skips frame 6, and goes on to the last frame 7.
It makes no sense. So want to know how we can change it so that if each frame has a Frame Label, we can do the same process of moving from frame to frame ( one frame at a time).
All help welcome ! Thanks !!! :)
Jen, a flashthusiast says
If you see the error “The class or interface ‘MouseEvent’ could not be loaded” make sure your document is set to ActionScript 3.0 in publish settings.
webbedkitty says
Grrr, I’m new to Flash CS3 also, and I’m having difficulty with a flash banner template my client purchased. The flash file already has an action layer, i.e. falling dollar bills, and I have added the client logo, however, they want me to add a hotspot to be clicked and navigated to the clients home website, URL. Can I not have two actions layers?
Above the button (inv_btn) layer I made a separate actions layer. I put in the actionscript:
And I get an error:
What am I doing wrong?
Please help!
webbedkitty says
Thanks, Jen. I think I’m writing 3.0 script for 2.0, whoops!
Does anyone know of any good Flash CS3 beginner tutorials?
Thanks!
Dwayne says
Hey Jen, what a lovely site you have here, I am a web developer/ designer but now I think I maybe a flashthusiats.
I am creating a computer game its a grand theft auto type thing, could you point me in yo some directions in which i can gather assets for me game.
Thank you
p.s webbedkitty this is a good flash beginners site
http://www.squidoo.com/Flash_Tutorial_hitTest
Enjoy
Super Dwayne
David says
I’m having the exact same problem that Ruby did up above, that I’ll click a button, it’ll take me to another frame that has the same buttons on it but then the buttons no longer work. I’m assuming they should be buttons and not movie clips (?) I couldn’t quite understand what Ingrid did but if anyone can point out my errors, it would be SO apprecaited. Thanks.
Joe says
Well, i have a template and it is flash 8 running on as 2.0. I used the
When I test my movie and click the button I get a new internet explorer window with my site. This is all on flash cs3 but when i open the file on internet explorer or mozilla, when I click the button my new window doesn’t pop up (not because of pop up bloker). If I use the cs3 code you gave me, then all the other code in the rest of the template would need to be changed and I do not have a clue on how to.
Andrew says
Hi, I had same prob as Ruby but fixed with same mouseDownHandler number so thanks.
I have two button set up same as each other, but the second one when I test movie runs through its 4 states (up, over, down and hit) continuously like it can’t stop! Why would it do that but the first one doesn’t?
Andrew says
Just fixed it – made a new button set up exactly as previous one and it stops now. Damn Flash – why does it do that kind of thing?
Andrew says
Sorry another problem has come up. Button 1 goes to frame 2 (correct) then button 2 goes to frame 3 (correct) but if I press on button 1 again nothing happens. Shouldn’t it go back to frame 2 with this script?
David says
One other thing, I don’t know if this matters, but I was using gotoAndStop(10); on the MouseCLICK because if I used gotoAndPlay, it would cycle through to the end of the timeline. If I put a stop(); script on a different layer, it stays there, but the buttons still don’t work. Any help?
Matteo says
Hi, great work!
i’m using the code you’ve written in a flash intro, exactly for the button “skip intro” and it works well!
but is it possible to make the page open in the same window and not in a new one? where have i to modify the code?
many thanks!!!!
kipley says
Okay, I’ve spent hours on what used to be a 30-second task for me in AS2, and still no go. Any suggestions? I turned the word “Home” into a button, then changed the color for the Over and Down states, and then drew a rectangle for the hit area. Only problem is, every time I do this, only the hit area extending outside the text works. It’s almost like the text field masks the hit area. If I make a really big hit area, everywhere outside the text area works. But when I mouseover the text itself, the cursor doesn’t even recognize that it’s a button. What’s going on??? ANy help is much appreciated!
David says
In the button’s timeline, is the rectangle you drew in a layer above the button states? That should solve your problem.
pete says
If a button action said this before, what should it say now in CS3?
nat says
Hi Jen,
I am also very, very new to flash actionScript 3.0, and I needed to know how to set up buttons correctly, I could get one to work but the others weren’t – thank you such much for your info, and for everyone’s posts, I worked out what I was doing wrong (not numbering my event handlers!!) and now it’s all working a-ok. thanks so much!!!
I do have a different problem now, I’ve been searching the net for ages and just can’t find what I am after, I want to make my swf play/pause via one button and I am completely lost! – any help/thoughts would be v much appreciated!!
Sarah says
Hii .. im new to AC3 … i wanted to creat buttons .. each one of them goes to different frame.. my buttons are in one layer and the content in another one … anyways .. wut does this error mean ??
i created a rectangle converted to button and gave it an instance name and wrote this code
this is my code :
ben says
Your instructions are so easy to follow. Thank you so many sites out there that make it really hard to understand. You are a champion !
Ben
James says
Hi I am really new (just few days) to Flash CS3. I am using a script to make a sliding menu bar. However, I could not make the buttons to function. I have tried different ways in using your script.
a. made a new action layer on the movie scene and attached the button script
b. go to edit button mode, made a new action layer and attached the script
The output gave me this message:
The following is the script:
The sliding menu bar script works fine without the button function (I know this sounds silly.. a menu bar without button function). Million thanks for your help! Really appreciate it!
the_other says
CS3/AS3 is very different from version 4. I’m lot at this point and need some help.
I have a map with 50 buttons plotted on it. I would like for each individual buttons to launch either a new scene of another swf. I’ve given an instance name for each button “button_13” and “button_14” etc. How and where do I add these on the buttons?
Any help would be really appricated.
the_other says
I forgot to mention that when I try to add any scripting below stop(); it gives me error and plays all scenes continuously without stopping at the begining of each scene.
Parker says
Ok, I just started actionscript 3 and im making a website. the top of each frame has HOME ABOUT BLOG PORTFOLIO CONTACT buttons. so on each frame i put this (of course for each frame the buttons had diff. instance names)
cs3 says i can not repeat the same function. i saw that someone named chet made a comment like this earlier, but the answer to his problem didnt even change the code. please help!
Chris K says
Hey. My problem is that I have a movie clip in ‘Scene 1’. It has a button in it that needs to navigate to a frame label that is not within the movie clip, but within ‘Scene 1’.
I saw some suggested script that could solve it above:
However, my adaptation of it didn’t work for me. My button instance is ‘nextBtn1’, the frame label that it needs to direct to is ‘song menu 2’ and the movie clip is called ‘Songbook Menu 1’ if that is of any relevance. Any help is much appreciated!
Thanks
Michael says
I am experiencing the same problem as Andrew… when i click button 1 it takes me to frame 5 (correct), when I click button 2 it takes me to frame 16 (correct) but when I click on button 1 again, nothing happens. I have tried everything I can think of, double checked everything, and the actionscript looks correct:
Any suggestions on anything to try to fix this? Any thoughts are appreciated. Thanks!
goldie says
How do you create a back button in AS3? It all seems like common sense but it is killing me!! My next buttons and my home button both went smoothly.
Dave says
Ok so Im a first time user of Flash and Im trying to create a simple training program for some co-workers. Some simple buttons with some simple video clips. I was excited until I found out that I have to use code for button functions. Can anybody please tell if there is another way to use buttons with having to input code?
Dave says
Is there any way to create simple buttons with out inputing code?
Ezza says
I am creating a game on flash, but having trouble with trying to make a button move from one place to another. I tried using a tween but it wouldn’t move when I played it! All i want it to do is move up and down, but it wont work! All my frames have actions applied to them. Do I have to change the button to a graphic or a movie clip, and what actionscript will i need?
Delatoni says
>How to link in normally in actionscript 3.0.
*note: for “hacks_nav” you can put what ever you want in its place just make sure they are both the same.
*note: and on “hacks_btn” you just have to put the name of your button you are trying to link.
*note: and on “hacks” you can either use frame anchors like I did or you can use frame numbers. BUT if you use frames numbers just make sure you enter it like this (12) not like this (“12”).
*note: also if you want it to play instead of stop replace “gotoAndStop” with “gotoAndPlay” and it will start playing at that frame instead of going to and stoping.
—————————————————————————–
>How to link to fames on the main timeline from a button nested in a movie clip in action script 3.0.
*note: for “trail_nav” you can put what ever you want in its place just make sure they are both the same.
*note: and on “trail_btn” you just have to put the name of your button you are trying to link.
*note: and on “home” you can either use frame anchors like I did or you can use frame numbers. BUT if you use frames numbers just make sure you enter it like this (12) not like this (“12”).
*note: also if you want it to play instead of stop replace “gotoAndStop” with “gotoAndPlay” and it will start playing at that frame instead of going to and stoping.
—————————————————————————–
>How to make a movieclip dragable in actionscript 3.0.
*note: for “tabledrag” and “tabledrop” you can put what ever you want in its place just make sure they are both the same.
*note: and on “tableMC” you just have to put the name of your movie clip you are trying to make dragable.
Delatoni says
>Sorry also note that if you are linking from a button that nested in a movie clip that’s nested in another movie clip you have to alter the code to look like this.
*You are going to want to add another “parent” after MovieClip(parent.parent) like that.
——————————————————————————
>For a Transparent Background And Fullscreen Video’s
In Dreamweaver after you add your .swf file to your page click on the flash movie and in you properties panel look for “parameters” button and click on it and then type…
and then click ok and your done.
*note: or if you have a video in .swf that you want to have the fullscreen function work on it just enter this instead…
allowFullScreen = true
—————————————————————————–
Well that’s it I hope this help you guys. :)
Jose says
What is the function for making a “next” and “previous” button?
AChristi says
I need to have a code that works with my next and previous button.
I have a flash CS3 slideshow, but I want people to see wich button belongs to wich photo by making the button glow. How can I do this?
Jo says
My code is as follow for Action Script 2, I need to change it because I have realised that this relates to Action Script 3. Can someone please help me
The errors are The class or interface ‘MouseEvent’ could not be loaded.
Kevin says
Thank you for these clear and FUNCTIONAL explanations of how to to make a clickable banner. After hours of searching for the answer, I finally found it here. Again, thanks!!
Julie says
I was wondering if you could help. I used your code for a button I created in Flash. My button resides on an intro animation. I created a skip button so that when the user clicks on it, the user will go to the homepage. The only problem is that the intro continues to play in a different window then the homepage. The idea is that when the user clicks on the skip button, the intro stop and disappears and then a new window pops up with the homepage. Here is the code on the skip button.
Debbie says
Hi Jen
Great post. I am also a newbie to Flash and your tutorial came along at the right time.
But I also have to sound the “how do you get the link to open in the same tab/window” horn.
Please help.
Debbie says
Actually I have found the answer. For the record, the last line needs to read:
Add the _self after the URL and that works fine.
Sorry to intrude Jen. ;)
Josh says
Hello everyone,
I am trying to make revise my portfolio website in Flash CS3. However, things are not as easy as I would have hoped. For some reason when I ‘test movie’ my buttons all work as rollovers but once you click the ‘about’ button to go to the ‘about’ page you’re stuck there! Once you’re on a page I can’t click another button to go to any other page. Does anyone have any suggestions for this frustrated Flash user? Thank you!
Kohaku Hiita says
Hey. I have to be the worst person at understanding CS3…EVER…so I was wondeing if I could get some help. I am trying to make a flash movie with an opening scene that loops untill my button is clicked and it starts the movie. My problem is the button- I’ve tried using some coding from other posts and formatting them to work with my flash, but none of them have worked for some odd reason. Now I have nothing to work with. Can someone help? All would be appriciated. Thanks. :)
LOST in AS3 says
I am completly lost… I am trying to create a flip book with a foward button and reverse button foward that moves to the next frame and stops, the reverse moves to previous frame and stops.
I have 9 images on the image layer
then the button layer where on the first frame I have the buttons. I have named the instances I can (using this tut) get the frame to go foward one frame and back one frame using this code…
I am sooo lost can anyone HELP
R
josesenra says
hi Kohaku
maybe you should try this:
1 – the “loop” animation goes into a separate movieclip running on frame one (must have a stop there)
2 – place a button in frame one and write the following code on the frame’s actions panel (IMPORTANT!!! don’t select the button to write the code.. select the frame)
well… what have we got here?? simple actually… you got a movieclip on frame 1 that’s just there doing it’s thing… you got a button wating to be clicked and when it gets cicked it sends the main timeline to frame 2 and stop there, after stoping the movieclip on frame 1.
good luck ;)
josesenra says
hi Josh.. can you be more specific as what you mean by going to another page???
Laura G says
Hi Jen, I tried using your script for my button:
And I get: syntax error: extra characters found after end of program – which refers specifically to line of script starting with “english” – what am I doing wrong??
Jonathan Jason says
You People are using AS3 in a really primitive way specially for the use of multiple buttons writting function after function after function and the same with event handlers that’s to much work guys why not use the power of Arrays and Loops to assign one function to all your buttons?
let me explain
first off create all your buttons and there functionality I prefer to use MovieClips to make my buttons for the flexibility.
Give them simple names for example you can name them the same as the sections of let’s say a website like (home, aboutUs, contactUs) you will be surprised how much easier this makes things later when you can use the names of your buttons to do a lot of other things using AS3’s classes
Now create an Array with all your buttons names in it like so;
We will loop through the array later using a (for Loop) to access the buttons by the index number of the array.
Then write your on click, over and out functions and issue the instruction to the event target button instead of a particular button, this makes your function reusable and that is one of the biggest advantages of OOP languages like AS3. If this doesn’t make sense keep reading
Leave them blank for now!
now the For Loop this is where the magic happens !!!
Let me explain!
write a loop that uses a variable give it the name of a single letter I will use the letter (i) make it an integer and give it the value of 0, then compare that variable with the array’s length property by setting it less then the array.length property of the array class, and finally increase the variable by one by using the ++ method of AS3.
inside the loop we add the button functionality by assessing the button through the arrays index by using our loop variable to access it like so “btnArray[i]”,
and if you use MovieClips for your buttons 2 little bits of code to make them work like true buttons the buttonMode and the mouseChildren property’s of the MovieClip class they both get a Boolean value so there really easy to set.
now add your functionality to your functions if the buttons are going to do totally different things the use if and else if statements to assign the functionality if they are for navigation to a url then use the navigateToUrl property of the flash.net class and if it is for navigation in the flash file then go back to your flash file and at the beginning of each section put a frame label with the same name as the button that will navigate to that section then use the event.target.name property to go there like so;
I hope that was clear enough for the smart ones lol any how the complete code is a lot more clean and short the writing ten functions and ten event listeners here it is
Jonathan Jason says
Laura G
try it like this
you error was you didn’t put assign function to the event handler at the end of your line of code.
Jonathan Jason says
LOST in AS3 here is the code I think you need for your project when trying to flip from one frame to another you can use really simple math and the “Read Only” property of the MovieClip time line “currentFrame” and by using if statements you can loop from the first frame to the last with out running out of bounds.
Jonathan Jason says
Josh
take a look at where you placed your code it sounds like the code is in the wrong place
try putting it on a frame that can be read through out the whole movie
if that doesn’t work post your code so we can take a look at it.
Steve says
Why on earth would they make it more complex? You would think that they would make the code shorter or something instead of twice as LONG!
Laura G says
Jonathan – i got the same error message referring to the first line of script
James says
Help! I have created a Flash CS3 Home page. I have a preloader on Frame 1 of my Actions layer. I have a stop action on Frame 32. I have 7 rollover buttons that animate as the come into the page. If I test the movie, it plays and stops on Frame 32. Each button is on its own layer. Where in the heck do I add the scripts that I want to add a URL script to each button? I have tried several places. If I add it to Frame 32, after the “stop();” the movie just keeps looking instead of stopping. This is so much of a pain than AS2. Why can’t you add a script to a button directly? Any advice would be much appreciated. – James
eric says
What if you want to create a map and you have multiple buttons that you want to have the same behavior on them but don’t want them to do anything other than display a pop-up next to the object being used as a button?
Ana says
I need some help with more than one button on a page. One button works fine. When I add the script for two or more buttons, the flash movie just starts from the beginning again.
I did add a stop(); in the beginning, what am I missing?
Andrea says
I’m really new at this whole AS3 thing. I know how to make a button in AS1 & 2, but AS3 is not so easy. I used the code from above and also used a code to go directly to a scene (I’d prefer the latter)
This is my code:
This is the error message:
Alex says
I have imported a video(AVI) and I need it so when anywhere on the page is clicked it goes to another scene and frame. I have tried many things and none seem to work! if any one can help please let me know!!
Thanks in advance
Phil says
Hi I’m trying to do the simplest of things a simple button hyperlinked to another page everytime I do i get this error.
This is my code.
Any help will be appreciated thanks
marie says
hi. i was wondering if anyone can tell me how/ why a button with a rollover function within a movielip in the main timeline does not work?
thanks!
Cristina says
Thank you for this tutorial. I am a graphic designer not a programmer and it is been so frustrating to transfer between FLASH MX and FLASH CS3 it was a whole new monster. Your tutorial was so easy and understandable I think I can move on now and start playing with more stuff in flash thanks for all your help =)
Michael says
I have a question, I need help. What I want to do is make a button that when you click on it it opens a SMALLER pop up window, that doesn’t have a nav bar or anything.
Like when you’re shopping online and you click on a pair of pants and a pop up window pops up that has a larger image and description and price of the pants.
This is in AS3.
I understand how buttons work but I’m not sure of the code on this. Any help would be immensely appreciated.
Thanks
Rob Johnson says
Hi there.
I’m not overly new to Flash but I have created some buttons from text and the text appears with a box around it showing it as a button….BUT when I test the movie, the button only registers if the mouse is hovered over the text directly and has no hitbox around it. This has never happened before, any ideas?
thanks,
Rob
GABRIEL says
U R GREAT!!! THAT´S RIGHT!!! I HAVENT CLUE OF ACTIONSCRIPT 3.0…in fact, i speak spanish, so its double hard for me. but u……..yes u!!!!!!! i love you! hahaha
thanks a lot, for real!
HelpMe says
BUTTON DOESN’T WORK AFTER CLICKING TO NEXT FRAME
Hi
I have a problem with my button navigation. I would like my buttons to work after being clicked, but it seems that my buttons works fine but if I want to reclick them again they stop working. I have each frame name in instances and have my actions on a different layer. Also, they I have made sure that the instances are also copied and named. There are no errors but I do not know why it is not working. This is my code:
PLEASE HELP! Thanks!
HelpMe says
BUTTON DOESN’T WORK AFTER CLICKING TO NEXT FRAME
Hi There
I have a problem with my button navigation. I would like my buttons to work after being clicked, but it seems that my buttons works fine but if I want to reclick them again they stop working. I have each frame name in instances and have my actions on a different layer. Also, they I have made sure that the instances are also copied and named. There are no errors but I do not know why it is not working. This is my code:
PLEASE HELP! Thanks!
Skeet says
Hey guys,
I got my 4 buttons working by using if and elseif statements.
The below action script is added to layer 1 in the main scene. The buttons are added to layer 2 and there is a holding movie called main_mc which is added to layer 3 – within main_mc is where all the main website content goes, and what the ‘gotoAndPlay’ frame numbers refer to (remember to put the stop(); function at the frame within main_mc that you’ve told it to go to). The buttons will work every time you click on them :-
I understand why Adobe have made AS 3.0 like this but it is a pain is the arse to have to write code to do what was previously a very simple task!
Cheers,
Skeet
Eric Valdi says
Hi everyone – I am having trouble making a movie clip called SJH_1 invisible on the stage. The movie clip plays a short slide show as the page loads – but when a site visitor clicks on a button, a video plays and I want to hide the slide show movie clip.
When I test the movie, a compiler error appears stating that an undefined property (SJH_1) is being accessed. SJH_1 is on stage by the time the function is called (and of course it is in the library).
Does anyone know why Flash considers SJH_1 to be undefined?
And, is there a different/better way to remove something from the stage than setting visible to false?
Thanks for any help!
LepyTheDinosuar says
Hey everyone.
I don’t have a problem or anything, but I just wanted to know:
Why did they complicate AS?
I used to be able to click on a symbol, open the action panel, and write:
but now… I just don’t know.
Doug says
Any help with this code would be appreciated. I’m trying to get mouse to turn into crosshair and to have it work on a linked butoon. Each code works sepaerately but not together.
Dave says
So I understand the whole button deal in AS3. My question/concern is a bit different here. I’m trying to do the following –
Let’s say i have 2 buttons ( to make this simple) The buttons are movie clips, inside a movie clip and this MC is placed in the main timeline.
So the user hits button 1, this makes the main timeline go to and stop at frame 5 where a little animation of a menu unfolds and pops out. If the user hits button 2, it makes the main timeline go to frame ten and have a like MC play.
What i am trying to do here is this – let’s say i’ve hit button 1, im at frame 5, my little menu has popped out. I want to be able to hit button 2, have the movie in my current frame reverse and then proceed to the new frame designated by button 2.
I have the reverse animation built into the movie clips. I just need to figure out how to make button 2 tell the movie clip in the current frame (given there will be more than two buttons in the real project) to tell the MC to gotoAndPlay a frame and then when it gets to it’s last frame proceed to the new frame designated by button 2 in the main timeline.
Any ideas?
Anonymous says
EVERYONE MAKE SURE THAT FLASH KNOWS THAT IT IS LISTENING FOR AN EVENT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
place this code at the top of your actionscript:
Harry says
I have a button the same size as a banner ad I’ve created. I’ve used the following action script (borrowed from you).
when I test my movie I get this error in Flash player 8:
Harry says
Sorry…
The error is:
peterd says
Harry,
The code you’re using is ActionScript 3.0, which isn’t supported in Flash Player 8 (only Flash Player 9+).
Peter
Natalie says
I seem to have a problem with adding actionscript to a button…in previous version of flash i’d have no problem but with CS3 whenever I make or draw a button, it doesn’t allow me to add actionscript to it even though i have it selected. It says in the Actions window that the current selection cannot have actions applied to it. I have no idea what to do. any ideas?
Bianca says
I’m new at this and am having HUGE issues with making any of my buttons work. I’ve been trying to link my buttons to other web pages and my first issue is that when i do test movie, even though I have a stop(); at the last frame, the movie loops over and starts again once i add any coding into the actions layer. Also when i put the codes in,
i keep getting these errors –
carly says
i honestly don’t understand why mine isn’t working.
help!
that’s what i have
i copied exactly what you have, changed monkey_btn to btn1, and changed the url!
what’s going on!
Jen deHaan says
@Natalie: If you’re using the ActionScript 3.0 in this post, you need to add the AS to a frame instead of attaching it to a button. Give the button an instance name (select it and add the instance name in the Property inspector), and then add the code on a frame (select the frame instead of the instance and add the code in the Actions panel).
@Bianca: Make sure that you have added the instance name for the button.
@Carly: Do you see errors? If so, which ones? The code looks fine. Maybe make sure that you have ActionScript3.0 in your publish settings. Also make sure that there are no funky quotation marks or similar the code (after pasting from the web) – you might want to copy and paste from notepad, etc.
Jen deHaan says
Can you put your FLA somewhere for download so I can take a look? or send it to flashhelp (at) gmail
Bianca says
that is the instance name that i gave it.. am i using a wrong format for the instance name? in lynda.com thats how they explained an instance name could/should be. and also regarding your response for natalie’s, do you add the script to the frame that the button is on in the actions layer? and what if i have a tween for the button, do i add the script into the last frame that the tween is on? or the first?
sorry i have soooo many questions
Bianca says
I fixed the issue the with instance name, but I also put a stop action in so the page wouldnt loop over and its still looping over and over when i test movie. WHYYY?? i have the button set as anti-alias readability, what should it be instead?
also, im getting an error that says:
Bianca says
i just emailed the FLA i also have another question – hopefully this one is more simple.
im trying to import an external word file into a text field to make it scrollable. I made the file in word and added a .txt ending to it so actionscript can read it and when its saved it shows up as coding and after my coding is up i just shows a little bit of coding as the word file instead of the words. here is my actionscript – but i think the problem is moreso with my text-file…
Bianca says
..or is there a way to just copy/paste the text and have it dynamic and have it work that way? when i did that before.. it loaded but once I tried to scroll, the text disappeared… SORRY!! I know this is a lot of coding and stuff!
thanks
Bianca says
i figured out the txt… thank you though. i still need help with the web page linking.
Bianca says
actually… with the coding i left earlier.. the text i imported as an external file loaded properly now and in the SWF and HTML files, once i drag the scrollbar, the text scrolls, but I loaded the page onto the FTP server and when i hit the scroll bar button, the text disappears. I dont know if its something in the publishing settings, or in the coding… i also loaded the external txt file and the same thing happened.
HELP
Jen deHaan says
OK, so in the FLA file you want to put a double equals in your if statement (the second error in the Compiler Errors panel). Change
if( pEvent.target = younghottBtn )
toif( pEvent.target == younghottBtn )
and then the stop action and the button code should work as expected.Rob says
I’m trying to make a button link to a downloadable file, but right now I can’t even get it to link to another web page. Here is the code I have in the action bar for frame 158 (the last frame in the clip):
Now when I run the movie in test mode, I get this error message in the output bar (not the compiler errors bars)
What does this mean and how can I fix it?
Thanks.
Bianca says
OMG thank you thank you :)
Bianca says
sorry i keep bothering you… i tried copy/pasting that code and changing the names for the rest of the buttons I have on that page, but i keep getting these errors:
Peter deHaan says
Rob,
What is
vcflink1
? Are you creating it in ActionScript, or is it an instance on the Stage?My wild guess is that you’re creating it in ActionScript and have something like
var vcflink1:MovieClip;
but didn’t addvcflink1 = new MovieClip();
. Complete random guess, but the only thing I can think of based on the code snippet/error.Peter
Rob says
vcflink1 is the instance the button on the stage.
Rob says
Okay, I got it to work (though I’m not sure how exactly), but I added on some frames at the end of the clip and moved up the keyframe on the action layer, so perhaps that was it. Either way, thanks for all the useful info on your site here.
Jen deHaan says
@Rob: Glad you got it to work :)
@Bianca, you need to have different function names for each button (you may be able to simplify your code too) – check out this entry for some code you can use and an explaination: http://flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/
Uday says
Hi All,
Any one can convert the following AS 2.0 code into AS 3.0?
btnDisplay.onPress = function(){
trace(“start Show”);
}
// I am calling the action of btnDisplay by another button…
btnShow.onPress = function(){
btnDisplay();
}
I need the same functionality in AS 3.0. so please any one can tell me predifined buttton’s action from other action
Thanks,
Uday
laloka says
Hi_going crazy with AS3, pretty sure I’ve done everything you guys recommend, but this is my problem:
I want 2 simple text buttons to take me to 2 different urls and another simple image button to have a mailto link.
I can make 1 button work, no problem but as soon as I add scripting functionality for the other 2 the first one stops working and the rest don’t work either. I have tried adding numbers after the mousehandlers and am sure my instance names are correct.
Is this a mac safari/firefox issue? Is there a workaround?? Here is the code and I will email you the fla file just in case you can give me a hand. Any help super appreciated!
eng_bot.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.yogamountainyogasea.com/index.html”));
}
esp_bot.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.yogamountainyogasea.com/esp/index.html”));
}
laloka says
oh…sorted it out– i wasn’t naming instances on the stage but on the TIMELINE! duh!
Lisa says
I’m a super newbie to Flash CS3. I have imported a graphic into Flash, converted it to a button symbol, but when i click on the button in the stage, it says “Current selection cannot have actions applied to it’.
I have imported both a gif and jpg. I have clicked on the button itself and gotten the ‘up,over,down,hit’ frames, but still cannot apply any scripting. The nav bar I’m trying animate has a left arrow, #’s 1,2,3 and a right arrow. My intent is to have the numbers go to a specific graphic. For the arrows I want them to go to the previous graphic (if user is on #2, and clicks on the arrow, he should see #1.
Any help would be MUCH APPRECIATED!
Lisa
Calvin says
Hi! I just started working with CS4 pro, AND I HAVE NO IDEA HOW TO MAKE THE BUTTON GO TO THE NEXT FRAME!!!!!!!!!! Please help because I aslo need It to stop at all frames.
Michael Horne says
Thanks for helping me to get this work – it was driving two of us in our office up the wall.
btnSpecialOffers.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.microsoft.com”)}
Squidge says
Hey,
I’m making an animation, and it was working fine until I put a movie clip on one of the frames. When I tested the movie, the button went back a few frames instead of going to the next one. It worked fine before, but now I can’t fix it. Can anyone help?
This is what it says in the output when you get to the frame:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame12()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler10()
Thanks
sPlatterKep says
Hello,
I nearly have this, could use a nudge! Using suggestions from Skeet (11/6), as well as Jonathan Jason (8/15) I have the following code, which works great, except that in the MC containing the content, when it goes to the frame it’s supposed to, when clicking the same button makes it jump to the next frame, as though the btnName value is lost,
-btns are on a layer in scene 1
-AS is too
-mc with content is too
-stops(); are in the MC where needed
AS from scene 1, frame 1:
stop();
home_btn.addEventListener(MouseEvent.CLICK, navigate);
about_btn.addEventListener(MouseEvent.CLICK, navigate);
map_btn.addEventListener(MouseEvent.CLICK, navigate);
donate_btn.addEventListener(MouseEvent.CLICK, navigate);
function navigate(event:MouseEvent):void
{
var btnName = “”;// creates an empty variable to hold the button/label name
btnName = event.target.name;// grabs the name of the button
main_mc.gotoAndPlay(btnName); // applies the name of the button as the gotoAndPlay target
}
eD sOLO says
stop();
import flash.events.MouseEvent;
button1.addEventListener(MouseEvent.CLICK,
rMOVE);
function rMOVE(event:MouseEvent):void{
gotoAndStop(2);
}
i get a message saying 1120:Access of undefined property button1.
i dont know what im supposed to do to define the property of the button – or even what that means!
please help
sPlatterKep says
FYI: I think I got it working, changed the line to read:
main_mc.gotoAndStop(btnName); // applies the name of the button as the gotoAndStop target
Thanks for all the ideas, etc. on this page!
Smory55 says
enter_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent): void {
navigateToURL(new URLRequest(“http://www.tadreebhr.com/”));
}
it didn’t work for me I got an error massage
Nadi Z says
Hi Jen,
How do I link my buttons to another .html page within my own website? I tried the URLRequest function and it works, but the web browser opens up a new tab every time you click a button in the navigation bar! I don’t want that. Help!!!!
JoeG says
Hey Some Great Tips here, I was wandering if you could help an amateur like me!? I have a button in my script that when clicked will display the contents of a text file :
/*
var req:URLRequest = new URLRequest (“content.txt”);
var loader:URLLoader = new URLLoader();
function clickMouse(event:MouseEvent ):void
{
text_btn.addEventListener(MouseEvent.CLICK,fileLoaded);
}
function fileLoaded(event:Event):void
{
content_txt.text = loader.data;
}
loader.addEventListener(Event.COMPLETE, fileLoaded);
loader.load(req);
*/
However when this is uncommented and run, the text is already loaded, without the button having been pressed? What silly oversight have I made.
Kind Regards,
Joe
SiuMing says
To make this open the link in the same window, here’s the code:
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.flashthusiast.com/”), “_self”);
}
Sahafi says
I’m trying to work with CS3 after working with Flash 8 and am trying to get 5 buttons to navigate to different frames. Although I am not getting any errors but it still isn’t working.
I tried two things so far and in both attempts only my bio button navigates. help please
attempt #1
stop();
import flash.events.MouseEvent;
homebtn.addEventListener(MouseEvent.CLICK, powerClick);
function powerClick1(event:MouseEvent):void {
gotoAndStop(1);
}
biobtn.addEventListener(MouseEvent.CLICK, powerClick);
function powerClick(event:MouseEvent):void {
gotoAndStop(2);
}
designbtn.addEventListener(MouseEvent.CLICK, powerClick);
function powerClick3(event:MouseEvent):void {
gotoAndStop(3);
}
photobtn.addEventListener(MouseEvent.CLICK, powerClick);
function powerClick4(event:MouseEvent):void {
gotoAndStop(4);
}
videobtn.addEventListener(MouseEvent.CLICK, powerClick);
function powerClick5(event:MouseEvent):void {
gotoAndStop(5);
}
Attempt 2:
stop();
import flash.events.MouseEvent;
homebtn.addEventListener(MouseEvent.CLICK, oneClick);
function oneClick(event:MouseEvent):void {
gotoAndStop(1);
}
biobtn.addEventListener(MouseEvent.CLICK, twoClick);
function twoClick(event:MouseEvent):void {
gotoAndStop(2);
}
designbtn.addEventListener(MouseEvent.CLICK, threeClick);
function threeClick(event:MouseEvent):void {
gotoAndStop(3);
}
photobtn.addEventListener(MouseEvent.CLICK, fourClick);
function fourClick(event:MouseEvent):void {
gotoAndStop(4);
}
videobtn.addEventListener(MouseEvent.CLICK, fiveClick);
function fiveClick(event:MouseEvent):void {
gotoAndStop(5);
}
tavi says
ummm…i tried what everyone said but then it said this
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/frame1()
what does that mean?
Michael Parker says
Thanks for the great tutorial – Flash CS4 takes a little while to get used to.
Muhammad Kashif Nayab says
Hi all
I’m trying to create links/buttons in Flash CS3 with ActionScript 3.0.
It’s working fine when there is only one link/button, code reference below:
myButton.addEventListener(MouseEvent.CLICK, MouseDownHandler);
function MouseDownHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest(“URL”), “_self”);
}
But when I try multiple links/buttons I keep getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Here is the code reference:
DealOne.addEventListener(MouseEvent.CLICK, onClickDealOne);
DealTwo.addEventListener(MouseEvent.CLICK, onClickDealTwo);
DealThree.addEventListener(MouseEvent.CLICK, onClickDealThree);
DealFour.addEventListener(MouseEvent.CLICK, onClickDealFour);
DealFive.addEventListener(MouseEvent.CLICK, onClickDealFive);
function onClickDealOne(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.tuttibambini.co.uk/index.php?main_page=product_info&cPath=&products_id=461”), “_self”);
}
function onClickDealTwo(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.tuttibambini.co.uk/index.php?main_page=product_info&cPath=&products_id=462”), “_self”);
}
function onClickDealThree(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.tuttibambini.co.uk/index.php?main_page=product_info&cPath=&products_id=463”), “_self”);
}
function onClickDealFour(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.tuttibambini.co.uk/index.php?main_page=product_info&cPath=&products_id=464”), “_self”);
}
function onClickDealFive(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.tuttibambini.co.uk/index.php?main_page=product_info&cPath=&products_id=465”), “_self”);
}
I try but I can’t figure out what that is…
Any help is always appreciated.
Thanks with Best Regards,
Muhammad Kashif Nayab Uddin
Janders says
I am teaching students how to create a puzzle game. I am worried that if there are going to be 30 puzzle pieces, that there will be A LOT of code in order to get each piece drag-able. Each piece is going to be a button. I have one piece that I can drag and I see from this site that I need a new function name for each new button. Is there a more efficient way of programming 30 different buttons that are each click and drag-able?
Thanks!
square_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDOWN);
function mouseDOWN(event:MouseEvent):void {
startDrag();
}
square_btn.addEventListener(MouseEvent.MOUSE_UP,mouseUP);
function mouseUP(event:MouseEvent):void {
stopDrag();
}
Wojo says
I have a menu problem i have this script on frame 1 of my timeline in an actions layer. The first script pans out to frame 30 where everything on the timeline ends. Script works perfectly.
function gotoHome(evt:Event):void {
gotoAndStop(“home”);
}
function gotoPartsandrims(evt:Event):void {
gotoAndStop(“rims”);
//<—- I am trying to get this menu to jump to frame 31 of my //timeline to goto the other menu.
}
function gotoGallery(evt:Event):void {
gotoAndStop(“gallery”);
}
function gotoLocation(evt:Event):void {
gotoAndStop(“location”);
}
function gotoContact(evt:Event):void {
gotoAndStop(“contact”);
}
function gotoStorehours(evt:Event):void {
gotoAndStop(“storehours”);
}
home_btn.addEventListener(“click”,gotoHome);
partsandrims_btn.addEventListener(“click”,gotoPartsandrims);
gallery_btn.addEventListener(“click”,gotoGallery);
location_btn.addEventListener(“click”,gotoLocation);
contact_btn.addEventListener(“click”,gotoContact);
storehours_btn.addEventListener(“click”,gotoStorehours);
then on frame 31 of the time line i have a similar script for another set of buttons.
function gotoRims(evt:Event):void {
gotoAndStop(“rims”);
}
function gotoTires(evt:Event):void {
gotoAndStop(“tires”);
}
function gotoLighting(evt:Event):void {
gotoAndStop(“lighting”);
}
function gotoInterior(evt:Event):void {
gotoAndStop(“interior”);
}
function gotoExterior(evt:Event):void {
gotoAndStop(“exterior”);
}
function gotoPerformance(evt:Event):void {
gotoAndStop(“performance”);
}
rims_btn.addEventListener(“click”,gotoRims);
tires_btn.addEventListener(“click”,gotoTires);
lighting_btn.addEventListener(“click”,gotoLighting);
interior_btn.addEventListener(“click”,gotoInterior);
exterior_btn.addEventListener(“click”,gotoExterior);
performance_btn.addEventListener(“click”,gotoPerformance);
This script works fine as well. Although when i run the whole time line the two scripts dont work with each other.
i get the following error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FocusMainPageTemplate_fla::MainTimeline/frame31()
at flash.display::MovieClip/gotoAndStop()
at FocusMainPageTemplate_fla::MainTimeline/gotoPartsandrims()
I could use all the help i could get i am just a beginer i dont understand why it is doing it due to probably lack of knowledge. I have many books and i cannot find an answer.
Aditya M P says
Thanks a lot for the great tutorial… :)
Aditya M P says
And @k:
He has explained about the “Duplicate function error” in the first few comments, lazy ass, just check them out!
k says
hi im just a beginner at flash and seem to be having some trouble. i had followed the steps exactly and when i come to test the button i get error 1021: Duplicate function definition.
could you help in this
thanks
Cyprian says
Hi Guys, hope someone can help. I have a simple banner made in F CS3 and the website where i want to upload it to requested to add button which i did and then add:
on (release)
{
getURL(_level0.Tag,”_blank”);
}
Unfortunately after adding this scrip the movie starts looping although it has stop(); in the top layer.
My questions are: how to make this clickTag work and stop the movie from looping?
Any help would be appreciated
sandra says
hi there,
I’m just trying to do simple buttons with the following code:
stop();
bplay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function startBall(event:MouseEvent):void
{
gotoAndPlay(2);
}
but it just wont work..
1120: Access of undefined property bplay.
1120: Access of undefined property mouseDownHandler.
why this is appening?
tanks
Wednesday says
The code supplied to open the URL in the same window (rather than new window all the time which looks messy) doesn’t seem to be working???
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.flashthusiast.com/”), “_self”);
}
I have my buttons working but added the “_self”); and got an error message? Any help much appreciated as this is really bugging me now! :)
16 Buttons says
I’m working with an interactive map graphic in Flash CS3. I want to create 16 buttons that will react when the mouse moves over the hit area. I’ve got that part working. But I need help with the action script to load an external text file. I want each button to trigger dynamic text to display in a popup. Can I use one text file for the whole project? Or do I need 16 diff txt files, one for each button? Can you help?
Ana says
I am new to Flash so this is a simple one for you – but not so much for me: I just need my button to link to URL which would open in a new window. How do I do that?
Holly says
How do i link my button to another webpage that i have made on flash?
Ryan says
I am having trouble making a button link to the next frame. I am getting this #1009 error message ” TypeError: Error #1009: Cannot access a property or method of a null object reference.
at website3_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at website3_fla::MainTimeline/enterSite()”
this is my code for moving from the first frame to the second:
stop();
import flash.events.MouseEvent;
button.addEventListener(MouseEvent.CLICK, enterSite);
function enterSite(event:MouseEvent):void {
gotoAndStop(2);
}
Any reason why that shouldn’t work?
Thanks a lot
Colin Santos says
This totally worked. Your tutorial rocked my face. Thanks with every fibre of my being.
Angela Bittner says
Hi I’m new to flash and CS3 I’m working on a flash project and my scene has three buttons which are presents the viewer should be able to click on each present which then takes the viewer to the next scene which its not doing right now. Then when should be at the next scene the are two more buttons which is suppose to allow the view to click on and take them back to the beginning of the first scene which is the intro of the movie which I put the timeline location and then the second button takes the viewer back to another location on the timeline.
My five scenes are Intro, birthday, firetruck, bulldozer, and dog. I am trying to get one button to go from the dog scene to the Intro scene and the other button to go from the dog scene to the birthday scene.
Here is the error message I’m receiving:
ArgumentError: Error #2109: Frame label Intro not found in scene Dog.
at flash.display::MovieClip/gotoAndStop()
at final_project_2_Dog_fla::MainTimeline/boneClick11()
Here is my actionscript code:
stop();bone.addEventListener(MouseEvent.CLICK, boneClick11);function boneClick11(event:MouseEvent):void {
gotoAndStop(“Intro”);
}
stop();dogbowl.addEventListener(MouseEvent.CLICK, dogbowlClick12);function dogbowlClick12(event:MouseEvent):void {
gotoAndStop(“birthdayscene”);
}
Any suggestions would be greatly appreciated.
Justin Putney says
Angela,
The format of the gotoAndStop command reads like this:
gotoAndStop(frame, scene);
The first parameter is the frame. So
gotoAndStop(”Intro”);
will look in the current scene for a frame labeled “Intro”.
Your code should probably look like this:
gotoAndStop(1, ”Intro”);
That will send you to the first frame of the “Intro” scene.
ben says
hi — just wanted to say THANKS! been trying to get my head around AS3 all morning and just about to give up and go back to 2 then found this page, excellent!!!
Thank you thank you thank you!
Bryan says
I am trying to get three buttons to work. I have defined all three buttons and they states work.
I wrote scripts for each button with the unique instances and unique function names.
stop();
b_treks.addEventListener(MouseEvent.MOUSE_DOWN, treksDownHandler);
function treksDownHandler(event:MouseEvent):void {
gotoAndStop(35, “Scene 1″);
}
b_tours.addEventListener(MouseEvent.MOUSE_DOWN, toursDownHandler);
function toursDownHandler(event:MouseEvent):void {
gotoAndStop(60, “Scene 1″);
}
b_cruises.addEventListener(MouseEvent.MOUSE_DOWN, cruisesDownHandler);
function cruisesDownHandler(event:MouseEvent):void {
gotoAndStop(60, “Scene 1″);
}
But, I am getting the following error messages:
1120: Access of undefined property b_treks.
1120: Access of undefined property b_tours.
1120: Access of undefined property b_cruises.
What am I doing wrong?
Bryan says
Is anyone listening?
lehoa says
You are amazing! Thanks for helping all us newbies to AS!!!!
Drachorn says
This worked great!! Thanks so much!!! ^_^
karrem says
btn1.onRelease = function() {
getURL(“E:desktopDocumentsUnnamed Site 2home page.html”);
};
i want to load HTML file from my disk in flash cs3
can any one help me plzz
Steve says
how could I add a simple text on mouse_over that says Click for Model Gallery them on MoUSE_out the text goes away
would I use the gotoAndstop on a different frame or is there a command that let me do it over the button
thank you
AA says
Just wanted to say thank you! Reading through the comments has helped me to figure out the tasks I needed to accomplish in my current project. It is so nice to see answers to the questions in the comments b/c so many are the exact same ones I had.
Some guy says
Err, could you explain to me how to make a button that just moves on to the next frame?
Dee says
Hello. I tried using one of the codes above. But my second button won’t work.
Here’s my action script
stop();
button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(2);
}
button3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndPlay(93);
}
and on my output I have an error that says
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at myprojectname_fla::MainTimeline/frame1()
my first button works perfectly fine. But my second button deos not go to frame 93.
Help?
Bryan Amburgey says
Error #2109: Frame label bio not found in scene Scene 1
This is the code:
//handle events for buttons…
bio.addEventListener(MouseEvent.CLICK, clickSection);
function clickSection(evtObj:MouseEvent) {
//trace shows whats happening..
trace (“The bio button was clicked”)
gotoAndStop(“bio”);
I am copying and pasting my initial working code and I continue to get this error. With some buttons it works, with others it does not.
Thanks for your help.
Marcia says
Hello all:
I am having a REALLY hard time figuring out how to get buttons on my (masked) roll-down menu to function (URLRequest). I can only seem to get the buttons to go to the URL if I move the roll-down layer up a few levels above the mask. Of course, then I now longer have a masked roll-down. I have spun and spun my wheels on this and I can’t find ANY solutions. Can anyone help on this?? I will be eternally greatful :))
K says
Hi. I am working on a project. There are six buttons in it. I have all of them working except the exit button. I can not figure out the right code. Does anybody know how I can do this?
Reikko says
Hi. I am an avid fan of flash really, though am newbie, i still know the basic fundamentals in flash but when it comes to scripting, I suck…
I am creating a slideshow with 5 pictures (or 5 scenes) and at least 6 seconds before it’ll change into the next pic.. I have tried to create a next button that will act as a skip if viewers dont wanna wait for few seconds to view the next pic. What code shall i use??
I saw this kind of slides in yahoo… last year i guess. And I really love it.. Can somebody please help me?? pls….
T says
I need to get buttons to increase or decrease a score. Any ideas?
LEe says
Hi all I am working on my code and are looking to set a height and width command on the open urls dose anyone have an example of this I can use?
Tom says
Am trying to allow for 4 buttons in one flash file to link to separate URLs and have them come up within in the same window. The current action script that I thought was right only allows for the banners to open just the first url for all of them and when I try to add _self nothing works.
——————————-
stop();
button1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://169.254.87.7/joomla/index.php/pc/california-region-news”));
}
button2.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://169.254.87.7/joomla/index.php/pc/mid-atlantic?start=2”));
}
button3.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler3(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://169.254.87.7/joomla/index.php/nonprofit”));
}
banner1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler4(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://169.254.87.7/joomla/index.php/liquor”));
}
alina12 says
thanks i didi it and it worked with me
but i need the the link open in the same page how the script will looks like
Erin says
I’m trying to create a simple image viewer, where the next button advances to the next frame of the timeline and the back button advances to the previous frame. How do I write AS3 to go to the next or previous frames, when this is a variable event? i.e., I can’t tell it to just go to frame 2… it needs to be something like x+1 or x-1. Here is the code I have so far:
stop();
function imgAdvance(event:MouseEvent):void {
gotoAndStop(2);
}
nextbtn.addEventListener(MouseEvent.CLICK, imgAdvance);
function imgRewind(event:MouseEvent):void {
gotoAndStop(1);
}
backbtn.addEventListener(MouseEvent.CLICK, imgRewind);
Mike says
I have been messing and researching this for over a week and I’m finally going to ask for help. I have a series of buttons for a nav bar. They each work fine when coded like this:
newsbtn.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest(“News.html”));
}
The problem is that I don’t want the pages to open in a new window. If I add the , “_self” target the buttons don’t work at all. Please help I need to get this sight up and running soon.
FlashSpec says
Mike, try this:
Parameters request:URLRequest — A URLRequest object that specifies the URL to navigate to.
window:String (default = null) — The browser window or HTML frame in which to display the document indicated by the request parameter. You can enter the name of a specific window or use one of the following values:
“_self” specifies the current frame in the current window.
“_blank” specifies a new window.
“_parent” specifies the parent of the current frame.
“_top” specifies the top-level frame in the current window.
Here’s some flash of mine: http://bit.ly/CtVgv – http://bit.ly/10Th0S
Mike says
I tried it your way and yes it is working. The problem is that once I insert it into my page it doesn’t work. As a stand alone button it works and opens the page just fine but loaded into the site being built in Dreamweaver it doesn’t work at all.
PragmaticStatistic says
I am new to Flash CS4 and am having problems with stop and goto button functions. I added the following code:
stop();
DurabilityBtn.addEventListener(MouseEvent.CLICK, buttonClickHandler1);
function buttonClickHandler1(event:MouseEvent):void {
gotoAndPlay(2);
}
PerformanceBtn.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
function buttonClickHandler2(event:MouseEvent):void {
gotoAndStop(3);
}
If I use Actionscript 2 publsih settings the movie stops but function lines won’t load. If I use ActionScript 3 publish settings the movie won’t stop and I get the same won’t load function statements.
What am I doing wrong? Please help!
Chris Bolton says
After literally searching for hours on the web re how to do this. Yours was the only solution I found that work. Thanks.
parisa afshin says
thanks for sharing that Jen, great job! just what i was looking for : )
Layn says
Thanks for the awesome tutorial ! It helped, until the part where ihave to change the code. I’m a starter and I have NO idea what code you could possibly mean. Should I use the name of my button or something ?
Also, the way you named things, like “monkey”, made me confused, do I have to keep it or is it just fine to use exactly that what you wrote ?
I’m sorry if someone asked you this before, but I didn’t have enough time to look through all of those reply’s/
Thanks for your time :)
Snap says
Need help with startDrag(true); on a MovieClip with mask inside it.
code:
N7.x=newX;
N7.y=newY;
N7.addEventListener(MouseEvent.MOUSE_DOWN, drag);
N7.addEventListener(MouseEvent.MOUSE_UP, drop);
// M7.MovieClip.mask(true);
function drag(event:MouseEvent):void {
event.target.startDrag(true);
}
function drop(event:MouseEvent):void {
event.target.stopDrag();
}
The problem seem to be that N7 is an instance of a MovieClip that contains a single frame, of two layers (one image and one shape that create a mask), if I only use the shape it is fine, but as soon as I use the mask function inside the N7 movieclip it give the error:
ReferenceError: Error #1069: Property startDrag not found on flash.display.SimpleButton and there is no default value.
at circle09_004a_fla::MainTimeline/drag()
I have searched everywhere, but can not find a way to make the drag function worked with a ‘masked’ bitmap inside a MovieClip. hope someone can help.
Gü Bosch says
THX for the awesome tutorial. It helped a lot.
Berko says
Why, oh why have they change this?! I was till now working in older version of flash with AS 2, and that method was in my opinion much better then this one; you have one button with script, and if you copy it, you have also copy that script with it, and then you just have to change some values in script and that new button had different function. Now you have to rename each button, and create separate script for each, and the dumbest thing is fact that you CANT PUT SCRIPTS ON BUTTONS!!! STUPID, STUPID, STUPID!!!
I think that I will delete this stupidity and return to old Flash….. Adobe, you have manage to ruin perfectly good software!
Michael says
Great tutorial, but I’m wondering how to do this: I’ve created a movieclip inside of which is my menu, and inside of my menu are my buttons – my question is this. How do I get the buttons inside of the menu to link to frames in my original scene?
oliver says
I’m working with this code
stop();
reel_btn.addEventListener.(MouseEvent.CLICK, onReelClick);
samples_btn.addEventListener.(MouseEvent.CLICK, onSamplesClick);
about_btn.addEventListener.(MouseEvent.CLICK, onAboutClick);
contact_btn.addEventListener.(MouseEvent.CLICK, onContactClick);
function onReelClick(e:MouseEvent):void
{
gotoAndStop(“reel”);
}
function onSamplesClick(e:MouseEvent):void
{
gotoAndStop(“samples”);
}
function onAboutClick(e:MouseEvent):void
{
gotoAndStop(“about”);
}
function onContactClick(e:MouseEvent):void
{
gotoAndStop(“contact”);
}
Whenever I run the SWF no error messages come up, but the buttons do nothing when click, everything else works fine, whats going on here can anyone help?
Mark says
Hello Jen- I love your button script here:
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.flashthusiast.com/”));
}
but how do I set a target to be “_self”? As it is, this only opens a new window. I want to remain in my same window/tab. Any ideas? Thanks, Mark
Jen deHaan says
Hi Mark,
Try something like this:
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbUpHandler);
function thumbUpHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.adobe.com”), “_self”);
}
Does that help?
Jen.
Jen deHaan says
Also, make sure that you check the quotation marks and replace them in the script editor with fresh ones – sometimes copying and pasting from the interwebs adds funky quote marks which can lead to errors.
Mark says
How do you get the CS3 script to target a particular window? It seems the default is to open a new window, but I want it to remain in the same. If I add: , “_self” I get an error.
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.flashthusiast.com/”));
}
Mark says
sorry for the double post! I thought my original one didn’t post yesterday. :(
Elfriede Kruger says
I’m struggling to make a simple animation in flash where I have to switch between scene 1 and scene 2 by the use of a button. Thus when I click on button in Scene 1 it must redirect me to Scene 2. What is the actionscript for this simple task.
Matty P says
I’m using the code:
function gotoOrderPage(event:MouseEvent):void {
var targetURL:URLRequest = new URLRequest(“order.html”);
navigateToURL(targetURL);
}
order_btn.addEventListener(MouseEvent.CLICK, gotoOrderPage);
I want to get my order page to open in the same tab. what should I do?
Jen deHaan says
@MattyP: Check the code in the comment 3 entries above – you can target windows using that format. (I think I need to do a separate entry on this one!)
@Elfriede: Linking to different scenes is covered in this blog entry here: http://flashthusiast.com/2008/07/31/creating-buttons-that-link-to-different-scenes-using-actionscript-30 There is also a FLA available for download that does that very task.
SlamerX says
Hi, i´m trying to close a movieclip and go to movieclip that i wan´t but how can i close a movieclip with code in as3.
my code is:
stop();
closestaff.addEventListener(MouseEvent.CLICK,clickSection);
function clickSection(evtObj:MouseEvent) {
//trace shows what’s happening.. in the output window
trace(“The “+evtObj.target.name+” button was clicked!”);
gotoAndStop(evtObj.target.portfolio_mc);
}
……..
i´m using name directly in teh but instance that work perfect but teh code to close i don´t know.
Adrian says
10X A LOT, MAN!!!
Sam says
Hey chaps, I’m trying to make a basic small video play from a flash button. All I’m trying to do is have the video (“psp”) play when I click my button. I’m such a newb I know, but this is driving me nuts! Any help would be appreciated!
ana says
Great help, but i ran into a problem when i went to publish my document, the publish document sends me an error and doesnt send me to my page even though when i played the movie it did work, am i doing something wrong when i publish the file or is there something im missing?
theodoros says
hello,
i want to make a link button but open in the same window. this code open in a different window. what can i do?
thanks!
Legun says
Is there a way on a mouseover on a button to change the background image of the scene and also have a hyperlink if a user clciks on the button?
Jen deHaan says
@ana: What error does it say?
@ theodoros: Please see this post about that topic: http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
@Legun: You could add a mouseover event which targets a movie clip that makes up the background (simplest way could be to gotoAndPlay a new frame that contains the new image, or you could load it).
@Bobby: For ActionScript 3.0, you need to have the code on a frame instead of attaching it right to the instance (you presently have the instance selected instead of a frame). Select a frame on the timeline, then you’ll be able to add your code in the Actions panel.
Bobby says
I’m new to flash and having trouble picking the coding side of things. When I make symbols I end up not being to apply
code as it says “current selection can’t have actions applied to it”
any idea what it going on?
JPunisher says
I don’t know much about AS3, but this really help me with the loop problem. Make sure you give your button an instance name! When you select it go to properties and then name it in the instance name block… Just thought it would help people in my predicament ;-D
Gresh says
I am a newbie. This stops my sound:
layer actions (frame 1):
stoper.addEventListener(MouseEvent.CLICK, stopMusic);
function stopMusic(e: Event) {
SoundMixer.stopAll();
}
but how am I to restart the sound from the place I stopped it?
I want to stop and start the animation as well as sound and I have two buttons: startBtn and stopBtn named starter and stoper.
Could somebody pleaeaease help!
Rodrigo says
My problem is that#
/*import flash.event.MouseEvent;
import fl.controls.Button;*/
import fl.transitions.Tween;
import fl.transitions.*;
menu_bloque.x = home_bt.x;
underline_mc.x = home_bt.x;
products_bt.addEventListener(MouseEvent.ROLL_OVER,moveUnderline);
function moveUnderline(event:MouseEvent):void
{
underline_mc.x = event.currentTarget.x;
/*new Tween(underline_mc,”x”,Strong.easeOut,underline_mc.x,e.currentTarget.x,12,false);*/
}
and I have this
The class or interface ‘MouseEvent’ could not be loaded.
help mi please
function moveUnderline(event:MouseEvent):void
Alexander says
Hi I am designing a flash cs3 website and I want to include an intro that ends with buttons that will lead to the different pages (frames like home, about us, contact…) of the document. How do I write the actionscript for the buttons to lead to the various labelled frames in Scene 1, since the buttons are in the intro movie symbol? The code I tried is below, nothing happens after I click it.
stop()
Home2.addEventListener(MouseEvent.CLICK, clickHome2);
function clickHome2(event:Event):void {
trace(“home”);
gotoAndStop(“Home”);
}
Aboutus2.addEventListener(MouseEvent.CLICK, clickAboutus2);
function clickAboutus2(event:Event):void {
trace(“Aboutus”);
gotoAndStop(“Aboutus”);
}
Membership2.addEventListener(MouseEvent.CLICK, clickMembership2);
function clickMembership2(event:Event):void {
trace(“Membership”);
gotoAndStop(“Membership”);
}
Jen deHaan says
@Rodrigo: It sounds like your document is set to ActionScript 2.0 – try changing it to ActionScript 3.0 and you shouldn’t see that error.
@Alexander: For information on targeting different scenes, see this post: http://flashthusiast.com/2008/07/31/creating-buttons-that-link-to-different-scenes-using-actionscript-30/ (there’s a FLA file linked there too).
Jen deHaan says
@Ruth: The first thing to check is if you have an instance name on the button (perhaps you named the button symbol when you created it but not the instance that’s on the Stage?) That’s the error one would see when there’s a problem with the instance name.
Make sure when you select the button on the Stage, that the text box in the Property inspector (Window > Properties) says bu1.
Hope that helps,
Jen.
ruth says
Hi,
I followed the instructions you laid out (or at least i think i did), and the button shows up fine, but when I click on it, the website doesnt actually pop up and it gives me an error. I named the button bu1 and changed the code so that it’s acting on bu1, but it still says this: “access of undefined property bu1” and it says the error is occuring in this line: bu1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
any idea what im doing wrong? I’m super new at this, so please explain to me in as plain english as possible.
please help me!! thanks!
ruth says
thanks jen! it worked!
and for the speedy response… it normally takes me days to get answers online
Juan Pablo says
hey there…
I am running into a little problem.
You see my buttons are inside a movie clip or navigation bar.
Somehow I am getting the following error message and I cannot seem to be able to fix it…
Alas the error message!
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Index3_fla::MainTimeline/frame 1()
What do you recommend I do to fix it?
Good site, it’s taught me a lot throughout my flash career.
JP
stephen gonzales says
Hello,
I’m new to cs3 and I am attempting my first full website in flash. I’m at the point of buttons and navigating within the web site. I created my buttons, but how do I make it when I click the button, it then goes to another place and makes the initial page disappears after that? Does the new location have to be on a new timeline, layer, scene, or what? Might you assist me with this, thanks?
Graham says
Hi ,
I was wondering if you had any issues with this working in Internet Explorer. It works with FF ok.
Any ideas??
Ayesha says
What is a Handler?
stefan says
Hi everyone, thx Jen for this post, i think i spend 2 hours figuring out how to do this in as3
Now i got another trouble in my quest to beat as3
i use this code to load text from php in as2 but in as3 i don’t have any idea how to do this.
a=new LoadVars
a.load(“myphp.php”)
a.onLoad=function (){
text_txt.text=this.var_name
}
And i think maybe you could help, help me please jen! you rule! Thanks in advance
Stacey says
Hi there.
I’m trying to link one scene to another.
It works correctly on one but when I copy and paste it gives me errors. It’s just a button to link to a scene (same on all pages).
Here’s the code:
stop();
allOn_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(106, “allOn”);
}
Here’s the error:
1021: Duplicate function definition.
Please help I only have this to finish!!!!
stefan says
Try this Stacey
stop();
allOn_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
function mouseDownHandler(e:MouseEvent):void {
gotoAndStop(“106”);
}
stefan says
If you’re using this in other places you don’t have to define again the function ’cause you already did it, i think this is why it gives you that error.
stefan says
stop();
allOn_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler2);
function mouseDownHandler2(e:MouseEvent):void {
gotoAndStop(”106″);
}
Jen deHaan says
@stefan (re: loadvars) – Peter Elst has a good post about the difference between AS2 and AS3 here: http://www.peterelst.com/blog/2007/11/28/actionscript-30-wheres-my-loadvars/
hope that helps,
Jen
Krysie says
I’m using CS4, I tried using the above script and changed the name to my name (BTN), and the below is what I have, and its not working (not clickable) in IE, although it works fine in Firefox….
BTN.addEventListener(MouseEvent.MOUSE_OVER, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.flashthusiast.com/”));
}
Any thoughts or suggestions?
Nessie says
Finally! After hours of searching someone finally explained how to create a freakin’ button that works with AS3. Thanks!
.Adi. says
Great tutorial, thnx!
CS3 is really wird: In the old versions of flash you don’t have to be an Actionscrip geek to add a hyperlink to a flash button. you could do it by few mouse clicks;(
stefan says
Thx a lot for the link Jen, i guess that solve my problem, thx again.
Robert says
Hello everyone! I have a problem. When I click the MovieClip called “chicken_hotspot” it should go to the frame called “news”. But in fact it does not do it but the other functions become unresponsive. What’s wrong?
THIS IS THE CODE:
chicken_hotspot.buttonMode = true;
chicken_hotspot.useHandCursor = true;
chicken_hotspot.addEventListener(MouseEvent.MOUSE_UP, gotoNews);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OVER, startChickenMotion);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OVER, StopMusic);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OVER, chickenOn);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OUT, stopChickenMotion);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OUT, chickenOff);
chicken_hotspot.addEventListener(MouseEvent.MOUSE_OUT, StartMusic);
function startChickenMotion(event:MouseEvent):void {
gotoAndPlay(“chicken2”);
}
function gotoNews(Event:MouseEvent):void {
gotoAndStop(“news0”);
}
function StopMusic(Event:MouseEvent):void {
mtrans.volume = 0;
channel1.soundTransform = mtrans;
}
function chickenOn(Event:MouseEvent):void {
channel2 = chicken.play();
}
function stopChickenMotion(Event:MouseEvent):void {
gotoAndStop(“chicken1”);
}
function chickenOff(Event:MouseEvent):void {
channel2.stop();
}
function StartMusic(Event:MouseEvent):void {
mtrans.volume = 1.0;
channel1.soundTransform = mtrans;
}
Robert says
Actually, i found the problem. FINALLY!
Bruno Morello says
Hi guys,
I’m using CS4 with AS3 and have a little problem with my rewind and forward buttons. For the play and stop buttons it works fine with this script:
playButton.addEventListener (MouseEvent.CLICK, playButtonClick);
function playButtonClick (e:MouseEvent):void
{
play();
}
But then I tried this for the forward button:
forwardButton.addEventListener(MouseEvent.CLICK, forwardButtonClick);
function forwardButtonClick (e:MouseEvent):void
{
this.gotoAndPlay(this.currentframe + 50);
}
I get error messages.
All I need is to rewind and forward the movie about 50 frames and keep playing without stopping.
Any help would be appreciated,
thanks
Azraai says
Hi,
Does anyone here know how to create form to send to an email address on CS3 using AS3.0?
Liesl says
I am a beginner and need a step by step instruction to convert images to button and then use these buttons to link to an url while the images are showing one after the other in a fade in fade out movie clip. Each image must link to another url…
Anyone out there who can help me in flash CS4 using actionscript 3?
ArleyM says
@Nadi Z and @Jean-Francois to make your button NOT open in a new tab add the target of “_self” like so:
navigateToURL(new URLRequest(“page.html”), “_self”);
Liesl says
Ignore my query, got it right, next problem is that it works in flash but not when input in Dreamweaver?? movie comes up but will not navigate to urls and pages setup.
JustaGuy says
@ Bruno: I think it’s this._currentframe
diana says
i’m new to flash. i want to know, is it possible to create a mulitple link from a single button?i’m trying to create a quiz using flash. what i plan to do is, whenever the user click on the right answer, they will see a “congratulations” frame. from that frame, i want to put the “next” button so it will lead the user to go to the next questions in the next frames. so is it possible to do that? that the button can go to multiple frames?
Godbar says
Hi Vlad,
This is the closest I have got to getting my button to launch my flash player. I was trying to use your geturl command but it just loads en empty window.
What I’m trying to do is emulate a function that I currently have applied to html buttons on my web page. My buttons have the simple ahref of javascript:Play(‘120′,’arabian_breaks_v1_demo_mix.mp3’)
and this calls up some js which launches my flash player.
When I try to use that same link ref on a button in a flash movie it fails because I’m obviously missing something.
So how do I word the code so that i calls up my flash player in the same way that a text link or button would?
Sorry for my ignorance.
Cheers
Godbar
Sandra says
I’m new at ActionScript 3.0. and though I see a lot of information about a link to a URL with the click of a button, I’ve got an Introduction movie that I want to redirect to another URL when it is done playing. Any suggestions?
Sandra says
Never mind. In answer to my own question, I got it to work with this:
var url:String = “http://www.site”;
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, ‘_blank’);
} catch (e:Error) {
trace(“Error occurred!”);
}
I also had to add another action (a stop action) so that the movie wouldn’t keep looping, which would have the URL keep reopening every time it looped.
Adam says
Flash is an abortion. Have you seen the terrible things Adobe has done to the UI in CS4? I can’t see how they make an amazing app like After Effects, and then the worst app I have ever used, as is Flash.
Please, HTML 5, put a stop to this scourge!
Jen deHaan says
Hi Sandra,
Have you followed the steps from this post for controlling the target window? http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
Sandra says
I can remember the good old days when things were simpler.
As for my, “never mind,” I take it back. I thought I had it working, but now I can’t get the URL to open in the same browser window. I thought it would be to simply replace the navigateToURL(request, ‘_blank’); with navigateToURL(request, ‘_self’); but it’s not working. Even the simple links within my flash movie open in a different browser window despite my indicating that they should open in _self.
Anyone have any ideas?
Sandra says
Thanks Jen,
I just looked it over.
The thing is, I’ve got an Introduction movie that I want to redirect to another URL when it is done playing. So, there is no button, just a key frame at the end of my timeline.
And, I made the other links by going to properties, under options, where you can just type in the URL and target it.
In both cases, I indicated _self. But, the links still open in a new browser window.
It’s a mystery.
Tiff J says
Hey guys! So I’m not so new to Flash, but this question is blowing my mind! If you could help me asap, I have this portfolio project due today (11/2 @ noon MST). So I have a button on my main time line and can’t get it to work throughout my whole website. I do not have the code on my actions layer, but on the button itself. Is that the problem? Here is the code
stop();
mainbut.addEventListener(MouseEvent.MOUSE_DOWN, mainplay);
function mainplay(event:MouseEvent):void {
gotoAndStop(3);
}
mainbut means my button on all of the frames to bring it back to the part on my time line where I labeled it “main” The button only works for “resume”, which is another label on my time line, frames 20 through 30. Label “main” goes from frames 9 to 19. I need this button to always go back to frame 9 on my timeline. But it only works when I am in my resume section, not from frames 31 to 90. What can I do? When I created different buttons on different layers, CS3 told me there was a duplication error. Even though I renamed all the buttons and their instance names mainbut01, mainbut02, mainbut03 etc.
So that’s all the info to make my problem clear. Anyone know how to make my button work on all frames from 19 to 90?
Thanks so so so so so much!
Tiff J
christine facella says
I’m trying to create a webpage that has two buttons (arrows) that will navigate the page left and right. Both buttons will have to be used multiple times: If I press the right arrow, the page “pans” to the right and stops . If I press it again, the page continues to pan to the right (and vice versa for the left button).
I have programmed other simple buttons that navigate me between scenes and link me to url’s, and have gone through several tutorials in my quickstartguide, but with this task
I can’t figure where to even start: Should the graphic on the page actually be a movie clip, that “plays” to the right if the right button is pressed? How would I move in reverse?
I don’t think I want to change the x axis of the page/clip, as I want it to be a smooth move. Or is there a way to make the transition smooth?
Can I script a single button for several events?
If anyone can help with anything (an example script would be awesome!) that will get me out of this flash-rut, I’d be super happy.
Thanks,
Christine
marcel says
please help m
Kit Umscheid says
Thank you for saving me from tearing the rest of my hair out. I’m sure they decided to make coding a simple actionscript like a URL button more complicated for a reason that I will probably come to appreciate as I use it more (I hope), but for now THANK YOU for posting this. : )
Bobby says
Hi! I have a minor problem with some actionscript-buttons. My button is supposed to be animated ad different animations should start and stop when the mouse is over and when its moves away. I had a code for that, but how do I get it to work in Actionscript 3?
The code is:
on (rollOver)
{
_root.Button.instance1.gotoAndPlay (2);
} on (rollOut)
{
_root.Button.instance1.gotoAndPlay (11);
}
Jayson says
Hi,
Im just learning flash in school and unfortunately i have the newest cs4 flash while my school computers all have macromedia flash player. Anyways, how can i make a button work that brings you to frame 2. I have tried your code from the first couple of posts, and it gives teh error access of undefined property my_btn. Any help you could give would be very helpful. Thanks in advance,
Jayson
Jayson says
One other thing it is saying, is that when i select the layer with my button on it and i try to open the actions, it says “current selection cannont have actions applied to it”
Thanks once again,
Jayson
JohnS says
Hi, thanks for the example. I have 6 buttons, which shows up all at the same time. Depending on which one is clicked, it takes you to either frame 2, frame 3, frame 4, frame 5, frame 6, frame 7 with all buttons shown for each frame. What I would like to do is show the down state for the button I pressed at frame one to show the down state of that button for frame #. Any AC3 code to allow that? BTW, I have all four-states per button. I would just like to show the down state per button for each. Thanks for your help!
Eric says
I’m trying to set up a “Movieclip _mc” style button and I can’t seem to find a tutorial on how to point this action to an external website.
I used the example above but changed the _btn class to a _mc and it didn’t work.
I’m relatively new to Flash so please be kind. :)
Every article I read is about the _btn class!
Frustrated Eric
Eric says
I figured out my issue above. I just had the code in the wrong frame.
Jennifer says
I am a college student trying to work out what needs to be.
I have to create an invisible button, and two other buttons. I know that all buttons are going to be a part of navigation, which will allow the user to navigate to each frame in the pace that they need.
So, I have a few keyframes with their labels. If I want to be able to have the user start from the first frame that is labeled, then move onto the next labeled frame, and then to the next labeled frame, and so, how do I do that for the frame labels?
This is how I think it should go, but not too sure at all.
stop();
function onAll_Below_IntroTextClick(evt:MouseEvent):void }
gotoAndPlay(“All_Below_IntroText”);
}
intro_btn.addEventListener(MouseEvent.CLICK, onAll_Below_IntroTextClick);
Now I want to inform you that my first Label, for my First Frame is titled All_Below_IntroText, my instance button name would be intro_btn. Now…what is going on here, is this correct? Is this wrong? Please help me because I only have another 3 days to complete everything needed for college assignments because of my program being a trial and have only 3 days left to complete a total of 4 or 5 more weeks of assignments.
itzel says
hello i’m building a website with flash buttons, I had use the code as is posted and everything works fine the only thing is that every time i click a button it opens the page on a new tap. Anyone knows what to do, in order to open the different url in the same tap?
Peter says
Ok, I’m also totally new to Flash (I’m using CS4, Version 10.0) and Actionscript 3. I have an html page with a link that loads a popup window which includes a simple Flash movie. Some javascript code produces the popup window.
What I’m trying to do is have a button in the Flash app close the popup window. I would think this would be fairly simple, but I can’t get anything to work. Any suggestions?
Thanks
Cruz says
so i’ve figured out how to do the whole thing. but let’s say i’m working on an animation. i have my first screen as the ‘play’ button. but once i click play, the animation starts but the play button stays on the screen. anyway to have the play button disappear once it’s pressed?
Jeff says
I am trying to make a menu function for my game and my code is
stop();
btnPlay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
and i am getting this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Spaceinvadors_fla::MainTimeline/EnterFrame()[Spaceinvadors_fla.MainTimeline::frame2:126]
i dont know what to do can anyone help
Jen deHaan says
@Lisa: You’re getting the same link opened, because all of your buttons are targeting the first function. You just need to rename your second through fourth click handlers to point to the respective functions.
For example, this line: port_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
Should be:
port_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
That will point at the function buttonClickHandler2 you have below that line, instead of your first buttonClickHandler.
I hope that helps solve it for you,
Jen.
Lisa says
Maybe I made a dumb assumption that I could create each page of my website as different .fla files and link them (the way it works in Dreamweaver), but after making the buttons and all the files, I can’t figure out how to make them interactive. I feel so stupid! How does this work??!!
My code is:
home_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.lisaruffmanweiss.com/index.html”), “_self”);
}
port_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Portfolio.html”), “_self”);
}
resume_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler3(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Resume.html”), “_self”);
}
contact_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler4(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Contact.html”), “_self”);
}
After I publish and test the swf file it opens a blank home page no matter which button I click. I’ve been trying to figure this out for months but I get conflicting information and, if any. THIS IS SO FRUSTRATING!!!
Michael says
Hi, sorry if I am repeating what others have written before, but I have the code on one layer (no keyframes etc, layer runs from start to finish of timeline) for two buttons; button 1 makes the movie run from frame 2 and stops on frame 10. button 2 runs from frame 11 to the end (so far only 20 frames).
i am getting the error of “TypeError: Error #1009: Cannot access a property or method of a null object reference.
at site_fla::MainTimeline/frame1()” when i run the movie. button 1 works, takes me to frame 10 then stops. the “close” button (button 2) doens’t work, and i get that error.
my code is as follows:
stop();
photo_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(2);
}
close_btn1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndPlay(11);
}
button1 is “photo_btn” and button2 is “close_btn1”. Could someone please please help me?? It is driving me mad.
Michael says
Nvm I got it to work .. I split the code so that the code for “photo_btn” was on frame 1 (start of movie), and code for “close_btn1” was on frame 10. works!
Lisa says
THANK YOU! THANK YOU!
Jen,
I now feel like I’m a step closer to getting my site up. I’m still having some weird issues, though. I saved all my .fla files as swf and html and have both uploaded to my host site. When I check the index.html file it comes up blank.
And when I look at my portfolio page, it doesn’t play the whole movie; it plays scene 1 and then jumps to my Contact page. I’m sure this is something to do with my code, but I’m still new at this and I can’t figure it out.
Thanks again for your help!!
Federico Echeverria says
Hello, i have a problem. i have this
stop();
btn1.addEventListener (MouseEvent.CLICK, onClick);
function onClick( event:MouseEvent):void
{
event.target.gotoAndPlay.(“page1”)
}
btn1.buttonMode = true;
but when i press on my button everything goes ok exept taht if i click on the image on the frame (Page1) it happens the same thing so is there a way to Modify it to just happen on the first frame? idk if you can understand what im saying. please i really need help im making a webpage. Thanks
general says
stop()
btn1.addEventListener(MouseEvent.CLICK,Play1);
function play1(event:MouseEvent):void {
gotoAndStop(“leaves”);
}
btn2.addEventListener(MouseEvent.Click,Pla1y2);
function play2(event:MouseEvent):void {
gotoAndStop(“MODELING”);
}
btn3.addEventListener(MouseEvent.Click,Play3);
function play3(event:MouseEvent):void {
gotoAndStop(“child”);
}
addEventListener(MouseEvent.Click,Play4);
function play4(event:MouseEvent):void {
gotoAndStop(“tats”);
}
general says
well im trying to make a photo gallery in flash becuase i cant get the right code in shadowbox either. well i made thumnails and when u clic on it the jpg shows i cant get it to work someoner help
stop()
btn1.addEventListener(MouseEvent.CLICK,Play1);
function play1(event:MouseEvent):void {
gotoAndStop(“leaves”);
}
btn2.addEventListener(MouseEvent.Click,Pla1y2);
function play2(event:MouseEvent):void {
gotoAndStop(“MODELING”);
}
btn3.addEventListener(MouseEvent.Click,Play3);
function play3(event:MouseEvent):void {
gotoAndStop(“child”);
}
addEventListener(MouseEvent.Click,Play4);
function play4(event:MouseEvent):void {
gotoAndStop(“tats”);
}
ria says
hi, does anyone know how to create a button in flash that enables the user to change the value of a number?? thank you
sam says
Hi I’m taking a class on flash but I got stuck making a start button! I have no idea why I’m having such a hard time because normally I think it’s really easy but for some reason the I keep getting a message that says “Current selection cannot have actions applied to it”
I converted the image into a symbol and it is a button because when I put the page in the brower in dreamweaver, it makes the little hand when I go over the flash image.
Please help.
Sam
Lisa says
I still have a few problems that I can’t figure out. Is there any way you can look at my files or if I could send them to you? I tried to post the code but that section of my post didn’t seem to show up.
I’m getting a bit desperate. Nobody is as willing to help as you seem to be (and your advice is excellent). I feel like I’m completely stuck.
Please help!
Lisa
frank says
hi, i’m new in actionscript and i have this problem. i am creating a web project. on my scene 1, i have this movie clip called classes located on frame 5 and on frame 15 i have this movie called math. i try to create a button on the classes movie clip to goAndStop on frame 15 and play the movie clip called math.
Jen deHaan says
@Lisa: If you can link your FLA file I’ll download it and try to take a look and see what’s up. Also if you can post a link to your site where it’s showing up blank that might help figure out what’s going on. It’s likely there’s an issue with the embed code / SWF it’s targeting.
Jen deHaan says
@Sam: For AS3, you need to put your code on a frame instead (you have the button selected instead of a frame). Make sure a frame is selected before putting code in the Actions panel.
Lisa says
Jen,
Thanks so much. You are a blessing!
My files are at:
http://us.1.p6.webhosting.yahoo.com/filemanager?directory=&dispopts=+
I’ve uploaded my swf, fla and html files there, as well as some image files and anything else that might need linking. My website is at: htp://www.lisaruffmanweiss.com.
Thanks again!
Lisa
Oli says
Hi Jen, just wondering if you could help me out here. All three of my buttons go to frame 2, where my game is. Here is my code:
stop();
play_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
moregames_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.kongregate.com/accounts/EpilogueGames”));
}
howtoplay_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(3);
}
See if you can spot anything odd.
Cheers,
~Oli
Oli says
Sorry, I forgot to mention that the buttons are supposed to go to the actual game, the instructions frame, and my game Studios website. They all still go to my gameplay frame.
Oli says
Never mind, i managed to fix it. Just changed the code to:
stop();
play_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
moregames_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.kongregate.com/accounts/EpilogueGames”));
}
howtoplay_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(3);
}
Remaning the mouseDownHandlers with numbers after.
Carlos Defilippi says
Hey, Everyone….
I am a new web site 15 pages to flash cs4 and as3. I’ve been building a flash website for the past week or so and so far things are going ok. However, I have a navigation menu with buttons I’ve as’d to navigate to a new pages Currently when the buttons are clicked do not open my pages or navigate the pages
thanks
Jan says
Hi,
Maybe you guys can help me with this.
I need to create a flash activity worksheet for little children.
Basically, the children has to click on the wrong answer and press on the delete key button (key code : 46) on the keyboard to delete the wrong answer. When the wrong answer is being deleted, a pop up movieclip will appear saying something like, “Well done!”
Every question has two answers, one correct and the other wrong. I intended to make each answer into buttons but then flash somehow does not let me input actions into the buttons. I have no idea why.
If you guys do have any other possible solutions for me to do this, please help me here.
Lisa says
Hi Jen,
Have you had any luck in finding out what I did wrong?
Lisa
Margaret says
http://www.twincling.org/node/742
bruno Morello says
Hi everybody,
Need a little help on loading external swf movies. I have a main menu page with 4 menus and when I click on a menu it loads an external movie and plays right on top of my menu page.
Is there a way to hide the main menu contents while the external movie plays ?
Any help would be great.
Bruno
Jen deHaan says
@Lisa: Sorry, I forgot to post that I’m not able to grab the file(s) from the Yahoo site – when I log in it says that I don’t have permission to see the files. Could you send it to me at kidderton ( at) gmail.com?
Regarding the home page, it looks like the home.swf file isn’t in the directory the home page is pointing at. You will either need to update the links in the index.html to point at home.swf, or move home.swf into the root directory of your site.
Hope that helps! I’ll watch for the file.
Thanks,
Jen.
Riddhi says
Hi!! trying to brushup my flash..but having a lot of problem with as3. please help. i followed your how to make a button and link it to a particular frame; say from 1 to 2. it worked initially.
Now i have added 4 button to the frame 2 which are also moveclip buttons like my initial button. I added the script in the same action layer as the earlier button but on frame 2, as my initial script was on frame 1. now the error i get is;
1046: Type was not found or was not a compile-time constant: product_ball.
Riddhi says
stop();
event_ball.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(3);
}
product_ball.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(4);
}
graphic_ball.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler4);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndStop(5);
}
Exhibition_ball.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(6);
}
Riddhi says
that was the script on frame 2
and
this is on frame 1
stop();
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
Riddhi says
hi!! got it..just changed the instance name to something else and not same as the button name.
hope it is correct. works for me.
thanks
Martin says
some one help have no idea on how to make a button work. Just want 2 buttons forward & rewind, this is just to skip to the next keyframe or rewind to the previous, this is for a slideshow
thanks in advance
Lisa says
Hi Jen,
Happy New Year!! Have you had any luck figuring out why my Home page is blank and my Portfolio page jumps to my Contact page after scene 1?
thanks, lisa
Jen deHaan says
Hi Lisa,
Sorry, was on holidays :) I took a look at the Portfolio page and don’t see any obvious reason why it’s progressing to the Contacts page. I’ll take a further look tomorrow – just wanted to let you know I’m taking a look. I’m gathering that at the end of the scene would be some URLRequest to the Contacts page, but I’m not seeing anything like that. I’d double check that you have the latest version of the Portfolio.swf up there, perhaps an older version is up? As for the home page, I’m still not seeing the home.swf up at the address its pointing to, which I’d gather to be the problem there.
Jen deHaan says
@Lisa: Try re-uploading the Portfolio.swf. I viewed the code in the SWF on your site and it seems different than the FLA you sent (there are some navigateToURLs outside of functions – I think it may be taking the last one, Contact, and jumping to it). I don’t see this in your FLA file, so re-publishing/uploading it may do the trick.
francois says
I love you – Thanks
I can sent the banner now..
Lisa says
Hi Jen,
Thanks so much for your help. I did what you said, and believe it or not, all the files did exactly the same thing. The home page still comes up blank and the portfolio page still jumps to the contact page. This is quite the puzzle!
Lisa
mandy says
Okay well i’m making a flash movie with a start button, but everything i enter turns out in an error my last attempt was almost right but flash said that } was unexpected and when i deleted it they said that it was an unexpected ending and that it needed this } so i’m al lost. the video i made just starts with the button but it automaticly plays the vid instead of waiting for instructions or a simple click with my mouse.
Monica says
Thank you so much Jen! This really helped me a lot.
Monica says
I have an animation that plays when the button is clicked then goes to a url. I used MouseEvent:MOUSE_DOWN for the animation and then MouseEvent:CLICK to go to the url. It works, but the only problem is that no one is going to hold down the mouse long enough for my animation to finish (even though it is only a few seconds) before lifting the mouse button and it jumping to the url. It gets about half way through and then it has already loaded up the page. Any suggestions on how to remedy this?
Thanks again for your great tutorial!
Brian says
Great site, Jen. Very informative. I wonder if you can help me with a website I’ve built in CS4. The site consists of about 100 “pages”, each an individual .swf file, which load in a single flash movie embedded in an html page. Navigation is achieved with buttons that use a loadMovie function. I have no problem loading specific files, so forward navigation is working. But I need a way to load the PREVIOUS file for backward navigation. Is it possible using actionscript to tell flash to load the previous .swf? Can the flash player store user history? (BTW, I am using Actionscript 2.)
I’ve scoured the internet for solutions to this and haven’t found a single mention of true backward navigation with flash. If you can help me solve this problem, I’ll be MOST grateful.
Brian
newbie says
Hi i am a newbie in flash, i need your help. I just want to link from a page to another page in flash. But I am stuck. Can you help me with the codings and send it to my mail.
Deeply appreciated.
Marshall says
Hello,
I am working on a video project and am having some serious issues and it is making me almost miss my deadline. the problems that i am having are with code.
My project is an interactive video for the web. There are two films the first film is quite dull and not very interesting when it plays there is also a button that you can click to go to the next film which is more interesting. the trick is when you click the button you can only watch the second film for the same ammount of time as you watched the first film. there are also credits that should run when the second movie is finished but that could be after 3 seconds or a minute so i need it to be able to adjust when it runs
I have no idea what i should do to make this work i need help with making the button work. i also need help with having the second video load while the first one is playing also i need it to be able to measure the length of the first film and play the second film for that exact time. and finally the credits will be difficult to work out
if there is anyone who thinks they can help please reply it would help save me from ruining this project
many thanks
Len says
OK,,Im trying my first foray into buttons in flash and I failed on step 1. I built a test using CS4. One slide with a simple image defined as a button. Second scene is just a simple text box for now. I have the script assigned as
stop();button_1.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);function mouseDownHandler(event:MouseEvent):void {gotoAndStop(1, “Scene 3”);}
Yes, the 2nd scene is Scene 3, and the button is named button_1
When I TEST MOVIE, i get a compiler error–1120: access of undefined property button_1.
HELP???
Steve says
Hi, another mindlessly stupid Flash newbie here. Ok, I’ve constructed a simple picture viewer, with each picture on its own keyframe. I just need my forward button to navigate to the next keyframe, and the back button to go to the previous keyframe. How the bloody hell do I do this, c’mon, there’s gotta be SOME way to do this! what import command do I use at the beginning, and what event listener do I use???!!! And one more thing… why the bloody hell couldn’t they make this goddam program more like Director, with easy to find prefabricated action for just about everything you would need to do, with the OPTION to write a script if you want???!!!??? Someone, please help me out here…
Steve says
Ok, (deep breath) here’s the code I’m using so far, with “goforth” being the forward button:
stop();
import flash.events.MouseEvent
goforth.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
}
Now I think to advance to the next keyframe, I do something like:
gotoAndStop(next (Keyframe))
How do I fit that into the above code to make it actually work?
Steve says
Please disregard previous panic attack; problem solved! :D
stop();
goback.addEventListener(MouseEvent.CLICK,backward);
goforth.addEventListener(MouseEvent.CLICK,forward);
function forward(event:MouseEvent){
if(this.currentFrame == this.totalFrames){
gotoAndStop(1);
}
else{
nextFrame();
}
}
function backward(event:MouseEvent){
if(this.currentFrame == 1){
gotoAndStop(this.totalFrames);
}
else{
prevFrame();
}
}
Darko91 says
thanks people you helped me much here just ceap the good work :))
you are the best !!!!!
David says
Hello everyone. I am using Flash Cs4. I have a problem were I want a button that is clicked to take the user to a new, different URL, and have that window open up minimized, without closing the current window they were in. In other words, I want a new webpage to open upon clicking this button, and at the same time, allow them to just click the original windows panel to go back, thus getting rid of the back button feature. Is this possible?
Kleinbaas says
FIXED: Multiple Buttons/Links
For those of you trying this with multiple buttons, you need to make sure that the “MyHandler” functions dont have the same names.
Your code for two buttons with links should look like this:
button_1_instance.addEventListener(MouseEvent.CLICK,button_1_ClickHandler);
function button_1_ClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“/button-1-page.html”), “_self”);
}
button_2_instance.addEventListener(MouseEvent.CLICK,button_1_ClickHandler);
function button_2_ClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“/button-2-page.html”), “_self”);
}
The button graphics must be converted to symbols and must have instance names assigned to them that match (that is button_1_instance and button_2_instance.
See http://www.adobe.com/designcenter/flash/articles/flacs3it_firstflash_pt2_06.html
and
http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
and
http://www.brightvisions.co.uk
Hope that helps! :-)
Kleinbaas says
FIXED: Multiple Buttons/Links
For those of you trying this with multiple buttons, you need to make sure that the “MyHandler” functions dont have the same names.
Your code for two buttons with links should look like this:
button_1_instance.addEventListener(MouseEvent.CLICK,button_1_ClickHandler);
function button_1_ClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“/button-1-page.html”), “_self”);
}
button_2_instance.addEventListener(MouseEvent.CLICK,button_2_ClickHandler);
function button_2_ClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“/button-2-page.html”), “_self”);
}
The button graphics must be converted to symbols and must have instance names assigned to them that match (that is button_1_instance and button_2_instance.
See http://www.adobe.com/designcenter/flash/articles/flacs3it_firstflash_pt2_06.html
and
http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/
and
http://www.brightvisions.co.uk
Hope that helps! :-)
Ryad says
Hi guys, am very new to flash and as3. am building a basic website with four buttons ( Home, About, History, Contact Us), a text holder (myText_txt) and a movieclip to hold pics (bigPic_mc). so my question is how do i load external .txt files (home.txt, about.txt…) when each one of the buttons are pressed while also getting the bigPic_mc to display four different pics (pic1,..pic4) ???? am really stuck with this and have tried a number of things.
Levi says
I am having trouble making a button on frame 1 that goes to frame 2 and one on frame 2 go to frame 3. I have tried this code “stop();
start.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
run.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(3);
}”
But I still get the error message “TypeError: Error #1009: Cannot access a property or method of a null object reference.
at windows_fla::MainTimeline/windows_fla::frame1()
“
Lisa says
Hi Jen!
My Home page is finally fixed! (I had the html pointing to my local files instead of the files I had uploaded.) Thanks again for your help! As for my Portfolio page, I decided to consolidate it into one scene, hoping it would solve that jump-to-the-Contacts-page that it does. Still no luck. I looked over the html and saw no sign of it jumping there. It doesn’t do this in the swf. THIS IS DRIVING ME CRAZY!!! My code looks like this:
home_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.lisaruffmanweiss.com/index.html”), “_self”);
}
port_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Portfolio.html”), “_self”);
}
resume_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler3);
function buttonClickHandler3(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Resume.html”), “_self”);
}
contact_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler4);
function buttonClickHandler4(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.lisaruffmanweiss.com/Contact.html”), “_self”);
}
Lisa says
Sorry, I take that back. It’s finally fixed!!! Removing the scenes solved the problem. Thanks so much for your help!
Red says
Re Levi, above. I am having same problem. Had something that worked in AS2 but not now in AS3. I had an app that had buttons moving forwards or backwards to frames. Now in AS3 I get error 1009. Button on first frame works but no others do.
EvenA says
i have a (maybe) stupid question about buttons,
how can i disable a button from another button inside of a movieclip with as3?
=(
bryan25renzo says
what if i want the button to be click and go to a different frame???
What should i put in…just started to use AS3….
Kevin says
First, thanks to everyone who have contributed these precious knowledge! I got through part of my project with the codes where I can link my flash button to another page. My new problem now is that I need my flash buttons to link to a named anchor on the same page, like clicking on the flash button, and then page would scroll down to my named anchor. I’ve read couple other posts about putting xxxx.html#anchor. but I’m having a different case, because I’m making an eBay page, which I can’t link to an external page, it needs to be in the same page, so I can’t have the html in the front… just need to navigate within the same page. Please can someone help me out here?? Greatly appreciated, good job guys!
Richard says
Hi, i am making a converter in flash to convert metric to imperial etc, i am trying to code a clear button so if the user types in the wrong value they can press it and it will clear the input text box
any help with the code would be much appreciated, i can only seem to find code for as2, im using cs3
sandy says
Hi all!
How do i add Feedzilla to my Flash CS3 webpage?
HELP!!!
Judy says
Hey Jen, I support all of the affiliates for my company and we use
on (release) {
getURL(clickTAG,’_blank’);
}
I need to clickTAG in there, can’t hardcode the url. Can you help with this one?
Thank you so much!
bharathi says
i want flash button that if curserover should jump(floating) with tictic sound,same time when without release mouse ,button should
come with mouse
Ronald says
I have an .mov that i converted to .flv but it came out as 1 keyframe and i have a button that i put on my video which links to a url but i need the button to move onto video or apppear at eactly 6min and 42secs. i have been working on this for 6hrs and cannot figure it out. if not knowing the code do you know how i can bring this one movie frame into multiple ones.
subhash says
I placed 4 screens in 4 different frames like 0th frame,40th frame,80th frame,120th frame …. so i want to move from 1st frame to 120th frame using a button control.All these frames must move sequential like a movie clip and has to show all the 4 screens while moving….So How to do this using a button control.
subhash says
I placed 4 screens in 4 different frames of 1 layer, like 0th frame,40th frame,80th frame,120th frame …. so i want to move from 1st frame to 120th frame using a button control.All these frames must move sequential like a movie clip and has to show all the 4 screens while moving….So How to do this using a button control.
easy says
Hi Jennie and John, i noticed there was a problem with your code, if you have two buttons the code should be
stop();
foodbtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.bc.edu/dining"));
}
peoplebtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest ("http://www.cbord.com"));
}
easy says
for the second btn you should have “buttonClickHandler2”
stop();
foodbtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.bc.edu/dining”));
}
peoplebtn.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (“http://www.cbord.com”));
}
Bryan says
Hello all. I used Flash YEARS ago. I am now on a Mac and have cs4. This is so different and I am lost. I read the great (and simple) tutorial above. I created a flash ad with a button that has a mouseover. When I try to include the script in the action panel, it says “Current selection cannot have actions applied to it.” LOL. How do I make a simple button that calls a URL? I don’t know Flash any more. Help.
Jen deHaan says
@Bryan:
Both of them are pointing at the same function. Change the line that starts with replay to:
replay.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
Post on multiple buttons: http://flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/
Bryan says
Well… I closed the program last night and when I opened it this morning…I was able to add the code to the actions panel. SO Confused.
I was able to get my button working BUT I can’t seem to get a second button working in the same scene. (AS3)
What I have is two buttons. One is a mouseover button (web_btn) that calls a URL and the other is a mouseover button (replay) that I need to go back to frame 1 and play. Can you help with adding the correct code for the second button?
stop();
web_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.thelisaproject.org/”)) }
Bryan says
This is my most recent attempt:
stop();
web_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.thelisaproject.org”));
}
replay.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
gotoAndPlay(1);
}
Both buttons attempt to call the URL and neither goes to and plays frame 1.
I think I am out of my league.
Bryan says
Jen-
THANKS so much!
kmlgd says
i dont know why they´d turn easy simple tasks into really complex ones. thats nice for a programer i think but for the rest of us, no. ;(
Robyn says
Hi, I’m trying to load a movie using a button. I’m sure this has been discussed in earlier threads, but I’m having a really hard time finding the info and what I have found includes other actions besides what I need. I just want the button, when hit, to load an external .swf file inside the movie clip playing.
In AS1, this is what the button command said
on (release) {
loadMovieNum(“About.swf”, 0);
}
So how would this translate into AS3?
Brian says
In desperate need of code to create a simple close button, but I am very unfamiliar with AS3. Does anyone have the code for this?
Thanks!
ochin says
Wow, that’s so usable..
thanks for sharing :D
keep sharing
Mr Sexyness says
so I have a question
I created my button easy ok. (flash Cs4 Action Script 3)
flash website
how do I create a link “RESUME” when they click it it will direct them to a PDF in the same browser only different tab and display my resume.
Thanks!
femzy says
hello Pros, am entirely new to Flash and am having some difficulties in my movie, i get this error “The class or interface ‘MouseEvent’ could not be loaded.” i have tried the same lines of script on flash8 and cs3 but i keep getting the same errors. Plssss help!
Dan says
I don’t do that much flash but when doing flash actionscript 1 or 2, a geturl on a button was really easy. Now on CS 4 and actionscript 3, it seems ridiculously harder. What the hell is going on?. Flash does my head in!!
Sylwia says
Hello there,
Please i need badly help. It is probably very easy but since I come back to flash after few years i am stack. I just want my movie STOP on the MouseEvent.CLICK or MouseEvent.UP.
I know how to get URL but this simple action is driving me crazy
Dani says
Hi there – I used the code at the very top to link a URL. It goes to Firefox, but it doesn’t open the site. All my code is exact, using my button instance and new website only… So frustrating its so close!! here is my code:
my_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.saltys.com/”));
}
Sita says
Hi there
I think I have tried everything suggested here, and I’m getting a bit desperate, I keep getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at soccer2010_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at soccer2010_fla::MainTimeline/mangenaClick()
I’m not sure of the reasons for this, I am creating an interactive touchscreen app with four buttons on the first frame that are meant to link to four different frames with flv videos.
I have only done the first one, and I also have a different piece of code on this one, could it be interfering with my buttons, and if so how would I solve it, and if not please just help generally.
The extra bit of code that is external to the back button code is:
myMovie.volumeBar=volume_container.volume_bar;
Sita says
sorry it erased the end of my post, the button code (that is on the same frame as the actual button) looks like this:
mikemangena.addEventListener(MouseEvent.CLICK,mangenaClick);
function mangenaClick(event:MouseEvent):void {
gotoAndStop(2);
};
Sita says
sorry i meant gotoAndstop (1);
Jen deHaan says
@Adam: Same window. For a post on how to control window targets, see http://flashthusiast.com/2009/07/24/controlling-the-window-a-button-click-opens-using-actionscript-30-in-flash/.
Adam says
Hey this was great! Very helpful! All the other sites made this process so uncecessarily complicated. But I have a question. In a webpage, will these links open in the same window, or will they open in a blank window? I want mine to open in the same window.
Thanks again!
-Adam
Keith J Chesworth says
I seem to be yet another one with the http call not working.
I have some child sites on happysnapper with GoToAndStop working fine
However I am doing one http://happysnapper.com/book with a total failure to work. I have copied and pasted the monkey example at the top then modified it to:
stop();
unseenlondon_btn.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(“http://www.unseenlondon.co.uk/”));
}
RAH_btn.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL (new URLRequest (“http://www.happysnapper.com/royalalberthall/”));
}
with a total lack of action.
The fla is sat at http://happysnapper.com/book/page3.fla
and the web page removed from the ‘book’ at http://happysnapper.com/book/pg3.html
Please help!!
An old and getting older Keith
Jen deHaan says
@craig: Please see this post here about how to do forward/previous code for buttons:
http://flashthusiast.com/2010/05/05/buttons-in-flash-using-actionscript-3-0-going-to-next-frame-and-previous-frame/
craig says
Does anybody have ‘forward’ and ‘backward’ code for 2 buttons to go to the next frame and then backwards. Seems like a pretty straightforward process to achieve, but not in AS 3. Makes little sense why Adobe would complicate a relatively simple command.
OMAR says
Hey everybody, Hey Keith J Chesworth,
I viwed the link http://happysnapper.com/book and actually i liked the book very much. i’ve been trying to make something smiliar for a photo album/cataloge but i failed. DO you, or anyway reading this, have any tutorial on making such a book, album or cataloge (specially the effect of turning the page-i failed to find an actionscrip3 or code to do it)
Please Keith/all if you can, help me as i’m still a beginner :)
Thanks….
Jerry Alport says
In your step2 of Making a Button Work, you attach the code to create a listener to an instance of the button.
Can a single copy of the function called by one listener instance can be called from other listeners of the button instances on different scenes or screens.
Is it possible to attach the code for creating the listener to the button object itself in the library rather than the instance.
This would save having to create code (yes, it’s only one line of code) for each instance of the button, and once the listener creation code was good on the button in the library, creating a new instance of the button would always create good code. It would also simplify making changes to the listener definition for multiple button instances.
Even better, if the function could be associated with the button object in the library, reusing the button could take less code.
doyle rolle says
Hi I have an urgent issue with my flash intro page. I have the button and proper code, but it keeps looping even though the timeline reflects there’s a stop. Once i remove the code and place just a stop, the movie stops looping.
enter.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest("http://www.ipledgedallegiance.com/"));
}
I’m using Actionscripting 3.0, CS4. Can anyone help?
Cesar Perez says
thank you so much, estab esperando esto hace rato
Takura says
So, I’ve made an animation and at a point I want the animation to stop and then you have to click on one of the buttons, of of them goes to another frame or something where the animation continuous :) The other 2 buttons say something like : You’ve chosen the wrong button or something. I know…it’s pretty much, but is this possible? This is not for an website or something.
Sorry if I didn’t describe good what I want and sorry for my poor English, I’m tired.
jpoopdog says
how do you use this code for multiple buttons as flash doesnt seem to be able to hadle multiple copys of this code on the same frame
i get an error saying 2021 error duplicate function defition
Jen deHaan says
Please see the other post for multiple buttons linked on this page above:
Iara F. says
my_btn.addEventListener(MouseEvent.CLICK, toHome);
function toHome(event:MouseEvent):void {
navigateToURL(new URLRequest(“home.html”));
}
I am using this example in my site and it is working. But I am only going to one page to another.
Iara F. says
stop();
pre_btn.addEventListener(MouseEvent.CLICK, preButton);
function preButton(evtObj:MouseEvent):void
{
gotoAndStop(“pre”); // Frame’s lable
}
next_btn.addEventListener(MouseEvent.CLICK, nextButton);
function nextButton(evtObj:MouseEvent):void
{
gotoAndStop(“next”);// Frame’s lable
}
I think You can label the frames and make each button go to each different frame and you can use gotoAndStop or gotoAndPlay you try to see which works best
Matt says
sita,
i’ve have flash project that uses a ‘replay’ button. i think this may actually help:
1) make sure your button is a button symbol.*
2) the replay button (or your button) has to be visible in the timeline* on the stage.
3) select the button and give it an instance name (in the properties panel), like ‘replay’
4) in the same frame as the button, on the actions layer, create a blank keyframe and put in the following code:
//this stops the playhead at this frame
stop();
//replay is the name of the button–change this to the name of your button
replay.addEventListener(MouseEvent.CLICK, clickSection);
function clickSection(evtObj:MouseEvent) {
//trace shows what’s happening in the output window
//trace (“The Replay button was clicked!”);
//go to the section clicked on
gotoAndPlay(“AnimStart”);
}
in the above, ‘AnimStart’ is a separate label on my ‘labels’ layer.
it may be the code is breaking if you’re saying ‘gotoAndStop’
why not have a stop action on the actions layer at frame2: stop(), then have a label layer with something like ‘f2Movie’
then have the button code say gotoAndPlay(“f2Movie”);
hope this helps.
LeeAnn Weber says
I desperately need help with a button in CS3. I have tried the above and keep getting the following errors. Any ideas what I am doing wrong?
I need the button to open a new window with a URL.
errors given by Flash:
1083: Syntax error: bitwiseand is unexpected.
Nader Hamandi says
Works perfectly for me using CS4
Thnx
Jon says
DUDE This doesn’t work!
Kodiak says
If you are getting syntax errors with the ActionScript code:
navigateToURL(new URLRequest("http://www.flashthusiast.com/"));
Try changing the (") to the actual an actual quote character (“) so it reads:
navigateToURL(new URLRequest(“http://www.flashthusiast.com/”));
Kodiak says
Bah, when i posted it converted to characters but what i was saying is:
Change the & quot ; in line 3 to the character “
Kaitlyn Demarest says
Simply just exploring at your article on my brand new HTC phone , and I needed to find if it would allow me comment or if it was going to make me go to a pc to do that. Ill check back again afterwards to see if it worked.
Rich says
Thank you for this tutorial! It is written well and easy to understand. There was only one thing that isn’t working correctly for me. My finished product opens the URL in a new window instead of the parent or self.. I need to make it open in the existing window instead of a new popup window.. Any suggestions? Thanks again for your help training us!
Rich says
You know what, I saw the link you posted in the comments and got the button working correctly. Thank you so much for your help!
And Kaitlyn, looks like it worked!
Jen deHaan says
@Lucia: Not sure what you mean – the link is right after that text…
Lucia says
For info on targeting a frame within a movie clip placed on a scene, see this post here: … Um,.. searching, scanning, looking,.. nope! :D (please one more little post yes?)
Christina Bruun says
Thanks! Just what I needed for my Flash header :)
Regards
Christina Bruun!!
Portfolio: http://cltb.dk/cases :)
Jen deHaan says
@Chris –
If you could elaborate on what’s not working that would help us help you. The code does work and many people in the comments got it working. If you’re trying to do something different or integrating it with something else, there may be an additional step or different article that you require and that could be causing the error.
Additionally, if you’re using CS5 there is a Code Snippets feature that covers adding the code.
Jen.
Chris says
I can’t believe Adobe actually linked this to their site. It doesn’t even begin to work. I’m starting to hate Flash and, for that matter, Adobe. It should be as simple as right clicking on the button and choosing the Actions command that ADOBE put there. But no, you have to go through a bunch of other crap that not even their own authors can figure out. We need a decent (and, for that matter, affordable) alternative to Flash.
Emmanuel says
Hi… I am working with Flash CS4/Actionscript 3.0 – I have tried for hours trying to get the replay button to work… Can anyone download my file and see what it is that I am doing wrong… PLEASEEEEE
https://www.yousendit.com/download/cEd1Rm96MGNoMld4dnc9PQ
Roge says
My problem es that im using photoshop layers, and i cant use them as a button. I change those layers to SYMBOL, then BUTTON, but the SOURCE BROWSER doesnt activate…. if any one can help, please. Thanks.
neloora says
Thank you soo much! I read a many many many codes, but still doesnt work my flash with it. But yours finally work! Thank you!
ps. and sorry for my bad english -.- :)
<3
polin says
hi, I have some broplem with the button. my button have home,service,produce and contact.it have broplem like this:
The class or interface ‘MouseEvent’ could not be loaded. thank you for post.
Andrew says
I am having the most difficult of times getting these buttons to work!! i keep following the directions and copying and pasting into actions and errors keeping coming up when i test. there are 3 syntax errors. I am using as3 on cs4. i even open up a new testing file and just have one symbol and a button and cannot get it to work. please helppp
thanks,
andrew
leokearon says
I am working with Flash CS4 and action script 3.0.
Is there anyway I can use the same button over multiple frames without having to change the code all the time? I don’t to have to create hundreds on buttons, which will do the same thing.
Lana says
Working on CS5 and AS3. Is there a way to have one button do different actions depending on frame?
So for example, you have a button on scene 1 frame 1. It will go to scene 2 frame 2. Now on that scene it has the same button but instead it will go to scene 3.
Tyla says
Hi Jen
I used you Flash ActionScript:
T_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (“terms.html”));
}
And it worked perfectly, the only problem is it keeps opening in another tab, is there a was to add a _self. I tried to put it just after the file name:
(“terms.html, “_self””));
But I got an error…Please could you point me in the right direction
Thanks
Newbie says
Hi, guys, i am using adobe CS5 and i wan 2 navigate to other scene by clicking on the button “Enter” , but don’t know why i cant enter to the next scene and it pop out something like this.
ArgumentError: Error #2108: Scene Navigator was not found.
at flash.display::MovieClip/gotoAndPlay()
at Navigator_MainPage_fla::MainTimeline/mouseDownHandler()
Newbie says
Hi, guys, i am using adobe CS5 and i wan 2 navigate to other scene by clicking on the button “Enter” , but don’t know why i cant enter to the next scene and it pop out something like this as the output and couldn’t move on to the next scene.
So can anyone please help me solve my problem?
ArgumentError: Error #2108: Scene Navigator was not found.
at flash.display::MovieClip/gotoAndPlay()
at Navigator_MainPage_fla::MainTimeline/mouseDownHandler()
ASnewbie says
Thank you!!!! :)
kurosawa says
Hi guys, I really need help with this AS 3 thing..its like a monster to me! Argh..! I just want to move to specific frame (or label..u know the one with flag in properties inspector)..I just cant get my buttons works!
Warning like this came out:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
What does that mean?
Please somobody help me..thanks!
Jack says
Hello there Flash fans!
I got little problem with my project. I want to hide default mouse cursor and change it to my own after click on picture on the stage(it become that picture). It is working fine. But after next click I need to switch it back to default cursor and show it, let the picture lay on the stage like before. I cant find the way how to do that. Could anyone please help me?
This is the initial function I use to switch the default cursor to my own:
stop();
Tuzka_Btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
Mouse.hide();
stage.addChild(Tuzka_Btn);
Tuzka_Btn.mouseEnabled = false;
Tuzka_Btn.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
function fl_CustomMouseCursor(event:Event)
{
Tuzka_Btn.x = stage.mouseX;
Tuzka_Btn.y = stage.mouseY;
}
gotoAndPlay(2);
}
buy zetaclear says
Suitable contribution. I don’t quite totally agree with every little thing you’ve went over, but you absolutely have some excellent points in there.
aandronov says
Hi all,
i didn’t have enpugh time to read all the posts, but here’s my experience:
I got here because of a “1120: access of undefined property” error. Every instance of my buttons was named accordingly but it didn’t work. I changed the “track as” property of the button from “button” to “track as menu item” and it worked.
Elvis Gammage says
Fantastic beat ! I would like to apprentice while you amend your website, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept I am extremely impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you modify it yourself? Either way keep up the nice quality writing, it’s rare to see a nice blog like this one nowadays..
kristen says
Is there a way I can have this peice of code pull in a URL from a XML file instead of having it hardcoded into the ActionScript?
JuJu182 says
Hi,
My code doesn’t work :'( Why ?
My links don’t work :'( I don’t understant
stop();
function button1_clicked(e:MouseEvent):void{
gotoAndStop(“Accueil”);
}
function clip2_clicked(e:MouseEvent):void{
gotoAndStop(“Photos”);
}
function button3_clicked(e:MouseEvent):void{
gotoAndStop(“Concerts”);
}
function button4_clicked(e:MouseEvent):void{
gotoAndStop(“Vidéos”);
}
function button5_clicked(e:MouseEvent):void{
gotoAndStop(“Biographie”);
}
function button6_clicked(e:MouseEvent):void{
gotoAndStop(“Média”);
}
function button7_clicked(e:MouseEvent):void{
gotoAndStop(“Contact”);
}
button1.addEventListener(MouseEvent.CLICK, button1_clicked);
button2.addEventListener(MouseEvent.CLICK, button2_clicked);
button3.addEventListener(MouseEvent.CLICK, button3_clicked);
button4.addEventListener(MouseEvent.CLICK, button4_clicked);
button5.addEventListener(MouseEvent.CLICK, button5_clicked);
button6.addEventListener(MouseEvent.CLICK, button6_clicked);
button7.addEventListener(MouseEvent.CLICK, button7_clicked);
Caleb says
Hi i am building an interactive digital piano in Flash CS5 and i have the whole thing done as far as clicking on the keys. However, i was wondering if you knew some coding to get my buttons to work by key stroke command because i would like to be able to play it with the computer’s keyboard.
thank you,
fellow flashthusiast
Jamal Languell says
I always visit your weblog every day to learn brand new matters.*”,~`
Naeem Ahmed says
Hi !
I m naeem From pakistan!
I want to make my wesite in flash .i make a flash for my site but i cant make a hyperlink ,I still make but its not working !any body Can complete my project ???????????
please help me
I m new user of flash ,
I shall be very thankfull to u .
Naeem Ahmed says
Please help me quick !
my email
mobilw number :+923077741470
Samah says
Hi, Help me please?!
i want to know the code for the button (in scene 1) is go to scene 2.
Also,
i made a button and i want it to open word decument.
becky says
hey im pretty new to this, so how do you make a button (in flash file 1) to link to another flash file (flash file 2), so when you click the button (in flash file 1) flash file 2, opens up in flash file 1? any help please :)
Samah says
I am similer to you.
Please help me. I have a project and the deu day is very close.
Samah says
Oh, i forget that i am working in Flash CS4 ( ActonScript 3.0)
Hardeep Dhiman says
Thank you!!!! :)
joshua says
I am on a school project and need the code for my button when clicked it shows the larger of the button image. PLease help
Dangaioh says
Thank you… I am a complete novice in regards to action scripting, and what has been blogged, questioned, resolved/answered has been a true God send… the postings here are quite helpful.
Again, thank you.
Sincerely,
– Dangaioh
taylynne says
Thank you for this… I’ve been using flash 8 for so long… I would just put the script
on(release){
gotoAndPlay(xx);
}
on the button. I figured I should give actionscript 3 a chance and try out a newer flash, and I was.. rather lost. This helped a lot. =D
Thank you again
AdobeEmployee says
Hi all! It looks as though you all are having some minor problems with your Cs5 installation of Flash Professional. Please email me here at and forward any questions or comments to me. If you just simply can’t figure out the problem then please feel free to send your game in an attatchment for me to take a look at.
– AdobeEmployee
Sarah says
Hi, I’m using flash builder and am trying to use a button to increase a variable, but it is giving me error 1180 (Call to a possibly undefined method)…what should I do??? I’ve looked online, and it doesn’t really help me
Site Here says
I’m not sure where you are getting your information, but great topic.
I needs to spend some time learning much more or understanding more.
Thanks for excellent info I was looking for this information
for my mission.
24 hour emergency locksmith says
Can I simply say what a relief to discover an individual who really
knows what they are talking about over the internet.
You certainly know how to bring a problem to light and make it important.
More people must check this out and understand this side of your story.
I was surprised that you’re not more popular because you definitely have the gift.
Costco Glasses says
soooo, there was a time when i would play yu gi oh yea many years in the past.
We’re about to shift, and getting a moving household kind of backyard sale. We have over five-hundred yu gi oh yeah cards that i would prefer to eliminate. I have a few rare kinds but i do not really take care of them therefore i dont wanna work their way through the difficulties of researching them. The amount of must i charge to trade my cards?
http://tinyurl.com/vendpater19546 says
I actually really want to save this specific posting, “Making a button work in Flash CS3,
CS4 or CS5 with ActionScript 3.0 – it
healthy living says
Hello my family member! I wish to say that this post
is awesome, great written and come with approximately all vital infos.
I would like to look more posts like this .
dandy says
HI! I am 50 years old and a novice in flash I made a flash movie ,i used a gif and a jpeg picture, i imported music,i made play and stop music buttons (It works),but please help me how to do , to make a button ,(a play button) when you click on it to start the flash movie and music together!Sorry for my english!
dev says
i want a solution,
btn2.addEventListener(MouseEvent.CLICK,nextf);
function nextf(myNextEvent:MouseEvent):void{
trace(“hi”);
}
i created a button name btn2 and created a separate actions layer and typed this codings but im gettting a problem ever
1046: Type was not found or was not a compile-time constant: btn2.
please help me
Gary says
In making the buttons connect to a site on the web I used this script for the first button and it worked . I also gave the button a name in the instance name:
my_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest(“http://www.nytimes.com/”), “_blank”);
}
I successfully created an email link with another button using:
mc.addEventListener(MouseEvent.CLICK, sendEmail);
function sendEmail(e:MouseEvent):void{
navigateToURL(new URLRequest(“mailto:1863olympia.com”));
}
My problem is when I added a third button that linked to another web page. I thought all I had to do was simply tweak the first script by simply changing the instance name of the button and the URL address. Not only dis this not work but it screwed up the previously working buttons. I got this message — duplicate function definition. Right now I am a bit lost with fixing the error. Any assistance you could provide would be greatly appreciated
SVG says
TO DENNY: the actionscript MOUSE_OUT event will fix that issue.
danny says
AS3 BUTTON BLOOPER: coding a button for the DOWN and UP states are great and dandy, however what if one SLIDES off a button?, I noticed that (for example) in a game if we press the LEFT button so a character can move it will of course move…when we go UP it will stop…when we decide to SLIDE off the button the character will continue to be active. I don’t know if that’s an AS3 bug but I thought it was interesting.