Last Updated on February 26, 2019
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:
- For basic information on creating a button in ActionScript 3.0, see this post: http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/
- 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/
Chris says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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?
Jen, a flashthusiast says
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 says
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 says
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 says
this is for the other buttons???
Monique says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
I get these errors:
With this script
Scene 1:
Ashford : Frame 1
Ascalon : Frame 1
Diane says
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 says
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 says
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 says
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 says
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 says
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 says
***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 says
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 says
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 says
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 says
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 says
http://www.morecult.com that is :-)
Jen, a flashthusiast says
great stuff Thomas – love the Flash work! keep it up!
tomripl says
Anyone can help with this error message?
krizzallid says
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
Jen deHaan says
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/
Emma says
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
Christie says
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 says
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 says
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 says
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 says
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 says
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 says
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 says
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ı says
I wanna learn flash :(
Squidge says
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 says
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 says
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 says
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 says
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 says
@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 says
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 says
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 says
thanx a lot for this info, been very frustruated becouse of changes in AS 3.0 :/
chelsea says
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 says
^^ Oh and I’m using CS4
chelsea says
…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 says
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 says
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 says
MODS PLEASE DELETE LAST 2 POSTS BY JOE
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?
Phey says
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 says
Is there anyone out there?
Bryan says
It’s OK… I figured it out on my own….
Krystina V. says
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 says
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 says
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 says
How do you create a download button in flash cs 4 as 3. Thanks.
Rick says
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 says
This has been COMPLETELY unhelpful.
Sam says
Jen, you rock. ty
sirwolliam says
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 says
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.
Jen deHaan says
@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 says
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 says
@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 says
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 says
Can you share the file?
Pete says
Tried your suggestion still same results, got any other suggestions?
Pete says
How do you want me to saend it to you? I sthere a way to attach it here?
Bertman says
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
Jen deHaan says
@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 says
@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.
Pete says
Jen,
Is there a way I can send it to you from here or by email?
rickibarnes says
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 says
@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 says
Jen thank you for support everything looks fine now :)
Nuno Figueiredo says
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 says
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 says
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 says
THANK YOU SO MUCH!!!
Mark - Flash beginner says
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 says
Thanks for this lesson! AS 3.0 is whacked.
Lee says
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 says
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 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.
Every article I read is about the _btn class!!!!
Frustrated Eric
Martha says
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 says
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 says
oops nvm… must have been an uploading/saving problem.. thanks!
Crispin says
Thanks for the support. It’s a pity that Adobe’s support couldn’t be as clear.
Todd A says
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 says
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 says
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 says
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 says
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 says
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 says
sorry, i got it to work after i posted this…
thanks!
rob says
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 says
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 says
kindly disregard… i found my answer… btw your site was very helpfull!!!
Judy says
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!
ktrach says
Dude your the best! awesome tutorial searched for hours for an answer for how to do this until i found ur post
rosh says
i have 3 button , in that main button inside another 3button ,inside button how to write a codu
AP says
You’re a lifesaver, THANK YOU! :) Worked perfectly! Easy tutorial, much appreciated!
Chazza says
Hi can you help me. Im using Flash cs3 actionscript 3.0.
Ive created two scenes. In my 2nd scene I have a button that when clicked links to a game.
Heres the code:
beer_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(76);
}
In scene one I have another button. I want that button to take me to scene to: Heres the code for the button:
stop();button1.addEventListener(MouseEvent.MOUSE_UP, mouseDownHandler);function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 2”);
}
When I click on test movie this comes up:
1021: Duplicate function definition.
Im really stuck on this plz help me x
allen says
hi,
Please i need your help if u have time to help me with action script 3.0 ..
” I have 3 different video (video1, video2, video3)”
and ” i have 3 different buttons (btn1, btn2, btn3″
I need to make each button play one vide..
for example btn1 play video1 and btn2 play video2 …etc
when i click btn1 it will play the vide1 and all the buttons will be hidden if the video playing when video finish all the buttons will be visible again.. also when i click btn2 it will play video2 and all the buttons will be hidden when the video finish playing it will be visible again and the same thing for btn3…
Please help me in this, i need the code for that if it is possible….
thanx in advance ..
Maria Belen says
Thank you very much for your tutorial it was really helpful.
Joshua says
Thanks !!!. You saved my life.
Janavi says
Hi,
I am new to flash. I want to add four buttons in my flash file ( Play, Rewind, Forward, Stop). Can any one please help me the step by step procedures on how to add these buttons with Actionscript 3.0 in Flash CS4.
pinky says
flash cs3 is a waste!
jfklimek says
hey any and everyone. First off, thanks for this post. It works for me… almost.
I am attempting to create a flash movie that has a bunch of buttons that when clicked will direct the movie to a certain frame on the timeline. I’ve got everything set up and the movie waits for my command upon playing, however, only some of the buttons work and some don’t. They all appear and react based on my Up, Down, and Over imagery I set up, but the actions don’t necessarily work. Then on top of that, when i find one of the buttons that work, it takes me to that frame where some different buttons will work, not necessarily the same any of the frames prior (in other words some of the buttons that didn’t work, now do but some of the buttons that did work now DON’T!!!?) it’s driving me crazy, I’ve tried many different ways to do this and i think this code is the simplest but I can’t figure out why it doesn’t connect with some of the buttons and not others. Please help if you can. The code is as follows:
stop();
btn_picsTL.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsTM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsTR.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsML.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsMM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsMR.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBL.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBR.addEventListener(MouseEvent.CLICK, mClickHandle01);
function mClickHandle01(pEvent):void {
if( pEvent.target == btn_picsTL ) { gotoAndStop(“2”);}
if( pEvent.target == btn_picsTM ) { gotoAndStop(“3”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“4”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“5”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“6”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“7”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“8”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“9”);}
if( pEvent.target == btn_picsTR ) { gotoAndStop(“10”);}
}
jfklimek says
I’m very sorry for the continuation but i’ve figured out a more specific problem to my post directly above.
I realize that when i click on a button that targets a frame that is after the current frame, it will advance. However, the buttons that link to a frame located prior to the current frame it will not go back. I can only continue the movie through frames that advance the timeline. How do i “gotoAndStop” to a frame that is before the current one on the timeline.
THis is the current code:
stop();
btn_picsTL.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsTM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsTR.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsML.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsMM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsMR.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBL.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBM.addEventListener(MouseEvent.CLICK, mClickHandle01);
btn_picsBR.addEventListener(MouseEvent.CLICK, mClickHandle01);
function mClickHandle01(pEvent):void {
if( pEvent.target == btn_picsTL ) { gotoAndStop(“2”); }
if( pEvent.target == btn_picsTM ) { gotoAndStop(“3”); }
if( pEvent.target == btn_picsTR ) { gotoAndStop(“4”); }
if( pEvent.target == btn_picsML ) { gotoAndStop(“5”); }
if( pEvent.target == btn_picsMM ) { gotoAndStop(“6”); }
if( pEvent.target == btn_picsMR ) { gotoAndStop(“7”); }
if( pEvent.target == btn_picsBL ) { gotoAndStop(“8”); }
if( pEvent.target == btn_picsBM ) { gotoAndStop(“9”); }
if( pEvent.target == btn_picsBR ) { gotoAndStop(“10”); }
}
Thanks for any help you can afford.
Abhi says
I wanted to know if we have to use many buttons not just only two, to gotoAndPlay( some frame number).
I want to create a function where I can just create one function. While running it I want to give it only the name of the button and the frame number, like we can easily do in case movie clips.
Carl says
ALL,
The ampersand, quote, semicolon should be an actual quote symbol :) for those of you who are html challenged.
("http://msdn2.microsoft.com/en-us/silverlight/default.aspx"));
(“http://msdn2.microsoft.com/en-us/silverlight/default.aspx”));
Janet says
Thank you so much for your tips. It is the first time I’ve seen your page and think it’s really full of tips and advice. I have benn trying to solve this problem for a while as I am new to Flash. Great site and I am grateful to folk such as you for publishing on the Web as it makes it so much easier for newbies to Flash. The books are sometimes not much help.
Once again
Thank you
joana caramona says
Hello there, im trying to make a button inside of another button in Ac3 using movie clips.
When you click the first button, it is possible to have another button inside of the first???
Can you explain me how to make this? I have found it in AC2 but i cannot found anything in AC3.
Thank you!
Gennie says
It worked great. Thanks so much. I’ll give u the website as soon as it is finished.
G.
Al Phillips says
I am new to Flash CS5 and Action Script. I would like to know whether one button can be made to bring up one or more other buttons? If so, what does a sample Action Script look like for this? Thanks!
tracy says
thank you sooo much for this information. ive spent a day looking and trying to work out how to get more than one link on a page working and im VERY new to this so its been doing my head in. thanks again – you’ve been a lifesaver!
DrStupid87 says
Hello!
So yeah, I’ve been trying to build a kind of ‘weapon generator’ for part of a project I’m working on but I’ve hit a wall.
I’ve been using a hell of a lot of functions in my little program but for no (apparent) reason, it’s generating a lot of errors.
Specifically:
Code:
StockMoveUp.addEventListener(MouseEvent.CLICK, StockUp);
StockMoveDown.addEventListener(MouseEvent.CLICK, StockDown);
StockMoveLeft.addEventListener(MouseEvent.CLICK, StockLeft);
StockMoveRight.addEventListener(MouseEvent.CLICK, StockRight);
HandleMoveUp.addEventListener(MouseEvent.CLICK, HandleUp);
HandleMoveDown.addEventListener(MouseEvent.CLICK, HandleDown);
HandleMoveLeft.addEventListener(MouseEvent.CLICK, HandleLeft);
HandleMoveRight.addEventListener(MouseEvent.CLICK, HandleRight);
TriggerMoveUp.addEventListener(MouseEvent.CLICK, TriggerUp);
TriggerMoveDown.addEventListener(MouseEvent.CLICK, TriggerDown);
TriggerMoveLeft.addEventListener(MouseEvent.CLICK, TriggerLeft);
TriggerMoveRight.addEventListener(MouseEvent.CLICK, TriggerRight);
MagazineMoveUp.addEventListener(MouseEvent.CLICK, MagazineUp);
MagazineMoveDown.addEventListener(MouseEvent.CLICK, MagazineDown);
MagazineMoveLeft.addEventListener(MouseEvent.CLICK, MagazineLeft);
MagazineMoveRight.addEventListener(MouseEvent.CLICK, MagazineRight);
CoverMoveUp.addEventListener(MouseEvent.CLICK, CoverUp);
CoverMoveDown.addEventListener(MouseEvent.CLICK, CoverDown);
CoverMoveLeft.addEventListener(MouseEvent.CLICK, CoverLeft);
CoverMoveRight.addEventListener(MouseEvent.CLICK, CoverRight);
BarrelMoveUp.addEventListener(MouseEvent.CLICK, BarrelUp);
BarrelMoveDown.addEventListener(MouseEvent.CLICK, BarrelDown);
BarrelMoveLeft.addEventListener(MouseEvent.CLICK, BarrelLeft);
BarrelMoveRight.addEventListener(MouseEvent.CLICK, BarrelRight);
GripMoveUp.addEventListener(MouseEvent.CLICK, GripUp);
GripMoveDown.addEventListener(MouseEvent.CLICK, GripDown);
GripMoveLeft.addEventListener(MouseEvent.CLICK, GripLeft);
GripMoveRight.addEventListener(MouseEvent.CLICK, GripRight);
I can promise you that all of my movieclips share the exact same identifier names with these functions. The top two sections of code here work fine (each line is assigned to a button that modifies the x or y position of the movieclip when clicked). But right after that, Flash tells me that the rest of it is:
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 834 1120: Access of undefined property TriggerUp.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 835 1120: Access of undefined property TriggerDown.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 836 1120: Access of undefined property TriggerLeft.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 837 1120: Access of undefined property TriggerRight.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 839 1120: Access of undefined property MagazineUp.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 840 1120: Access of undefined property MagazineDown.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 841 1120: Access of undefined property MagazineLeft.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 842 1120: Access of undefined property MagazineRight.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 844 1120: Access of undefined property CoverUp.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 845 1120: Access of undefined property CoverDown.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 846 1120: Access of undefined property CoverLeft.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 847 1120: Access of undefined property CoverRight.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 849 1120: Access of undefined property BarrelUp.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 850 1120: Access of undefined property BarrelDown.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 851 1120: Access of undefined property BarrelLeft.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 852 1120: Access of undefined property BarrelRight.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 854 1120: Access of undefined property GripUp.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 855 1120: Access of undefined property GripDown.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 856 1120: Access of undefined property GripLeft.
Assault Rifle Generator, Layer ‘ACTIONSCRIPT!!’, Frame 1, Line 857 1120: Access of undefined property GripRight.
I’ve had this problem for a while now and I’ve looked for a long time on how to solve it. Is there any kind of limit to the amount of button functions I can create? Do I need to tweak any AS3 settings? Does Flash CS5 despise me?
If there’s any help here, it would be greatly appreciated.
Thanks in advance.
MurenCreativez says
hi< why am i getting this error compiler msg???
"TypeError: Error #1009: Cannot access a property or method of a null object reference.
at test3_fla::MainTimeline/frame1()"
Adrienne says
Hello Im having problems, my 1st frame code is
stop();
import flash.events.MouseEvent;
sync_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick (e:MouseEvent):void{
gotoAndStop(2);
}
This seems to work fine, and get my to the 2nd frame, which is where i have problems, my aim is to make a button to continue, and a button to go back to the first frame i p much copied what you used.
stop();
SyncMusic_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event:MouseEvent):void {
gotoAndStop(3);
}
BktoConfig_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(1);
}
The instance names were copied straight from where i named them so they are right, this is making me mad because ive been working on cs5.5 at uni, and on cs4 at home and my cs4 doesnt run my cs5.5 work i had made a start on (where all this was working)
I keep getting the error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at Untitled_fla::MainTimeline/onClick()
And the button going back doesnt work, Im in urgent need of help because this assignment is due next week, and ive been working on it for at least 2 weeks now and nothing i can do seems to be working.
baconParty says
Hi There, I’ve followed your tutorial, thanks, it works for my first button in this case btn_airQuality.
I’ve also added more mouseStates. But my second button goes berserk. And I have no idea why.
Can you please help me?
Thanks for your tutorials!!!
Code Follows:
stop();
btn_regComp.addEventListener(MouseEvent.MOUSE_DOWN, regCompDownHandler);
function regCompDownHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.escience.co.za/air_quality.html”));
}
btn_regComp.addEventListener(MouseEvent.MOUSE_OVER, regCompOverHandler);
function regCompOverHandler(event:MouseEvent):void
{
gotoAndPlay(“regCompStart”);
}
btn_regComp.addEventListener(MouseEvent.MOUSE_OUT, regCompOutHandler);
function regCompOutHandler(event:MouseEvent):void
{
gotoAndPlay(“regComp_Out”);
}
btn_airQuality.addEventListener(MouseEvent.MOUSE_DOWN, airQualityDownHandler);
function airQualityDownHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest(“http://www.escience.co.za/air_quality.html”));
}
btn_airQuality.addEventListener(MouseEvent.MOUSE_OVER, airQualityOverHandler);
function airQualityOverHandler(event:MouseEvent):void
{
gotoAndPlay(2);
}
btn_airQuality.addEventListener(MouseEvent.MOUSE_OUT, airQualityOutHandler);
function airQualityOutHandler(event:MouseEvent):void
{
gotoAndPlay(7);
}
SRK says
Hello,
I’m currently working on a project that requires the use of a fly out menu. That works just wonderfully. My real problem is getting the buttons within this fly out menu to work. The menu is a MC which holds the buttons. What I want is for the buttons to link to Frame Labels out on the Main Time Line. I’ve found some code that partially works. It’s allowed me to get one of the buttons to work as I’d like, but when I go to duplicate the code for the other BTN’s, it errors out. Here is the code I’ve used on the btns that exist within the MC:
var rewt:MovieClip = new MovieClip();
rewt = root as MovieClip;
ANNULUS.addEventListener(MouseEvent.CLICK, clickSection);
function clickSection(event:MouseEvent)
{
rewt.gotoAndStop(“ANNULUS”);
}
And here are the compiler errors:
Symbol ‘MENU’, Layer ‘SUB BTNS’, Frame 2, Line 13 1151: A conflict exists with definition rewt in namespace internal.
Symbol ‘MENU’, Layer ‘SUB BTNS’, Frame 2, Line 18 1021: Duplicate function definition.
I’m wondering if there is a new instance name I’m not naming or something else….
Thank you in advance for any help, hopefully I’ve described the problem well enough.
SRK
mohammad says
what code should I write if :
when a symbol reaches the other symbol,it (symbol 1)goes to frame 4.
Alise says
Hey,
I’ve recently started to build my website, anew … had need for some change.
I know a little about Flash and the internet provides me with tutorials for the things I need … so, I decided to make my website a little bit flashier then before.
But … I stumble on problems I don’t seem to be able to fix.
this page http://alise-art.com/eng/home.html for example … contains buttons, made in flash … but if I try to add navigate to URL (just like you describe) it’s always faulty for some reason and … the most curious thing happens … the text on my buttons, just vanishes … an each and every view, the black/white and the invert.
I wonder if you could enlighten me further.
why won’t flash accept my code (well, your code actually)
kind regards, Liz
Ryan Bishop-Olejnik says
Hi, I am trying to write code for pause/play buttons in a slideshow and was wondering if there was anyway to write multiple frame numbers into the code rather than writing the code out in each keyframe?
pausebutton.addEventListener(MouseEvent.CLICK,stopmovie);
function stopmovie(eventMouseEvent):void
{
gotoAndStop(534-2);
}
playmoviebutton.addEventListener(MouseEvent.CLICK,playmovie);
function playmovie(eventMouseEvent) :void
{
gotoAndPlay(534-2);
}
Katherine Hambley says
This has been a big help, I am converting all our AS2.0 CD UI to AS 3.0 and I needed help quickly. Thanks again!
Salma Vohra says
I have assigned a sound using ActionScript 3.0 on a button which on a click, plays the sound and on second click it stops the sound. I would like to add a still image to this button. So when clicked once a sound is played and the still image pops up and when clicked for the second time, sound stops and so does the image.
Can you help me with the code please.
Thank you
santosh says
hi friends, i have got a problem to keep same function for multiple buttons. The function is next frame button. Can any one help what should i write in actionscript