…and especially enthusiastic about motion tweens in Flash…
A common request in the comments is for information on how to create a button that links to a scene using ActionScript 3.0 in Flash CS4 or CS3. Luckily, it’s largely the same as creating a normal button that links to whatever, and uses the same gotoAndPlay format as in ActionScript 2.0. So hopefully it’ll make sense once you see it.
So if you’re unsure on general button code, see this post here: Making a button work in AS3. More links about writing button code at the end of this post.
Now you’re ready for some scenes-with-buttons action. Here’s some code:
stop();button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownHandler(event:MouseEvent):void { gotoAndStop(1, "Scene 2"); }
So that code assumes that you have a button with the instance name button1, and a scene in your document called Scene 2 in the Scenes panel. The number “1″ in that code points to frame 1 of the scene.
So what if you want to, say, link to a particular frame? Let’s link to frame 5 of a scene called monkeyScene:
stop();button2.addEventListener(MouseEvent.MOUSE_DOWN, monkeyDownHandler); function monkeyDownHandler(event:MouseEvent):void { gotoAndStop(5, "monkeyScene"); }
Hope that answers the question. I’ve put an FLA file online that links each scene using buttons so you can see this in action.
Linking to buttons within a scene
There have also been questions about linking to frames within a scene. I’m not positive what the specific problem is, but I’ll take a stab at it (or at least show what seems to work for me.
Now, what causes many of the problems with Scenes in Flash (and why they are officially discouraged from use in Flash best practices - I never use ‘em unless I have next to no code in a FLA), is as follows. From what I understand, when you publish your SWF file, all of the scenes in a FLA are made into one big giant string of frames. Kind of like sticking all of your scenes into one big timeline (one big scene, essentially) and pushing it out as a SWF. Therefore, this can mess up your code. If you’re pointing to a frame 56… which one? To you it may be frame 56 of scene 3, but to Flash that may be frame 56 of the giant new timeline in the SWF that’s published.
So, it’s good to avoid scenes.
But I digress. So if you’re linking to buttons within the same scene, you could specify what scene you’re pointing to in each button. So if you’re in a scene called monkeyScene, you could make your button that’s on frame 1 point to frame 2 of monkeyScene as follows:
stop(); mbutton1.addEventListener(MouseEvent.MOUSE_DOWN, monkeyHandler1); function monkeyHandler1(event:MouseEvent):void { gotoAndStop(2, "monkeyScene"); }
I’ve uploaded another real ugly FLA file that links multiple buttons to frames within a single scene. Check out monkeyScene in the FLA file.
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.

JK
August 4th, 2008 at 12:54 pm
So in ActionScript 2.0 you had:
But now in 3.0, you have:
Why is it more complicated to do the same thing?
Lisa
August 5th, 2008 at 11:51 am
Halalujah!
Your ugly like fla worked beautifully. I added “back” buttons on each frame, set the properities for it on each frame, copied and pasted the code for the “forward” button and made the appropriate changes….and wallah!
I wonder if not using a scene name since I’m only working in one scence was part of the problem….
Thanks Jen!!
Chetan Sachdev
August 19th, 2008 at 1:38 am
I am unable to find Window component which is in Flash 8 in Flash CS3. Could you please suggest an alternative to Window Component in CS3.
andia
August 27th, 2008 at 1:57 am
hi Jen!!
first i would like to thank you for your fantastic tutorial!!! you are great.
then i wanted to ask.: you have explained how to creat several buttons, and you explained how to link two or more scene together. well i wanted to creat a home page, in e way that when i click in a word, in the same page another page opens. i created 2 scene and used the way you explained to move from one scene to the other but i am not sure if this is the best way to have a new window in the same page, or should i use another method?
andia
D.
September 2nd, 2008 at 3:02 pm
I thought it was strange to say that using Scenes is discouraged…I have been using them a lot and they have been working fine.
jen d
September 2nd, 2008 at 9:39 pm
Hey D,
Good question. Generally they’re OK for code-less long animations, however there are many cases where it may be best to avoid using them. Here’s the pertinent section from Flash best practices on scenes that may help clarify (http://www.adobe.com/devnet/flash/articles/flash8_bestpractices_print.html). I wrote it for Flash 8, but it’s still relevant.
Using Scenes
Using scenes is similar to using several SWF files together to create a larger presentation. Each scene has a timeline. When the playhead reaches the final frame of a scene, the playhead progresses to the next scene. When you publish a SWF file, the timeline of each scene combines into a single timeline in the SWF file. After the SWF file compiles, it behaves as if you created the FLA file using one scene. Because of this behavior, avoid using scenes for the following reasons:
* Scenes can make documents confusing to edit, particularly in multiauthor environments. Anyone using the FLA document might have to search several scenes within a FLA file to locate code and assets. Consider loading content or using movie clips instead.
* Scenes often result in large SWF files. Using scenes encourages you to place more content in a single FLA file and hence, larger documents to work with and larger SWF files.
* Scenes force users to progressively download the entire SWF file, even if they do not plan or want to watch all of it. Your user progressively downloads the entire file, instead of loading the assets they actually want to see or use. If you avoid scenes, the user can control what content they download as they progress through your SWF file. This means that the user has more control over how much content they download, which is better for bandwidth management. One drawback is the requirement for managing a greater number of FLA documents.
* Scenes combined with ActionScript might produce unexpected results. Because each scene timeline is compressed onto a single timeline, you might encounter errors involving your ActionScript and scenes, which typically requires extra, complicated debugging.
There are some situations where few of these disadvantages apply, such as when you create lengthy animations. If you create lengthy animations, you might find it advantageous to use scenes. If disadvantages apply to your document, consider using multiple FLA files, movie clips, or screens to build an animation instead of using scenes.
Ken
September 9th, 2008 at 6:27 pm
Learning Flash CS3 and Dreamweaver CS3 and having issues with the listing of the Gnome project you have listed. For some reason I have what I feel followed all the required parts and still my flash file doesn’t load in the browser (Firefox 3.0.1). Am I missing something?
Operating System Vista Ultimate. Authoring software Adobe Design Premium CS3
Any help would be appreciated (tested IE 7 just now and that too doesn’t display my gnome. : (
vijay
September 14th, 2008 at 4:32 am
Hi,
I want to create button in flash…………. for that : If any user want to download a swf portfolio by button click.
honkuan
September 23rd, 2008 at 2:55 am
he i have a problem here, when i apply the code into my button layer it having error code:
Sarah
September 26th, 2008 at 2:02 pm
Hi! I am doing a simple actionscript 3.0 assignment, however, it’s not so simple because I used scenes! Here’s the issue: my buttons aren’t going to the next scene when I click on them, and from what I can tell (as a newbie) I am using correct syntax etc. What is wrong? Here’s what I have:
Vic
October 2nd, 2008 at 2:00 pm
hello, i am having real troubles with this too. i am making a website and am using buttons to jump from scene to scene. when i put all the code in i keep on getting the same error message that it can not find the scene i am asking to jump to. do you have any suggestions what i might be doing wrong please? thank you. here is the error message.
Vic
October 2nd, 2008 at 2:09 pm
i have just copy and pasted your button from the sample fla above, and now it works. i have been using the very basic buttons ‘up, over, down, hit’ is there a problem with doing this? thank you
tomripl
October 6th, 2008 at 1:57 pm
how do u rename the scene?
tomripl
October 6th, 2008 at 2:04 pm
it’s okay. figured this out already.
aiman
October 20th, 2008 at 5:47 am
hey jen. i’m using flash 8 and i have problems linking button/moviesclip within multiple symbols. i need to link it to another scene. it only works if the buttons is not within any symbols. if i put the buttons outside any symbols, other function wont work. currently the actionscript i’m using for my buttons that works outside any symbols but wont work within symbols is:
thank you.
rademenes
October 24th, 2008 at 6:59 am
Hi Jen!
I’ve got problem with attached video into button.
When I push the button ,video does’t stop and duplicate play every time when I repeat action .Have you any ideas how to solve this problem? pleasee :-( (Im newbie flash coder)
Here is a code:
Ben Levy
November 5th, 2008 at 9:11 pm
I am using this code
stop();
more_btn.addEventListener(MouseEvent.MOUSE_DOWN, more_btnHandler1);
function more_btnHandler1(event:MouseEvent):void {
gotoAndStop(114);
}
When i click the button i made to go forward it goes forward and then when i click a back button i made it goes back to the beginning of the swf starting with my intro animation but the content the showed up when i clicked my back buttons is on top of every thing. who do i get it to just go back and not start all over again
jimmy
November 21st, 2008 at 7:51 am
halo there….
i want to ask about: how to make a button(action script 3.0) to load another swf file? (not for website, just for interactive cd) plzz help me…..i am already very2 confuseddd…….
Many thx!
Joe
December 3rd, 2008 at 3:40 am
hello, please can you help me, i need it for uni work lol
the issue is that i made a button to go forward on frame 1 to frame 10, the code being:
that works fine, but i want to place a button on the frame 10 to go baack to frame 1, but everytime i place the code in, it just plays my first scene and carrys on, thru the second scene, ignoring the stop code, this only happens if the code on the 10th frame is there, with it its fine.
so i can you please tell me what im doing wrong, or is there a specific “back button”?
cheers
Hadi
December 7th, 2008 at 6:02 am
Im a bit of a noob when it comes to action script, and i have been tring to get this working for ages but i can’t hack it.
could you please give me sum guidence.
how do i make a button(action script 3.0) to load another swf file.
please help.. thx
slitherer
December 15th, 2008 at 5:47 am
Hello, good answers everyone! I would like to ask you something in the same area.. I now have a site.swf obj in a index.html page, what I would like to do is : to open by pressing a button another index1.html page which has the same site.swf obj embeded but in another scene.
I would appreciate your help.
By the way I am talking about AS2
Thank you
nw
February 11th, 2009 at 8:33 am
hi there! as a total newbe to as3 is there a way to put ‘mouseover’ comments on to button instances?
I have many buttons that are the same instead of having a seperate symble for each- goto page 1, home, top, etc
thankyou
heymelby
February 11th, 2009 at 2:23 pm
I’m totally frustrated, I have 3 embeded FLV’s and a 4th that is a segway with buttons on it. I want the SWF to play movie 1, then go to movie 4(with buttons) so users can click to see either video 1 again, 2 or 3. i’ve tried doing it with scenes but i’m to dumb to wrap my head around AS3. anybody got a solution.
arcueid
March 9th, 2009 at 11:40 pm
hi~ I hope you are still alive… what if I want to load an external .swf file? what code should I use? …thanks~!^^-
Terra
March 19th, 2009 at 12:05 pm
I am kindof new to flash so please forgive me for asking a newbie question. I am a student taking graphic design and in our flash class our assignment is to create a fully functional portfolio website.
I have done the design and created the pages as scenes within a scenes. (8 scenes. scene 1 is preloader and scenes 3-8 are duplicates of scene 2) Anyway, I cannot get the buttons to go to the pages when I test the movie.
I am pasting the code I used for the buttons/pages (and this code is duplicated on every scene) currently I am getting 51 duplicate function definition errors when I test the movie and it just runs through all the scenes in order once and then stops.
Code:
stop();
WSNB_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 2″);
}
stop();
TOUR_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 3″);
}
stop();
ABOUT_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 4″);
}
stop();
GALLERY_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 5″);
}
stop();
MERCH_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 6″);
}
stop();
CONTACTBAND_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 7″);
}
stop();
LINKS_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “Scene 8″);
}
Thank you for any help or suggestions!!!
Michel
March 26th, 2009 at 4:57 pm
This really helps, but I have a movieclip on the stage that won’t stop playing. I want a button on ROLL_OVER to target that movieclip & then ROLL_OUT to move to another label within the clip. How is this achieved?
Andy
April 3rd, 2009 at 7:36 pm
Thanks heaps, great help! Was wondering if there’s a way to have transitions when using the script to change between frames in the same scene, rather than just jumping straight to that frame?
Polly
April 11th, 2009 at 5:31 am
AHH!! I LOVE YOU I LOVE YOU! YOU TOTALLY JUST HELPED ME SOLVE MY PROBLEM! THANK YOU SO VERY VERY MUCH! XD YES! AH-HA! I COULD NOT FIND ANYTHING LIKE THIS ANYWHERE! TT_TT So happy…
Justin
April 27th, 2009 at 10:25 am
This is causing my brain to bleed - I’ve copied and pasted the code above to get a button to link into a scene, but it doesn’t work. I’ve done it all exactly as demonstrated above, but when exporting to the swf file it seems it ignores the actionscript. Basically all my scenes just play (and loop) one after the other, not allowing me to even click the button. I got it to work once, but that was it - must have been a fluke.
I’m not a flash programmer, but i need this for Uni too, and it’s driving me mad! esp since I’m on a deadline.
Pls HELP!!
Justin
April 27th, 2009 at 10:30 am
Oh yeah - i downloaded the sample FLA file that links buttons to scenes, and it does exactly the same thing. Is there a problem with my compiler or something?
Annie
May 11th, 2009 at 12:17 pm
PLEASE PLEASE can someone help me? I am trying to make a back button and I have put the action script on like so:
stop()
buttonback.addEventListener(MouseEvent.MOUSE_DOWN, goback1);
function goback1(event:MouseEvent):void {
gotoAndStop(1, “Scene 1″);
}
and I have put this code on the 2nd frame.
And this is what i have put on my forward button:
buttonforward.addEventListener(MouseEvent.MOUSE_DOWN,goforward);
function goforward(event:MouseEvent):void {}
gotoAndStop(2, “Scene 1″);
It works clicking forward and back, and then forward and forward and back, but it will not let me go back twice. I have no idea why this happens when the code works the first time going from the second frame to the first, but will not work again once I have gone past the third frame.
I would really appreciate any help or ideas people can give me,
Thank you!
Brenda
May 15th, 2009 at 8:01 am
Hi, all. I’m actually getting back into Flash after being out of it for 7 years. (The last version I used was the first MX version, before Adobe bought out Macromedia.) I’m working with AS 3 in Flash Professional CS4, and I copied and pasted the code above to link my button to the next scene, but when I tested the scene, it gave me the following 3 syntax errors:
Scene=Scene 2. layer=ABOUT. frame+1, Line 1 Statement must appear within the handler Source: stop();About_btn.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownnHandler(event:MouseEvent):void {
Scene=Scene 2, layer=ABOUT, frame=1, Line 3 Scene name must be quoted string Source: gotoAndStop(1, “Scene 3″);
Scene=Scene 2, layer=ABOUT, frame=1, Line 1 Scene must appear within a handler Source: stop();About_btn.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownnHandler(event:MouseEvent):void {
Because I haven’t worked in Flash for so long, I’m going to assume operator error on my part, but any advice you can give me on how to resolve this will be greatly appreciated.
Annie
June 11th, 2009 at 6:36 am
Hi!
Thanks so much for this tutorial! I would’ve been at it for hours trying to figure it out. I’m not very Flash savvy. Thanks for your help! (:
- ANNIE
Misty
June 16th, 2009 at 3:40 pm
I don’t get it. I have a scene, scene 1 that only has 1 frame in which I have a single stop code and have loaded all of my movie clips into it in different layers.. My buttons are part of a movie clip and I have been added to that scene as well. Now I want to link one of the buttons to a new scene upon hit. I can’t figure out how to do this. I don’t know where to put the above code. I’ve tried multiple solutions but it just plays frame 1 of scene one which is a background and then frame one of scene two which is nothing at this point so now Its just blinking at me. Can someone please help me?
Ximena
June 21st, 2009 at 1:59 pm
Hi Misty I has the same problem, and I work like you: in a single frame, and movieClips distributed in layers. The only solution I have found is that the code of the button that you need to hit, is on the main line, I have it with a movie clip:
mymovieclip_mc.visible = false;
mymovieclip_mc.addEventListener(MouseEvent.CLICK,jumptoscene);
function jumptoscene(event:MouseEvent):void
{
gotoAndPlay(1, “mynewscene”);
}
Ximena
June 21st, 2009 at 2:01 pm
sorry, please don’t worry about the first line, it’s about visibility.
Lani
June 23rd, 2009 at 6:12 am
I downloaded the buttons-within-a-scene.fla I am using Flash CS4. When I preview the flash file, the screen shows a button with “label” as the text. In the output window, I get the following error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at buttons_fla::MainTimeline/__setProp_mbutton1_monkeyScene_buttons_0()
at buttons_fla::MainTimeline/frame1()
I find that Actionscript 3 is very frustrating. It used to be simple to create button navigation that called specific frames in the timeline.
Jen deHaan
June 23rd, 2009 at 12:31 pm
@Lani: I’m not running into any errors in Flash CS4 with the updater. Perhaps check that it is installed? (Help > Updaters). I know there were some issues fixed in this area.
Jen deHaan
June 23rd, 2009 at 12:32 pm
@Misty: Check out the attached FLA file to this blog post to see if it helps you in regards to where the code is placed and how the document in general is structured.
Ag
July 5th, 2009 at 7:46 pm
Hi,
I downloaded your fla example, and it didn’t work at first until I made the update. However I’m facing a huge problem when trying to do something extremely similar. On my website (http://www.engsoc.org/~agutier2/) I get an error, #1009 Cannot access property or method…..
I have 22 buttons at scene 1, frame 1. Only one has Actionscript so far, this is linked to frame 2 (resume) so my problem is that when pressing the button to go back, it gives me that #1009 problem, as It goes back to the first frame but apparently the stage is not loaded or so I’ve read in so many more places.
my code is the following:
resume.addEventListener(MouseEvent.CLICK, clickSection);
function clickSection(Event:MouseEvent):void
{
gotoAndStop(1, “Resume”);
}
and the button instance IS named “resume”
and on the resume frame,
stop();
pdf.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest(”http://www.engsoc.net/~agutier2/images/Resume/AGutierrez.pdf”);
navigateToURL(targetURL);
}
w2003.addEventListener(MouseEvent.CLICK, Clicking);
function Clicking(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest(”http://www.engsoc.net/~agutier2/images/Resume/AGutierrez.doc”);
navigateToURL(targetURL);
}
w2007.addEventListener(MouseEvent.CLICK, Clicker);
function Clicker(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest(”http://www.engsoc.net/~agutier2/images/Resume/AGutierrez.docx”);
navigateToURL(targetURL);
}
index.addEventListener(MouseEvent.CLICK, backtomain);
function backtomain(event:MouseEvent):void
{
gotoAndStop(1, “Index”);
}
I would really appreciate if anyone could help me with this problem I’ve been on it for a few days now and I can’t find anyone having the same problem.
Thank you guys for taking the time to help!
Jim
July 8th, 2009 at 1:21 pm
Jen I have added a button like this
hotAC_btn.addEventListener(MouseEvent.MOUSE_DOWN,
hotACDemos_P_Handler);function
hotACDemos_P_Handler(event:MouseEvent):void {
gotoAndPlay(66);
}
frame 66 loads a child SWF … everything works great, but later in the movie after I remove that child my button does not work. So I put in
hotAC_btn.addEventListener(MouseEvent.MOUSE_DOWN,
hotACDemos_P_Handler);function
hotACDemos_P_Handler(event:MouseEvent):void {
gotoAndPlay(66);
}
again on another frame after the removeChild I get duplicate function defined. What code can i add to recall or reinitialize the button without having to add another one. I can get it all working if I add a the same button with different handler names, but that gets messy.
Thanks in Advance
Jim
July 8th, 2009 at 3:04 pm
Got it I think .. somehow flash was forgetting the call for the function. So I just added
hotAC_btn.addEventListener(MouseEvent.MOUSE_DOWN,
hotACDemos_P_Handler);
back in on frame 65 and everything is working GREAT!
If there is a better way I would love to know.
Ravi
July 28th, 2009 at 8:31 pm
Hi All, I am new to AS3.0 please help me.
I have four main buttons in a movieclip on the main timeline with AS telling them to gotoandplay different frames on the main time time line which has different movieclips at different frames. Inside the movie clips i have sub buttons which has gotoandplay script to different Frames in the same movieclip. it all plays well, but when i click on a button inside the movieclip to gotoandStop frame two it does and when i click on the main button nothing works. Can any one help me out , below is the code i have used.
Main buttons code
function main1Click(event:MouseEvent):void {
MovieClip(root).gotoAndStop(”dashboard”);
}
mainBtn1.addEventListener(MouseEvent.CLICK, main1Click);
function main2Click(event:MouseEvent):void {
MovieClip(parent).gotoAndStop(”stats”);
}
mainBtn2.addEventListener(MouseEvent.CLICK, main2Click);
function main3Click(event:MouseEvent):void {
MovieClip(root).gotoAndStop(”four”);
}
mainBtn3.addEventListener(MouseEvent.CLICK, main3Click)
sub buttons code indside moviclip
stop();
function testMain(event:MouseEvent):void {
gotoAndStop(2);
}
test_btn.addEventListener(MouseEvent.CLICK, testMain);
function Homebtn(event:MouseEvent):void {
gotoAndStop(1);
}
home_btn.addEventListener(MouseEvent.CLICK, Homebtn);
aaron
August 17th, 2009 at 5:03 pm
Sarah (posted on September 26th, 2008 at 2:02 pm),
did you ever get your problem fixed? i am using almost identical code and am having the same issues. they buttons work in the first scene, past that, nothing works.
thanks!
Jen deHaan
August 17th, 2009 at 11:22 pm
@aaron: Make sure you have a stop() action on the other scene(s). My guess is your movie may be hitting the end of the timeline and going back to the beginning?
MiraS
August 29th, 2009 at 6:55 am
Hello,
I’m new in Flash and I’m very thankful when I find places like this site. I’ve read the replies here, trying to figure out my problem but i couldn’t so I’m asking for some help.
I’m making lets call it a presentation and have 1 scene for the intro, 2nd for Menu with 5 btns for now and the rest of the scenes are the “goals” of the buttons. Pretty simple right. I have no problems linking 1st and 2nd scenes but when I tried to link one of the buttons to its goal scene I got an error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Projectandscenes_fla::MainTimeline/frame316()
I don’t have frame 316 in either of my scenes. It’s nothing there so I don’t know how to fix it.
Please help and thank you for the time.
Jim
September 2nd, 2009 at 5:25 am
Jen HI! Thanks for this great for this great POST. It was a huge help! I would like a button to go to a new URL load that movie and play a specific scene. Can that be done? If so how might I do that?
Jackie
September 2nd, 2009 at 12:34 pm
trying to figure this out: i have 2 scenes in my fla. one is the preloader, the other is scene 1. in scene 1 i have a layer named menu and a layer names contents. the menu layer has 7 buttons, the contents layer has a movie clip. within that movie clip, there are 2 layers, one with action script and the other with text. the text layer has 7 frames each with different text. what im trying to do is link the buttons on the main scene (scene 1) to the frames within the movie clip in the contents layer. how do i do that?
if the frames were within the any layer on scene 1 it would be easy with the instructions above. but they are within a layer. help? been trying to figrue out for 3 days already (self teaching flash newbie here…)
Jen deHaan
September 4th, 2009 at 9:32 am
@MiraS: When a SWF is compiled, it puts all of the Scenes onto a single timeline. Say your first scene has 200 frames, frame 316 would be frame 116 of Scene 2. Hope that makes sense. The first thing I’d check with that error is whether your code and buttons are at the same frame location (for example, if your code was at frame 1 but your buttons at frame 2, you would see such an error.
@Jim: You could use the button code to get a new URL from here: http://flashthusiast.com/2008/02/25/making-a-button-work-in-flash-cs3-with-actionscript-30-its-not-too-bad/. In the SWF that is on the second page, you could load the scene. If you’re wanting to target specific scenes from the different buttons, you might want to look into URL variables so you can target them from the button URLs and use that in the second SWF.
@Jackie: To target a frame inside a MovieClip, you would use code such as the following (where myMC is your movie clip):
button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownHandler(event:MouseEvent):void {
myMC.gotoAndStop(5);
}
So the simplest revision would be to just add that one additional line (go to and stop at the scene, and go to and stop at the MC’s frame), as in the following:
button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(1, “scene2″);
myMC.gotoAndStop(5);
}
Kevin
September 8th, 2009 at 2:16 pm
Hello. I have a Flash CS4 .fla that has four buttons in it - it is a single scene. Each button goes to a different frame in the file. The code is very straightforward and is similar to examples I have found all over this site. However, only the first three buttons work. The fourth button, if clicked on, will display the proper contents, but the other buttons will not take you back to the other scenes. To make this even more obtuse, if you let the file work its way down to the fourth button on its own (without clicking on button 4 to go there immediately) then the buttons DO work. I am all out of ideas. I have worked with Flash since version 5 and have not seen this kind of craziness before.
I thought it might be a corrupt file, so I re-created the project again from scratch, and I get the same thing. Help?
Here is the URL to view the file: http://webpost.isws.illinois.edu/
And here is the code for the buttons under button 4:
ButtonS4B1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS4B1);
function mouseDownHandlerS4B1(event:MouseEvent):void {
gotoAndPlay(1, “Scene 1″);
}
ButtonS4B2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS4B2);
function mouseDownHandlerS4B2(event:MouseEvent):void {
gotoAndPlay(81, “Scene 1″);
}
ButtonS4B3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS4B3);
function mouseDownHandlerS4B3(event:MouseEvent):void {
gotoAndPlay(161, “Scene 1″ );
}
I also have similar code (that works) for Button Three, etc:
ButtonS3B1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS3B1);
function mouseDownHandlerS3B1(event:MouseEvent):void {
gotoAndPlay(1);
}
ButtonS3B2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS3B2);
function mouseDownHandlerS3B2(event:MouseEvent):void {
gotoAndPlay(81);
}
ButtonS3B4.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerS3B4);
function mouseDownHandlerS3B4(event:MouseEvent):void {
gotoAndPlay(241);
}
I am more than willing to provide the source .fla file if you are interested in taking a quick look.
Thanks!
sandrar
September 10th, 2009 at 11:50 am
Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.
Bob
September 26th, 2009 at 9:55 pm
Brand new to Flash. Need help with AS3, not for a website, but for student interactive learning
I have 1 generic button that I use called next. I have 3 copies this button and given each copy a different instance name.
Easy part first,
1 button I want to do a frame by frame advance
1 button I want to do a frame by frame previous
Code I have as follows
MasterPrev_btn.addEventListener(MouseEvent.MOUSE_DOWN, MasterPrevDownHandler);
function MasterPrevDownHandle(event:MouseEvent):void
{
gotoAndStop(prevFrame);
}
MasterNext_btn.addEventListener(MouseEvent.MOUSE_DOWN, MasterNextDownHandler);
function MasterNextDownHandler(event:MouseEvent):void
{
gotoAndStop(nextFrame);
}
The 3rd button is a little more difficult, maybe!!
I want this to randomly jump between frame lables.
Code for this I have tried
MasterRand_btn.addEventListener(MouseEvent.MOUSE_DOWN, MasterRandDownHandler);
function MasterNextDownHandler(event:MouseEvent):void
{
choice = Math.round(Math.random()*33);
switch (choice)
{
I have got this working in AS2, however on another scene I have a Drag&Drop facility that I want to use
Surprisingly enough this code doesn’t work, that why I need help :(
help is very much needed
Bob
September 26th, 2009 at 9:56 pm
Sorry, can email the fla file if required
Bob
September 27th, 2009 at 5:55 pm
Ok I managed to figure out the frame by frame adavence and previous by using the code
MasterNext_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandlerMN);
function mouseDownHandlerMN(event:MouseEvent):void {
gotoAndStop(currentFrame+1);
But help is required for the random. Please I would like to get this going for my Students soon.
Thanks
Bob
September 28th, 2009 at 3:55 am
no worries, managed to fix that problem.
Who’s a drag and drop expert??
new problem arisen hehe
multiple frames drag and drop, first frame drags and drops fine, however when move to next frame, the first image is still there, how to refresh the screen to prevent the previous image from appearing on the current frame.??
Josh
September 29th, 2009 at 10:03 am
Hey I’m getting the TypeError: Error #1009: Cannot access a property or method of a null object reference.
at DSWEBSITE2_ABOUT_fla::MainTimeline/frame26()
I don’t really understand why… the buttons on the main page work fine…. but on the 2nd page, “About” page… none of the buttons work and I get the error once when the action script frame comes up….
stop();home_btn.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler5);function
mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(98,”HOME”);
}
projects_btn.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler6);function
mouseDownHandler6(event:MouseEvent):void {
gotoAndPlay(1,”PROJECTS”);
}
video_btn.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler7);function
mouseDownHandler7(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.vimeo.com/6039176″));
}
contact_btn.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler8);function
mouseDownHandler8(event:MouseEvent):void {
gotoAndPlay(1,”CONTACTS”);
}
thats the code I’m using of the page that doesn’t work… each one is segmented into scenes… I don’t get it… ugh… must kill… or get helped…. please help!
Karbo13
November 1st, 2009 at 5:55 pm
Just an observation:
In your file to download (buttons-scenes.fla), I got a error, the buttom in frame 5 in monkeyScene has same instance name and same function name, then I change both names and put my own buttoms. Now all is OK.
Thank you very much for this tutorial.
A greeting from Guatemala, City.
josue
November 5th, 2009 at 1:30 pm
ok iam working on cs4 with 3 frames iam using this
stop();
ONE.addEventListener(MouseEvent.CLICK, clickButtonHandler);
function clickButtonHandler(event:MouseEvent):void {
gotoAndStop(2);
}
TWO.addEventListener(MouseEvent.CLICK, clickButtonHandler2);
function clickButtonHandler(event:MouseEvent):void {
gotoAndStop(3);
}
for my buttons it goes to the next frame but then it doesn’t want to go to the third frame I GET
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at project6_Scene1_fla::MainTimeline/frame1()
mwa
November 24th, 2009 at 8:12 pm
HELP ME . . so i have transfered my flash file from my skool comp to my home one, both use Flash CS4 and action script 3 . . BUT . . when i transfer it onto my home Flash program it comes up with heaps off errors! and on the skool computer it was fine!
ALSO . . why cant it find my scene when i know its in the same file?
eg:
ArgumentError: Error #2108: Scene CoverPage was not found.
at flash.display::MovieClip/gotoAndPlay()
at CLICKTOVIEW_MapOfAus_fla::MainTimeline/enterBookPage()
I really need help . .
anything would be good right now!
Thanks,
mwa
JaymanJohn
November 26th, 2009 at 4:49 am
from Malaysia with love!
thnks!
Pontus
December 8th, 2009 at 10:49 pm
Hi, i have a menu in my fla file where i want to link to 4 diffrent scenes. I have used this code:
stop();b60.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);function mouseDownHandler1(event:MouseEvent):void {
gotoAndPlay(1, “Scen 1″);
}
b70.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);function mouseDownHandler2(event:MouseEvent):void {
gotoAndPlay(1, “Scen 44″);
}
b80.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);function mouseDownHandler3(event:MouseEvent):void {
gotoAndPlay(1, “Scen 45″);
}
b90.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler4);function mouseDownHandler4(event:MouseEvent):void {
gotoAndPlay(1, “Scen 50″);
}
But it dosent work.
The movieclip i have in the file dosent start when i add this code and if i click the buttons they say that the scenes that i have in my file dosent exist.
How can i solve this?
Please help.
meda
December 11th, 2009 at 5:06 pm
You are awesome, the way you explain and demo is clear. Thank you for your blog and directions, now my homework is done.
jouky
December 19th, 2009 at 5:33 am
Hi. I’m having a problem with my flash website using AS3.
Here is the problem I encountered, whenever I click a button on my website it just keep poping out this error message :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CFMWEBSITE_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at CFMWEBSITE_fla::MainTimeline/profile_homepage()
Here is my code:
stop();
homebutton.addEventListener(MouseEvent.MOUSE_DOWN,home_linkpage);
function home_linkpage(event:MouseEvent):void {
gotoAndStop(1,”Homepage”);
}
profilebutton.addEventListener(MouseEvent.MOUSE_DOWN, profile_linkpage);
function profile_linkpage(event:MouseEvent):void {
gotoAndStop(1,”Profilepage”);
}
animationbutton.addEventListener(MouseEvent.MOUSE_DOWN,animation_linkpage);
function animation_linkpage(event:MouseEvent):void {
gotoAndStop(1,”Animationpage”);
}
gallerybutton.addEventListener(MouseEvent.MOUSE_DOWN, gallery_linkpage);
function gallery_linkpage(event:MouseEvent):void {
gotoAndStop(1,”Gallerypage”);
}
linkbutton.addEventListener(MouseEvent.MOUSE_DOWN, link_linkpage);
function link_linkpage(event:MouseEvent):void {
gotoAndStop(1,”Linkspage”);
}
How can I solve this problem? Thank
Garth
December 19th, 2009 at 1:21 pm
Hope you can help. I am new to flash, but am on a steep learning curve as am a fast study. I am building my first site and it is a bit complex. It resembles a family tree structure of movie clips within movie clips with buttons animating in other movie clips that are mixed into more movie clips. Seems a bit much perhaps, but it was needed to acheave the desiered look and functionality. Problems started with navigating a time line from buttons located tree or so branches down. Though I never found anything to help me in any tutorial I looked at, I did figger it out. The code needs to be in the timeline that you are navigating while you referance the button instance. Problem solved you may say, well no. A new one popped up that is to me not saposed to be there, which is that while navigating the buttons, the ones that scroll out for finer navigation do not always work. Hard to explane it better with out writing a book on it.
Hope you can help or someone to give an idea.
Garth
December 21st, 2009 at 3:55 pm
Update… Still no luck, even tried re-aranging everything to different locations. Seems that I am able to brouse the menuĀ“s top down, but go bottom up and they no longer work. Home button re-sets the scene, so if I know where I want to go, then I can go straight there. No good though for people brousing the site though. Any thoughts on why. Would not have this problem if I made the site in Dreamweaver. P.S. I had started in Dreamweaver, but menus and frames do not mix well if the frame is not big enough.