…and especially enthusiastic about motion tweens in Flash…
So there have been a number of questions on my kinda recent post about making a button in Flash CS3 or Flash CS4 using ActionScript 3.0. I will do the next couple posts on how to do the things in the questions (and actually check em out in Flash, and make an FLA to download). Update: More links about buttons and button code at the end of this post.
So if you haven’t already read or don’t know how to make a single button, head on over to the post linked above. Here, I’ll continue on to multiple buttons.
Say you have a couple buttons on a page, and you want one to go to one URL, and the second one to go to a different URL - you need to change your function names in your code so you don’t have multiples with the same name. So, you would need to do something like this:
thumbsdown_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler); function thumbDownHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://msdn2.microsoft.com/en-us/silverlight/default.aspx")); } thumbsup_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbUpHandler); function thumbUpHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://www.adobe.com/devnet/flash/")); }
Note the thumbDownHandler and thumbupHandler in the code.
The source file: Mutliple buttons to URLs
So some people are instead targeting multiple frames. In that case, the code would look like this:
stop(); first_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1); function mouseDownHandler1(event:MouseEvent):void { gotoAndStop(5); } second_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2); function mouseDownHandler2(event:MouseEvent):void { gotoAndStop(10); }
The source file: Mutliple buttons to frames
MORE INFORMATION ON BUTTONS:
This blog specializes in the new motion model of Flash CS4, and is brought to you by team tween of Flash at Adobe. The blog will includes tips, techniques, and info on tweening in Flash using the Timeline and Motion Editor (as well as some stuff about motion runtime with code). From time to time, we might also talk about ActionScript 3.0. So if you're interested in tweens, this blog is for you. We also want to hear your feedback in the comments. All views expressed here are those of the authors, and do not necessarily represent the opinion or views of Adobe Systems Inc.

Chris
March 26th, 2008 at 9:04 am
Can you please tell me what to add to this code to make the page show up in the same window (of the browser?)
Thomas
March 27th, 2008 at 11:16 am
Hello Flashthusiast,
Here I am again, in need for some help :-( I made a flashmovie in as3 and added three buttons that need to refer to different URL’s. Two of them work (home_btn and mixlawax_btn) but when I add the third button (moremusic_btn) I get an error report?
This is how I added my code in the actions pane:
What went wrong?? I can’t findout how to make all three work. And my geuss was if two buttons work the third would work too if I just copy past the code and adjust the btn name and URL to refer to…
Really hope you can help me out, I tried every possible thing to make it work, but I think I need a pro like you ;-) to set me back on track!
Thanks in advance.
Grtz
Thomas
Jen, a flashthusiast
March 27th, 2008 at 11:48 am
Hey Thomas!
In the moremusic_btn button, try renaming “thumbUpHandler” to a unique name, like thumbUpHandler2 or otherUpHandler. It looks like it’s conflicting with the “thumbUpHandler” function in the home_btn button.
Hope that works,
Jen.
Jen, a flashthusiast
March 27th, 2008 at 12:00 pm
Hey Chris,
You can set the target window right after the URL, pretty similar to AS2. So you can modify the navigateToURL linke as follows:
Hope that works for ya,
Jen.
Anita
March 30th, 2008 at 12:35 am
I’ve also tried this, and have sort of the same kind of problem with one of the buttons not working. This is my code:
Both buttons, for some mysterious reason, go to the same page (the first URL specified), and I cannot find out what I’m doing wrong. I didn’t name anything the same, and I tried copy/paste to find out if I had overlooked an error in button two, but no. Help… :-)
peterd
March 30th, 2008 at 10:38 pm
Anita,
I’m not seeing the same issue locally. What about if you change the URLs to http://www.adobe.com and http://www.apple.com. Do they both still go to the same domain? What happens if you click the second button first? Do they always go to the first button’s URL?
Peter
Bav
April 1st, 2008 at 9:40 am
Hi, all
can anyone help me with this code?
I am trying to create 5 buttons that jump to different scenes
here is the code for one:
the problem is, I keep on getting this error:
what I am doing wrong here? any advice
please
jennicandance
April 2nd, 2008 at 10:24 am
I have had the same problem so if anyone can answer that it would help me out too…
Can someone post on how to create button rollovers using AS3? I’m having some trouble…
Thanks
Aisa chin
April 2nd, 2008 at 11:35 am
Hi there,
I work for a Telecommunications company in Calgary and came across your name.
Are you able to contract you to come out to calgary to give a presentation on Flash through Adobe or can it be through you.
And if you would be interested please do let me know. We would love to have you speak for us.
Thanks,
Aisa
Aisa Chin
April 2nd, 2008 at 11:40 am
Hi there,
I am emailing from the creative team at a telecommunications company in Calgary.
We would like to know if we are able to bring you in to talk about flash here in Calgary. Is that done through Adobe or can do you it as an on the side thing?
We would love to have you speak for us on flash.
It would be great to further discuss this if you could email me.
Thanks very much,
Aisa
heather
April 3rd, 2008 at 10:55 am
I was getting Error #1009 as well and figured out what was causing it. The keyframe in my “actions” layer where I applied by button action script occurred in frame 1, but the instance of my button didn’t appear until frame 5. Since the action occurred before the button showed up, that’s why I got the error. When I moved the keyframe of my actions layer to frame 5 (the same frame where my button first appears), the error went away.
For a better explanation, see this website:
http://curtismorley.com/2007/08/15/flash-cs3-flex-error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/
Jen, a flashthusiast
April 5th, 2008 at 6:42 pm
Hi Aisa,
Unfortunately speaking and travel is generally up to Adobe. For the next while I’m pretty swamped with working on the software - but there might be someone available from Adobe (they do events and traveling in canada), or even from the local user group (I think it’s still running) who might be available to speak.
Best of luck,
Jen.
Bav
April 12th, 2008 at 2:55 am
right thanks, i have managed to sort out the errors. Now I have another problem (its just goes on) I have 5 buttons but they all seem to be jumping to scene 1, however I did managed to make the second button to jump on scene two. As soon as I add the third button it jumps to the first scene here is the code that I am applying to my scenes
and so on…..
any advice thanks ….
Dave
April 17th, 2008 at 7:16 am
Hi Jen - thanks for a great site - load of really helpful information.
I’ve created a flash menu bar which slides out from the right to reveal sub-menu options which I want the user to be able to click on to navigate further into the site. I’ve included the URL in my message to you - if you have time, would you please follow the URL, click on the “portfolio” button and offer some advice on how I can make the submenus active as they just take the property of the “portfolio” button at the moment. For the record, the “portfolio” button has been created as a button with up & over states while the submenus are purely text written with hyperlinks on the over state of the button.
Hope that all makes sense?
Xinivion
April 21st, 2008 at 5:43 pm
Hey i have looked and looked but have found nothing this here ismy last hope… i have a bunch of buttons on diferent keyframes and then i have buttons linking to each key frame.. i when there are buttons on the other keyframes it gives me a silly error message… is there a way to tell the comp. wut frame the button is on?
Monique
April 22nd, 2008 at 6:38 am
Im a little new in the CS3 version, so Im kinda confused…
I have a menu of 4 buttons inside a movie clip, how do I give the actions to the buttons there? should I do it in a different action layer or in each button?
Here is what I have so far, im not sure I have it right… I’ve written it like that for every button???? thnxs :)
Monique
April 22nd, 2008 at 6:54 am
this is for the other buttons???
Jen, a flashthusiast
April 22nd, 2008 at 11:15 am
Hi Xinivion — Make sure that the button code for the buttons at that keyframe is at the same frame. So if you have “buttonA” and “buttonB” at frame 10, make sure the code for that button is on a keyframe at frame 10 as well.
Jen, a flashthusiast
April 22nd, 2008 at 11:18 am
Hi Monique - Your first code snippet looks fine. The second one, make sure your mouseDownHandler’s match (one of them has a 2 - you should add the “2″ to the handler name in the first line.)
Monique
April 23rd, 2008 at 8:19 am
Thank you Jen, I tried doing what you said but, this is what I get with all the buttons… Im doing the action in the last frame of the timeline of each button inside the movie clip????
should I do this in a different layer for actions inside the timeline?
This is the errors i get
Tom
April 29th, 2008 at 10:38 am
Hi flashthusiast,
I developed a flash site for a photographer friend of mine and she is thrilled with it. She especially loves the opening, which resembles an unveiling. With that said, I am not happy with the funtionality of my buttons. If you move your mouse too quickly they stay in their rollover state. Is there a better approach to the functionality of these buttons. Right now, leaving the ‘hit’ area triggers the roll off state. Can you have a look? and maybe point me in the right direction? http://www.kristensomodywhalen.com
Thank you Jen, for your time.
Tom
tom2
May 2nd, 2008 at 7:46 am
hey there,
thx for your help on setting up multiple buttons…
here is MY question, one of my scenes i am jumping to from one of my buttons events has an embedded .flv playing. when i hit any other button for another scene, the sound from the movie continues to play.
how can i prevent this from happening? i’ve tried stop FLV, and stop all sounds etc, to no avail.
cheers,
t.
zall
May 4th, 2008 at 2:31 am
what is i have lots of buttons (15 for example). each of them should call the same function with different paramets. navigateToUrl for exmple. is there any other way to do this exept creating different handlers for each button.
with as 2 i did like that: i difined a url property for each button and used only one function. it must be the way to do the same in as3. i dont want to do 15 listeners and handlers
Dom
May 13th, 2008 at 6:37 am
Hi Everyone,
Really need some help with linking buttons to different scenes within my flash website that I am building. Also adding a stop function so that each scene stops before it moves onto the next. I used to be able to do this in AS1-2 but am totally confused by AS3. Can anyone help me? I would really appreciate it!
Thanks Dom.
Lisa
May 13th, 2008 at 11:16 am
Jen,
I’m new to Flash and trying to get buttons to work, need to use buttons to move back and forward by frame…your site has been great!
Here is my code from from frame 4, action layer (each frame in action layer has similiar code, 18 frames in all); my problem is listed below. I did my Next button code first…worked well, clicked from frame to frame just like I needed it too….then I started on the Back Button code…yikes
Thanks.
The Problem: (example)
on frame 3, click back button, takes me to frame 2…then I click the Next button (still on frame 2) and it takes me to frame 4…I click the back button while on frame 4 and it takes me to frame 1!!!
Ali
May 17th, 2008 at 11:04 am
Dear Jen,
My comment is more about the AS in general. I’m a designer and not a CODER and I think Flash is not really a designer friendly application and the obvious reason for that is the AS language. May be time has come for Adobe to develop ways to address this issue instead of developing AS v4 :))) . I don’t know what they think at Adobe, but in my opinion designers are designers and coders are coders. Flash is not really for designers ;-). It is similar to think that in order to work with photoshop you need to learn VB :)))
Best Regards
Ali
Amy
May 19th, 2008 at 9:27 am
Just popping in to say thank you so much for the help! Like Ali (who posted right before me), I’m a designer, not a coder. So Flash gives me problems sometimes, but your blog has been a big help. Keep up the great work!
Kevin
May 24th, 2008 at 6:25 am
I get these errors:
With this script
Scene 1:
Ashford : Frame 1
Ascalon : Frame 1
Diane
June 1st, 2008 at 2:05 pm
Could someone help with code for BACK buttons using AS3? My NEXT buttons work just fine but when I click on the BACK buttons, they do go back to the specified frame and play that part of the animation and they do stop on the correct frame after the animation sequence is done playing, BUT when I click the NEXT button, rather than just playing the next animation sequence, it blows right through the next animation sequence and goes to and plays the following one. This is all on one timeline and one scene. Here is the code I’m using:
THANK YOU!
Harry
June 2nd, 2008 at 12:03 am
Hi Jen
I am trying to make a survey type programme where the users clicks on either Yes or No on each frame. Then in the last frame it has the results of the survey. So the surveyer is able to see which questions the user answered yes and no to. I am having trouble with the last frame. Putting the answers into a dynamic txt box. Here is the code
Thanks!
Bibiana
June 15th, 2008 at 5:34 pm
Hi Jen!
If you could help me, I have 3 buttons. 2 of them dont have problem, but the middle one is giving me the error:
why? thanks for any help!!
this is my code:
Chris
June 16th, 2008 at 4:46 am
Hi every body,
Can you help me with Actionscript 3.0 please?
I have a vertical scroll with 10 buttons (but_one, but_two, … etc.) and I have 10 FLV movies (mov_one, mov_two, … etc.) and I need to link each button to one of these movies so I can see one movie at a time (in the same position) every time I click on one of the buttons.
I have all the movies in one layer and I don´t know if it is a problem, cause when I tried to link each movie with one of these buttons with actionscript, I could see only the first movie (by clicking but_one) and when I click on any other button the first movie does not disapiared and or the first movie overlaps with the other movies when I click them.
Please, any body their can help me??
Thanks alot!
Amy Berg
June 17th, 2008 at 9:11 am
Hi, there –
I have a file with three scenes. They all reference buttons that navigate to content in “Scene2.” I can use these buttons to navigate to Scene2 from both Scene1 and Scene3, but once inside Scene2 they no longer work. However, if I play straight through Scene1 without navigating at all, the buttons in Scene2 will work. None of my code has changed and my file was working yesterday.
Any suggestions?
Thanks,
Amy
MKane
July 7th, 2008 at 7:33 pm
Hello,
I am writing for help because I am at my wits end. I am trying to make my flash portfolio using these instructions. There are 12 buttons, each going to a different frame. (I have put the frames right next to each other, not on 5 and 10 ect I don’t know if that is bad) Anyway, everytime I put in your code and (and alter it to my specs) It tells me mouse event is wrong. Now I have tried working with it, but really, only the first button would end up working.
Does anyone know what I am doing wrong? I would be so grateful for some guidance.
All buttons are btn1-btn12 and Frame1-Frame12
Jake
July 17th, 2008 at 4:47 pm
***MODERATOR PLEASE DELETE LAST POST ‘JAKEMOBBS’***
Hi Jen,
Hope you can help me..
Here’s my AS3 code for buttons leading to URLS (hoping to open in the same window):
it works fine when I test it in flash, but when i actually upload it, none of the buttons go anywhere..
any thoughts? thanks in advance..
Jake
Rachel
July 31st, 2008 at 4:49 am
Hi Jen,
I have the same problem as Amy Berg (June 17th) - is there any way to make buttons work while navigating around frames in scenes?
Would appreciate any feedback you could give, thanks!
Rachel
Jen, a flashthusiast
July 31st, 2008 at 9:32 pm
Hi Rachel and Amy,
I hope I’ve covered this in a new post I made about buttons and scenes and uploaded some FLAs: http://flashthusiast.com/2008/07/31/creating-buttons-that-link-to-different-scenes-using-actionscript-30/.
It sounds like you may need to make sure to target the scene in your button code, because if you’re pointing to frames Flash may get confused once it’s published (in a SWF, there’s only one sequence of frames).
Does that work/help?
Jen.
Eugene Stadnichenko
August 16th, 2008 at 10:26 am
Thank you so much! you definitely helped me big time today… i’m a total n00b in Flash all around… Have been looking up a fair few tutorials and yours is the first that made complete sense and everything is working for me! thanks again
Thomas
August 23rd, 2008 at 3:54 am
my new site works, wanted to thank you as well for your assistance, look at my site it’s really cool…I think ;-)
Peace
Thomas
Thomas
August 23rd, 2008 at 3:55 am
http://www.morecult.com that is :-)
Jen, a flashthusiast
September 4th, 2008 at 10:30 pm
great stuff Thomas - love the Flash work! keep it up!
tomripl
October 6th, 2008 at 1:30 pm
Anyone can help with this error message?
krizzallid
October 17th, 2008 at 3:56 am
hi…
i want to know how to stop all action.
actualy i put a flv file in difference keyframe in one symbol movie clip.
in sence i put a button back
but if ther back…flv file stilll play
Emma
November 5th, 2008 at 9:45 am
I have been trying to add to my animated button but can’t find out how to jump to another scene.
Cuz all my scenes are on a new scene not on the frames as the buttons.
Please if any1 knows how please email-me
Jen deHaan
November 5th, 2008 at 10:27 am
Hi Emma,
Try this blog entry for info on making buttons that jump to other scenes:
http://flashthusiast.com/2008/07/31/creating-buttons-that-link-to-different-scenes-using-actionscript-30/
Christie
November 13th, 2008 at 4:34 pm
I am just tackling my first web site in Flash. I have set everything up in my main timeline on a content layer. I have created a layer for “action” that spans the length of my timeline. I have about 620 frames right now. I have a ton of buttons throughout the timeline in various frames. My two main buttons are “portfolio_btn” and “contact_btn”. Those two two buttons appear at the bottom of all keyframes. I have started my code for the buttons and it looks like this:
From Frame 1, I can click “portfolio_btn”, and it takes me to the correct frame. From that frame, I click the “contact_btn” and again land where I am supposed to. But, from that frame, I click the “portfolio_btn” and nothing happens. Where am I going wrong?
I get this error message:
Any advice will help because these are just three of many clicks I need to code correctly.
Thanks :)
Skeet
November 14th, 2008 at 6:20 am
Hey Christie,
I find if you use IF Else statements rather than assigning each button a new handler, it works better.
Like so:
You might also have to create a container movie clip (called main_mc here) to put everything in - you’d then change the code above to:
main_mc.gotoAndStop("portfolio");…and so on.Hope this helps!
Skeet
Chloe
November 16th, 2008 at 4:37 am
Hi ive tried to use this code in my exsisting document but to no effect, i cant seem to figure out why it wont work but my knowledge of AS3 is very little can any one help with the beow code. Its only the anmation_mc which wont work
Thank you
dora
December 13th, 2008 at 6:13 pm
I am having troubles translating my idea into visuals.
…so i created a bunch of buttons on a stage, each one once clicked zooms into a bigger image with text elaborating on it. the problem is every time i click on a button the other buttons show and overlap the zoomed image. how can i create them in a way that once clicked the other buttons won’t show, or disturbed the intended info? i tried putting them in one layer, distributing them… but i am running out of thought so your help would be great!
Thanks!
Roxy
December 15th, 2008 at 5:49 am
Hi everyone!
Im having trouble creating multiple buttons in one keyframe of my flash animation using CS3…
This is the code I am using to navigate to a test URL (yahoo)
purple_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler);
function thumbDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.mixlawax.com”));
}
Which works fine… But how can I alter this code to make the other 2 buttons on my page work (and navigate to different URL’s?)
Im sure its fairly straightfoward, but when i paste this code and change the instance name of the button, i.e,
green_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler);
function thumbDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.hotmail.com”));
}
I get this error message:
1021: Duplicate function definition.
Roxy
December 15th, 2008 at 5:51 am
The code thats working (the first code pasted above) navigates to yahoo in my test- the URL is milawax.com as i copied and pasted from above!
:)
Roxy
December 15th, 2008 at 7:20 am
I’VE FIXED IT! Ok for anyone who is as stupid as me- to do multiple buttons, you need to change the instance name, handler prefix, and obvs the URL. Thats all.
SO- this is the code you need- notice the differences between the two.
purple_btn.addEventListener(MouseEvent.MOUSE_DOWN, purpleHandler);
function purpleHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.yahoo.com”));
}
green_btn.addEventListener(MouseEvent.MOUSE_DOWN, greenHandler);
function greenHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.google.com”));
}
Its so easy when you know how eh?!
Sorry to everyone for being so dumb in my posts above!
:D
Hi
December 22nd, 2008 at 4:33 am
Hi
Does this work in frames?
I got it all to work with multible URLs and multible buttons.
I works fine when I test it in Flash - but doesn’t - when I test it in Dreamweaver with the index-file and all.
Can somebody help me?
Thank you SO MUCH!!!
Biber gazı
December 24th, 2008 at 10:43 am
I wanna learn flash :(
Squidge
December 26th, 2008 at 3:27 pm
Hey,
I got CS4 for Christmas, and I can’t get my buttons to work. I had one button (to go to the next frame), and it works fine. Then I added another button (to go back a frame), which also works fine. But when I go back a frame, then click next, it skips to the frame after the last one I was on. Can someone help please?
Thanks.
Squidge
December 27th, 2008 at 5:20 am
If it helps, this is what came up in the output when I went through and pressed all of the back buttons:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame1()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerA()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerB()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerC()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame4()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerD()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame5()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerE()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame4()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler2()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame5()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler3()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler4()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame4()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler2()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame5()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler3()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandler4()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at WelcometomyChristmas_fla::MainTimeline/frame6()
at flash.display::MovieClip/gotoAndStop()
at WelcometomyChristmas_fla::MainTimeline/mouseDownHandlerF()
Simon
December 27th, 2008 at 6:20 pm
Hello Jen,
Thank you for putting together such a good blog.
I used this code on a different flash movie with instances of the same buttons. When I try it in this movie I get this in the compiler for all four of the buttons:
The class or interface ‘MouseEvent’ could not be loaded.function autonotify1Handler(event:MouseEvent):void {
Here is the code:
autonotify1btn.addEventListener(MouseEvent.MOUSE_DOWN, autonotify1Handler);
function autonotify1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.santamonicarealestatesearch.com/real-estate-autonotifyform.html”), “_self”);
}
realmlsbtn.addEventListener(MouseEvent.MOUSE_DOWN, realmlsHandler);
function realmlsHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.santamonicarealestatesearch.com/real-estate-mls.html”), “_self”);
}
marketvaluebtn.addEventListener(MouseEvent.MOUSE_DOWN, marketvalueHandler);
function marketvalueHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.santamonicarealestatesearch.com/real-estate-market-value.html”), “_self”);
}
homebtn.addEventListener(MouseEvent.MOUSE_DOWN, homeHandler);
function homeHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.santamonicarealestatesearch.com/”), “_self”);
}
Any information you or anyone else can give would be much appreciated!
Thanks!
Simon
Ben Parer
January 29th, 2009 at 11:01 am
I have a couple of buttons with over, out and down events.
over and out work fin but as soon as down happens and I jump to another frame (ie start on frame one jump to 2 or 3) the over and out functions return #1009 error. I know this is probably really basic as3 but I cannot wrap my head around it for the life of me. I get the fact that it can’t locate either the object or frame label but I don’t know why.
//// WHO BUTTON //////////////////////////////////////////////////////
who_btn.addEventListener(MouseEvent.MOUSE_OVER,who_btn_over);
who_btn.addEventListener(MouseEvent.MOUSE_DOWN,who_btn_down);
who_btn.addEventListener(MouseEvent.MOUSE_OUT,who_btn_out);
function who_btn_over(evt:MouseEvent):void{
this.who_btn.gotoAndStop(”ON”);
}
function who_btn_down(evt:MouseEvent):void{
this.gotoAndStop(”intro_who”);
}
function who_btn_out(evt:MouseEvent):void{
this.who_btn.gotoAndStop(”OFF”);
}
//// WHAT BUTTON //////////////////////////////////////////////////////
what_btn.addEventListener(MouseEvent.MOUSE_OVER,what_btn_over);
what_btn.addEventListener(MouseEvent.MOUSE_DOWN,what_btn_down);
what_btn.addEventListener(MouseEvent.MOUSE_OUT,what_btn_out);
function what_btn_over(evt:MouseEvent):void{
this.what_btn.gotoAndStop(”ON”);
}
function what_btn_down(evt:MouseEvent):void{
gotoAndStop(”intro_what”);
}
function what_btn_out(evt:MouseEvent):void{
this.what_btn.gotoAndStop(”OFF”);
}
Dee Dee
February 9th, 2009 at 7:14 pm
I have used the original article on this page and my buttons work fine, however I do not get the curser change when I rollover my links. My .fla is 305 frames long, it is an intro header and at the end I used the script when the navigation links appear in the final frame. I have placed the action listed above in the last frame.
Jen deHaan
February 10th, 2009 at 3:07 pm
@Dee Dee: I’m guessing that you’re using a movie clip instead of a button instance. If so, add the following line (changing “mc” to your instance name(s)):
mc.buttonMode = true;
Joe
February 13th, 2009 at 3:50 pm
So, I used your advice on changing function so I could use various buttons and it worked great. The only problem I am having now is that when I click a link it uses an open window and makes a new tab, then it also opens a new window, so basically its opening the link twice. How do I go about fixing this?
This is the AS code I am using:
[quote]nsplat.addEventListener(MouseEvent.MOUSE_UP, goLayersSite1);
function goLayersSite1(Event:MouseEvent):void {
var layersURL:URLRequest = new URLRequest (”http://www.mymaniak.com”);
navigateToURL(layersURL);
}[/quote]
Joe
February 13th, 2009 at 3:51 pm
This is the code:
nsplat.addEventListener(MouseEvent.MOUSE_UP, goLayersSite1);
function goLayersSite1(Event:MouseEvent):void {
var layersURL:URLRequest = new URLRequest (”http://www.mymaniak.com”);
navigateToURL(layersURL);
}
misi
February 16th, 2009 at 1:56 pm
thanx a lot for this info, been very frustruated becouse of changes in AS 3.0 :/
chelsea
February 23rd, 2009 at 1:50 am
Hi,
I am having problems with my code. I am trying to make a website with a menu that contains 3 buttons one the left side next to a box on the right that will have text in it. I’m trying to make each button display different text in the box. So far I have 3 scenes with the exact same layout except for the text (the text changes per scene). I am able to create a button that will successfully link the first scene to the second scene, but I can’t get any of the other buttons to work. This is the code I have used - could you either please tell me what I’m doing wrong or give me an easier way to do this? Thank you!
Scene 1 code:
stop();
home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler7);
function mouseDownHandler7(event:MouseEvent):void {
gotoAndStop(1);
}
travel.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler8);
function mouseDownHandler8(event:MouseEvent):void {
gotoAndStop(5);
}
stay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler9);
function mouseDownHandler9(event:MouseEvent):void {
gotoAndStop(6);
}
Scene 5 code:
stop();
home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler4);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndStop(1);
}
travel.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(5);
}
stay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler6);
function mouseDownHandler6(event:MouseEvent):void {
gotoAndStop(6);
}
Scene 6 code:
stop();
home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler7);
function mouseDownHandler7(event:MouseEvent):void {
gotoAndStop(1);
}
travel.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler8);
function mouseDownHandler8(event:MouseEvent):void {
gotoAndStop(5);
}
stay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler9);
function mouseDownHandler9(event:MouseEvent):void {
gotoAndStop(6);
}
chelsea
February 23rd, 2009 at 1:50 am
^^ Oh and I’m using CS4
chelsea
February 23rd, 2009 at 1:52 am
…and the Scene 1 code posted wrong it’s actually:
stop();
home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {
gotoAndStop(1);
}
travel.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(5);
}
stay.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(6);
}
Sorry! It’s almost 5am and I haven’t slept yet :P
Deborah
February 25th, 2009 at 3:24 pm
I have a similar problem where I have created a dynamic menu all with actionscript to load an external image gallery. However, it seems that the created label made by the dynamic textfield is preventing some of the hit state.
Here’s my code…..
var myPics:Array = new Array (”image1″, “image2″, “image3″, “image4″, “image5″, “image6″, “image7″);
//get the number of items in the array
//use this as the value of variable “totalItems”
var totalItems:int = myPics.length;
//create function to make add button labels
function createLabels():void {
for (var i:int=1; i<=totalItems; i++) {
//create text field to act as button lanel
var btn_label:TextField = new TextField();
this.addChild(btn_label);
btn_label.name = “image”+i;
//create text format class to format our text fields
var format:TextFormat = new TextFormat();
format.font = “Verdana”;
format.color = 0xFFFFCC;
format.size = 14;
//assign text format class to text field
btn_label.defaultTextFormat = format;
//set label coordinates
btn_label.x = -270;
btn_label.y = -205 +(i*48);
//set text for button labels
btn_label.text = “Image “+i;
//btn_label.setChildIndex(index 5);
}
};
//create a function to make dynamic menu
function makeMenu():void {
for (var i:int=1; i<=totalItems; i++) {
//create a new class
var myBtn:galleryImageBtn = new galleryImageBtn;
this.addChild(myBtn);
myBtn.name = “image”+i;
myBtn.x = -235;
myBtn.y = -186+(i*48);//this may change based on your button’s dimensions
myBtn.addEventListener(MouseEvent.CLICK, btnPress);
}
};
makeMenu();
createLabels();
//create a new class
var myFrame:frame = new frame;
this.addChild(myFrame);
myFrame.name = “frame”;
myFrame.x = 200;
myFrame.y = 70;
//create loader to load images
var myLoader:Loader = new Loader();
//function to run when nextBtn is pressed
function btnPress (event:MouseEvent):void {
//use instance name of the button that triggers the event
//as the target path for the images in the images folder
this.enabled = true;
myLoader.load(new URLRequest(”galleryimages/full_images/”+event.target.name+”.jpg”));
addChild(myLoader);
myLoader.x = -100;
myLoader.y = -140;
};
Thank you for your helpful site.
Zaphod
March 11th, 2009 at 1:11 am
Hello
I have a mind boggling Error 1009 problem. It is annoying to the point of disrupt my sleep in the middle of my dream about lots of kittens in my house doing the choirs for me. (I just woke up at this time to fix the problem)
I have a Main Menu fla, which has 7 buttons, each of them (except the middle one) displays an animation and links to an url. But the center one should just display an animation and go back to frame 1, where others can be clicked again.
When I say gotoAndPlay(1); at the last frame of my fla, where the center button animation ends, I get Error 1009, I understand my frame1 is just a frame with actionscript (and the buttons) to wait for clicks, and is not a movie clip. But I can’t find a workaround for this problem with my 2 days of flash knowledge.
Here is the code for frame 1 (7 buttons, all instantiated and named)[Couldn't get mouseOver animations to work so I commented them]
stop();
panda_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(681);
}
/*panda_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
function mouseOverHandler(event:MouseEvent):void {
gotoAndPlay(505);
}*/
zoo_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndPlay(10);
}
/*
zoo_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler2);
function mouseOverHandler2(event:MouseEvent):void {
gotoAndPlay(530);
}*/
color_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndPlay(155);
}
/*
color_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler3);
function mouseOverHandler3(event:MouseEvent):void {
gotoAndPlay(580);
}
*/
shape_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler4);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndPlay(230);
}
/*
shape_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler4);
function mouseOverHandler4(event:MouseEvent):void {
gotoAndPlay(605);
}
*/
story_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndPlay(305);
}
/*
story_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler5);
function mouseOverHandler5(event:MouseEvent):void {
gotoAndPlay(630);
}
*/
season_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler6);
function mouseDownHandler6(event:MouseEvent):void {
gotoAndPlay(375);
}
/*
season_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler6);
function mouseOverHandler6(event:MouseEvent):void {
gotoAndPlay(655);
}
*/
number_button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler7);
function mouseDownHandler7(event:MouseEvent):void {
gotoAndPlay(85);
}
/*
number_button.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler7);
function mouseOverHandler7(event:MouseEvent):void {
gotoAndPlay(555);
}
*/
And here is my last frame, where the center button animation ends:[Navigate to the same URL commented, that url call was how I dealt with the problem in the testing phase]
stop();
/*navigateToURL(new URLRequest(”/Main.html”), ‘_self’);*/
gotoAndPlay(1);
TypeError: Error #1009: Boş nesne başvuru özelliğine veya yöntemine erişilemiyor.
at Menu_fla::MainTimeline/frame1()
(Never mind the turkish there!)
Thanks a lot, The kids who will play with this preschool children education program will pray for you if you can help me ;) [Otherwise they'll pray for just more candies, or chocolate]
Joe
March 20th, 2009 at 11:22 am
MODS PLEASE DELETE LAST 2 POSTS BY JOE
Bryan
April 4th, 2009 at 2:49 pm
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?
Phey
April 4th, 2009 at 6:57 pm
How do i end this Actionscript and convert this to multiple buttion actionscript? Help!! Please
groundswell_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
function buttonClicked(event:MouseEvent):void
{
gotoAndStop(”groundswell”);
}
stop();
Bryan
April 6th, 2009 at 10:19 am
Is there anyone out there?
Bryan
April 7th, 2009 at 6:03 am
It’s OK… I figured it out on my own….
Krystina V.
April 7th, 2009 at 8:01 am
In Adobe Flash CS4, when I make buttons and try to link them to other scenes in my flash animation, they don’t seem to work.
I’ve tried multiple scripts to make it work, but it doesn’t. Is there any alternative way?
Paolo
April 9th, 2009 at 5:54 am
I created 4 buttons in Flash CS3. I am having the same problem with the target window opening a new window.
I used the suggested:
thumbsup_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbUpHandler);
function thumbUpHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.adobe.com/devnet/flash/”), “_self”);
}
When I upload it through Dreamweaver the buttons still open a new target window even with the _self.
Can anybody help me out on this one?
David Y
April 17th, 2009 at 1:16 pm
Thanks so much for this great info, Jen. I had been very frustrated since it seems Adobe no longer includes instructions with their products. It is wonderful that you are willing to share your expertise.
Yohei Chino
May 5th, 2009 at 7:07 pm
How do you create a download button in flash cs 4 as 3. Thanks.
Rick
May 19th, 2009 at 3:51 am
Hi Jen,
Thanks for your great tutorial, I was able to create multiple buttons in CS3 and they work fine. I am stuck on one issue though: How to make the selected button remain in its “over/down” state when selected. The button is grey when unselected and turns orange when you roll-over - it should stay orange when selected but is does not.
Your help on this matter would be most appreciated.
Kind Regards,
Rick
Me
June 9th, 2009 at 12:57 pm
This has been COMPLETELY unhelpful.
Sam
July 1st, 2009 at 10:56 am
Jen, you rock. ty
sirwolliam
July 7th, 2009 at 11:35 am
Hi. I’m making an Autorun CD using Flash CS4. I need a button that links to the content of the disc, so the user can “browse the CD” to explore the contents. Does anyone know the AS3 code to link the button to the contents of the CD? I won’t know which drive they will be using, so I need it to be specific to the drive it’s running on. Thanks in advance.
Alan
July 22nd, 2009 at 7:43 pm
hi
I have the one button called “goback_btn” and i have 5 different frames that i want to put the same button on, which all have to go back to the first frame but i cant figure out what code to put in for it to work.
Pete
July 24th, 2009 at 11:53 am
I’ve been triying to get multiple buttons to work with AS3 and I get the following output message: “TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PortfolioInterface_IntroSplash_fla::MainTimeline/frame1()”
Here’s my script:
stop();
btn1.addEventListener(MouseEvent.CLICK, click2Enter);
function click2Enter(event:MouseEvent):void {
gotoAndStop(”menuScene”);
}
btn2.addEventListener(MouseEvent.CLICK, photoClick);
function photoClick(event:MouseEvent):void {
gotoAndStop(”photoScene”);
}
btn3.addEventListener(MouseEvent.CLICK, mediaClick);
function mediaClick(event:MouseEvent):void {
gotoAndStop(”mediaScene”);
}
It will take me to the first frame Label but none of the buttons work after that. They will mouse over and change states but won’t goto the frame Label assigned.
Got any ideas?
Jen deHaan
July 24th, 2009 at 1:03 pm
@Pete: My guess is that your frame with the button(s) and the code are not at the same frame number. Try moving the code to the same frame position as your buttons (they can be on different layers, but at the same number) and see if that resolves the error.
Pete
July 27th, 2009 at 10:43 am
Did not resolve the error. Now I recieve this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PortfolioInterface_IntroSplash_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at PortfolioInterface_IntroSplash_fla::MainTimeline/Enter()
Jen deHaan
July 27th, 2009 at 12:25 pm
@Pete: That’s the same error number as before, so my guess would be that the code and the instances referenced in that code aren’t at the same frame number. Maybe check the chunk of code you’re moving and make sure all the instances it contains are at that frame?
Pete
July 29th, 2009 at 7:35 am
Tried your suggestion still same results, got any other suggestions?
Jen deHaan
July 29th, 2009 at 8:45 am
Can you share the file?
Pete
July 31st, 2009 at 6:07 am
How do you want me to saend it to you? I sthere a way to attach it here?
Bertman
August 3rd, 2009 at 1:11 am
Hello
First of all thanks for great site and support…
but Im still a big noob of ac3…
I would like to ask what is “mouseDownHandler” or “buttonclick2″ from the following examples :
button2.addEventListener(MouseEvent.CLICK, buttonClick2);
function buttonClick2(event:MouseEvent):void {
gotoAndStop(1,”Scene 2″);
}
my_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
my buttons name is hakkimda_btn and its intance is also hakkimda_btn but it doesnt work
it says something like unreleated type function.. error code 1067
Thanks
Pete
August 7th, 2009 at 8:14 am
Jen,
Is there a way I can send it to you from here or by email?
Jen deHaan
August 7th, 2009 at 9:20 am
@Pete:
Sorry about the delay, so behind on my comments! :) Yep, you can send it to jen (at) deseloper.com and I’ll take a look.
Thanks,
Jen.
Jen deHaan
August 7th, 2009 at 9:26 am
@Bertman: You will want to change the “button2″ and “my_btn” parts of your code to match your button instance name(s) in your code, hakkimda_btn. The buttonclick2 and mouseDownHandler are referencing the functions in your code (the parts that send the playhead to the new location), and everything looks good there.
rickibarnes
August 10th, 2009 at 9:15 pm
Is there any way of writing a single function that can take a url as a parameter? I ask because I like to use Flash for making menus on websites, but I find it a bit ridiculous to have to write a separate function for every. single. button.
Jen deHaan
August 11th, 2009 at 9:03 am
@rickibarnes: Of coure not, you can handle the functions in different ways. You can for example do case/switch which is quite common. Here’s an example for three buttons in a menu:
stage.addEventListener(MouseEvent.MOUSE_OVER, overBtn);
function overBtn(evt:MouseEvent):void {
switch (evt.target) {
case menu1_btn :
btnNum=1;
highlightBtn();
openMenu();
break;
case menu2_btn :
btnNum=2;
highlightBtn();
openMenu();
break;
case menu3_btn :
btnNum=3;
highlightBtn();
openMenu();
break;
}
};
Bertman
August 13th, 2009 at 5:45 am
Jen thank you for support everything looks fine now :)
Nuno Figueiredo
August 23rd, 2009 at 10:32 am
Hello! I have a question if you could help me…
This image is what I’m doing: http://img263.imageshack.us/img263/123/24981262.jpg
I’m a flash noob and this is a work for school, so if you help me I would be very appreciated.
This is the code that I have:
home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {
gotoAndStop(5);
}
mapa.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(10);
}
and I did everything I know and I can’t solve it out.
Thank you
karen
September 5th, 2009 at 12:19 pm
hi, thanks for the article, it’s very helpful =)
but i’m having a small problem:
imagine that the thumbs up leads to another frame ( gotoAndStop(3) for example) and within frame 3 there is another button that leads to a new frame
I can’t get that button in frame 3 to work; i was treating it just like a third button :
green_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(4);
}
but it does not work. it gives me a “TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/frame2()” error
do i need to treat it differently? thanks
jozef
September 22nd, 2009 at 7:53 am
hello everyone, I am getting constant flash-mate for the last few days. I ‘ve tried to applied button function to external swf, thumbnail panel with images, however, if I try url link from the suggestions above (code is inside external panelc scroll):
panelc.img1_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler);
function thumbDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.google.com”));
}
panelc.img2_btn.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler2);
function thumbDownHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.yahoo.com”));
}
everything works, once scroll downloaded , I click image 1 goes to google, image 2 goes to yahoo, however, if I try to apply function to go to certain frame within the main timeline, using :
panelc.img3_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(80);
}
panelc.img4_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler4);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndStop(81);
}
panelc.img5_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(82);
}
etc…
-buttons dont react, I dont get any errors either, not sure what to do, first time flash user, want to go out take photos instead, pls can anyone give me any suggestions, I ‘ve read every possible article, can’t make it working, thanks
Leah Glick
October 7th, 2009 at 7:03 am
THANK YOU SO MUCH!!!
Mark - Flash beginner
October 13th, 2009 at 4:17 pm
Hi, I’m new to Flash, and having a real problem.
Basically, I’ve got a simple flash file that has 5 buttons that use a motion tween (I want them to come in from off screen to their final positions). That bit works, no problem.
However, What I’m trying to do after the motion stops is to make each button do display some pop up text. The animation goes over 49 frames, and each button is on a seperate layer, named similar to the button. I’ve also got a layer called actions. All the layers run until the end of the scene at frame 49, so all buttons are visible at the end.
The project looks like this:
sizeLayer
Toughnesslayer
Talktimelayer
etc.
There is an instance of a button on each layer,
size_button on sizeLayer
Talktime_button on talktimeLayer
I’ve added the following code to frame 49 of the actions layer
stop();
this.size_button.addEventListener(MouseEvent.MOUSE_DOWN, sizeHandler);
function sizeHandler(event:MouseEvent):void {
trace(”I’ve been clicked!”);
};
but when it runs, I get an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Test_fla::MainTimeline/frame49()
(Test.fla is the filename I’m working with at the moment).
Any ideas as to how I might get this working please. I’ve been at it for about 5 hours now and it’s frustrating.
Thank you.
Kook
October 19th, 2009 at 12:33 pm
Thanks for this lesson! AS 3.0 is whacked.
Lee
October 23rd, 2009 at 10:46 pm
Hi:
Similar to Anita who posted a problem with her Action Script on March 30th, 2008 at 12:35 am.
her code was:
I’ve also tried this, and have sort of the same kind of problem with one of the buttons not working. This is my code:
maria.addEventListener(MouseEvent.CLICK, gotomaria);
function gotomaria(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.fef-aalborg.dk/testsite/sider/rapport/indien2008maria.html”), “_self”);
}
lisser.addEventListener(MouseEvent.CLICK, gotoingerlise);
function gotoingerlise(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.fef-aalborg.dk/testsite/sider/rapport/indien2008ingerlise.html”), “_self”);
}
Both buttons, for some mysterious reason, go to the same page (the first URL specified), and I cannot find out what I’m doing wrong. I didn’t name anything the same, and I tried copy/paste to find out if I had overlooked an error in button two, but no. Help… :-)
and you suggested that if she change the url to seperate sites that that might work.
By the way is this as2 or as3?
I am having the same problem, except I have different URL’s and it does not seem to work for me. First of all the code is applied on in the time line, in a image handler that has 24 images and text and multiple layers in the timeline, each with it own movieclip and inside that a button. (when the user clicks the images, which scroll from left to right, it shows a larger thumbnail of the picture, above the image scroller, and then when the user clicks this image it is supposed to take them to the site I want them to go to) as I said it keeps taking them to the same site, even images that I have not assigned any Actions too, they also link to the same site.
here is the code.
Images_btn1.onRelease = function() {
aaronshust()
}
function aaronshust(){
getURL(”http://www.aaronshust.com/index.html”, “_blank”)
}
and
Images_btn2.onRelease = function() {
matthewwest()
}
function matthewwest(){
getURL(”http://www.matthewwest.com”, “_blank”)
}
but as i said the both go to the first site.
as I said their a 24 separate images that i need to point to 24 sites, my deadline in the end of October here.
So My question is are.
In AS 2.0
My directory tree is images/ holder/ Image_Text (each with an _1, _2,_3 ETC.. to _24 for example Image_Text_1)/ and Images_btn1 Which is where I added the action script in the time line
1. Do I need to create the code on the on the holder level?
2. if so what would the code be so that when the user clicks on each separate images it will go to the proper sites?
3. Can I assign different variables to the code for each image and call each one using a function, if so what is this code.
I am still new to learning AS.
I have looked all over the net to find a solution, please help
Lee
Mike Gasaway
November 15th, 2009 at 10:23 pm
Great resource!
Jen, you’re awesome.
I have a small issue with buttons in that I have some buttons that go to frames within flash and others that go outside to different urls. The problem is if I click on the button that goes to a different frame, I can’t click the button that goes to a different URL. I have to refresh the page first.
Is there something I should put in the code to refresh the page?
thanks!
Eric
November 18th, 2009 at 11:37 am
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.
Every article I read is about the _btn class!!!!
Frustrated Eric
Martha
November 22nd, 2009 at 3:46 pm
Hey guys i have some trouble getting some buttons to work…
Inside my buttons I have movie clips, which keep the buttons rotating until you click,
my problem is that I need the code for the CLICK… when you click they don;t stop!
I have tried several things but they won;t stop.. does any body know?
Justin B
November 25th, 2009 at 2:41 pm
hey, I tried using your help from what you gave Chris, in the 2nd post… but even with your code, the button links keep opening up in new windows…
here’s my code:
home_btn.addEventListener(MouseEvent.MOUSE_DOWN, buttonDownHome);
function buttonDownHome(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.web4brains.com/barcode/”),”_self”);
}
creators_btn.addEventListener(MouseEvent.MOUSE_DOWN, buttonDownCreators);
function buttonDownCreators(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.web4brains.com/barcode/creators”),”_self”);
Justin B
November 25th, 2009 at 2:46 pm
oops nvm… must have been an uploading/saving problem.. thanks!
Crispin
November 30th, 2009 at 6:34 am
Thanks for the support. It’s a pity that Adobe’s support couldn’t be as clear.
Todd A
December 1st, 2009 at 4:54 pm
Hi Jen,
I have a flash movie, that I’ve got 4 buttons on a page. I can get the first button, and the last button to work, but for some reason I cannot get the middle two buttons to work. When I test the movie, it runs fine, the two middle buttons(Contacts and Link) do nothing when you click on them. The top button, gallery and the dynomite button work correctly. Here is my code:
function handleClick1(pEvent:MouseEvent):void
{
if( pEvent.target == gallerybtn )
{
//handle the event
gotoAndPlay (1, “Gallery”);
}
function handleClick1(pEvent:MouseEvent):void
{
if( pEvent.target == contactbtn )
{
//handle the link event
gotoAndPlay (1, “Links”);
}
function handleClick1(pEvent:MouseEvent):void
{
if ( pEvent.target == linkbtn )
{
//handle the contact event
gotoAndPlay (2, ” Contacts” );
}
function handleClick4(pEvent:MouseEvent):void
{
if( pEvent.target == dynomitebtn )
{
//handle the dynomite event
gotoAndStop (60, “Webpage Set”);
}
}}}}
//register events
gallerybtn.addEventListener(MouseEvent.CLICK, handleClick1);
contactbtn.addEventListener(MouseEvent.CLICK, handleClick1);
linkbtn.addEventListener(MouseEvent.CLICK, handleClick1);
dynomitebtn.addEventListener(MouseEvent.CLICK, handleClick4);
If I change the contact and link events to handleclick 2 I get “error 1120 Access of undefined property handleClick 2,
handleClick3″
Any help you may begin to offer would be excellent!
Thanks,
Todd
Stan
December 6th, 2009 at 11:42 pm
I keep getting a error 1120: Access of undefined property btn4Handler. Below is the code I am using.
Any help to solve this would be appreciated.
btn1.addEventListener(MouseEvent.MOUSE_DOWN, btn1Handler);
function btn1Handler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.s2sbuilders.com”), “_blank”);
}
btn2.addEventListener(MouseEvent.MOUSE_DOWN, btn2Handler);
function btn2Handler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.s2sbuilders.com/prodects.htm”), “_blank”);
}
btn3.addEventListener(MouseEvent.MOUSE_DOWN, btn3Handler);
function btn3Handler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.s2sbuilders.com/photos.htm”), “_blank”);
}
btn4.addEventListener(MouseEvent.MOUSE_DOWN, btn4Handler);
function btn4andler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.s2sbuilders.com/quotes.htm”), “_blank”);
}
Pontus
December 7th, 2009 at 4:11 am
I have an flash file with 4 scenes. In layer 2 i have a movieclip. In layer 1 i have 4 of the buildt in buttons which you can find under components. I want this 4 buttons to go to 4 seperate scenes. How do i do it?
Should i use this code?
}
b80.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(”Scene 1″);
If its correct where shall i but it because direct on the button you cant have a action.
//Pontus
Eileen
December 9th, 2009 at 11:41 am
After long hours and numerous tries, tons of tutorials. it wasnt until I came across this website and found the code stop();
first_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {
gotoAndStop(5);
}
second_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(10);
}
that I’d been searching for like what seems now forever… and viola…you had the correct code to make my buttons work… THANKYOU!
Shannon
January 19th, 2010 at 1:56 pm
Hi all,
I am creating a site for a not-for-profit org and have a navigation on the top that I want each button to link to a different page…
here is my code
stop();
homebtn.addEventListener(MouseEvent.MOUSE_DOWN, mousedownHandler);
function homebtnHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.islandcoastprimarycare.org”), “_self”);
}
aboutbtn.addEventListener(MouseEvent.MOUSE_DOWN, mousedownHandler2);
function aboutbtnHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.islandcoastprimarcare.org/about.html”), “_self”);
}
resourcebtn.addEventListener(MouseEvent.MOUSE_DOWN, mousedownHandler3);
function resourcebtnHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.islandcoastprimarycare.org/resources.html”), “_self”);
}
contactbtn.addEventListener(MouseEvent.MOUSE_DOWN, mouseddownHandler4);
function aboutbtnHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.islandcoastprimarcare.org/contact.html”), “_self”);
}
I get the following errors
‘{’ expected for function homebtnHandler(event:MouseEvent):void {
and
Unexpected ‘}’ encountered
Can anyone tell me what is wrong with the code?
Please and Thank you!! :)
Shannon
hiromi
January 27th, 2010 at 12:35 pm
hello
i am new to flash.
i created a movie
http://candmphotography.com/images/homebanner.swf
now, i am trying to make it so when i click on each image, it goes to different url. for ex., if i click on baby photo, it goes to a url and if i click when a wedding dress shows, and i click on it, it goes to a different url.
i added this action in an action layer, but when i publish it, i get an error msg.
“Access of undefined property Kids.
Access of undefined property Wedding.”
as3:
Kids.addEventListener(MouseEvent.MOUSE_DOWN, buttonClickKids);
function buttonClickKids(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://candmphotography.com/children.html”));
}
Wedding.addEventListener(MouseEvent.MOUSE_DOWN, buttonClickWedding);
function buttonClickWedding(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://candmphotography.com/wedding.htm”));
}
hiromi
January 27th, 2010 at 12:51 pm
sorry, i got it to work after i posted this…
thanks!
rob
February 13th, 2010 at 3:16 pm
Can you help me determine the code for your example that will make an email send? Actually more than one email button in one framde.
I have been in flash for years, and after 8 hours of searching and trial and error, I am amazed how complicated something that used to be so simple has become.
Thanks for your help.
Rob
DJ Edenbaum
February 14th, 2010 at 10:29 pm
ok… i’m working on my first Flash Website, and i’m having a little trouble. I have five buttons, and the all have different names, but i keep getting an error 1023, followed by a 1021 for the last 3 buttons the first two work great… help me please… here is my code:
aboutus_btn.addEventListener(MouseEvent.MOUSE_DOWN,aboutus);
function aboutus(event:MouseEvent):void {
navigateToURL(new URLRequest(”Nebraska.html”), “_self”);
}
Trotn_btn.addEventListener(MouseEvent.MOUSE_DOWN, Trotn);
function Trotn(event:MouseEvent):void {
navigateToURL(new URLRequest(”/****nebraska/Nation_Wide.html”), “_self”);
}
IU_btn.addEventListener(MouseEvent.MOUSE_DOWN,IU);
function IU(event:MouseEvent):void {
navigateToURL(new URLRequest(”/****nebraska/Industrial.html”), “_self”);
}
MU_btn.addEventListener(MouseEvent.MOUSE_DOWN, MU);
function MU(event:MouseEvent):void {
navigateToURL(new URLRequest(”/****nebraska/****.html”), “_self”);
}
Join_btn.addEventListener(MouseEvent.MOUSE_DOWN, Join);
function Join(event:MouseEvent):void {
navigateToURL(new URLRequest(”/****nebraska/Membership.html”), “_self”);
}
Forgive the asterisks… it to protect my non-profit organization…
please help i am supposed to have this site up 2-16-2010 at 9am
DJ Edenbaum
February 15th, 2010 at 12:03 am
kindly disregard… i found my answer… btw your site was very helpfull!!!
Judy
March 1st, 2010 at 10:44 am
Can you help me make the change to AS3 for this code:
on (release) {
getURL(clickTAG,’_blank’);
}
My ad servers require the clickTAG in the script but I can’t figure out how to make it work. The clickTAG is used by DART and Yahoo!’s ad server to locate the url for the clickthrough. We can’t hardcode urls.
Thank you so much in advance!