…the site you can never remember how to type…
So I used to monitor comments coming in from the CS3 Video Workshop, which contains a few hundred video tutorials on the CS3 products. Some of the comments that came in regarding the Flash videos was how people were having frustrations about how to set up button code with ActionScript 3.0. I thought that’s where I’d start out, with a simple example that compares the two.
Luckily, the set up is pretty much the same assuming you put code on the Timeline. If you didn’t, it will be a bit of a change and you’ll need to follow the steps below.
When you were using ActionScript 2.0, you would put code on the main Timeline. You’d have a button on the Stage with the instance name myBtn (set in the Property inspector). You would add code to frame 1 that reads:
myBtn.onRelease = function() { getURL("http://www.flashthusiast.com"); };
In ActionScript 3.0 it looks a bit different. And yes, it’s an extra line of code and it is a bit more complex looking. However - you don’t need to use classes or anything, set up is the same. Here are the steps you’d take to create an interactive button in Flash CS3.
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); function mouseDownHandler(event:MouseEvent):void { navigateToURL(new URLRequest("http://www.flashthusiast.com/")); }
And that’s all there is to creating a clickable button with AS3. All you need to do is change the URL to make it work in your own document. You can also change the MouseEvent from MOUSE_DOWN to, say, MOUSE_OVER to change how the interaction works. Search Flash Help for MouseEvent, and look at the Class in the ActionScript 3.0 Language Reference.
If you have MORE THAN ONE BUTTON and want to add that to your FLA file, please continue on to this post about adding multiple buttons to your file.
This is Jen deHaan's latest blog in her neverending series of blogs. In the beginning there was deseloper. A designer developer. Now it's Flashthusiast, an enthusiast about Flash. Are you a Flashthusiast? Read on! This blog is about Adobe Flash, and will include tips, techniques and info on drawing, animation, and a bit on ActionScript 3.0. Jen is a QE on the Flash team at Adobe (San Francisco).
Vlad
February 26th, 2008 at 1:21 pm
I probably put a comment in the wrong spot … ups. I just made my first button using CS3 and can’t make it work because scripting 3 is like a whole new moster. I just need to go to the next frame. HELP!
Jen, a flashthusiast
February 26th, 2008 at 2:11 pm
Hey Vlad,
luckily you just need to modify the code above, and it’s pretty much the same as AS2 :) This should hopefully work for you, just swap out the frame number you need to stop at and change the button’s instance name to that of your button –
stop();
my_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
Chet
February 27th, 2008 at 10:14 am
Soooo… what I have three buttons and want them to go to different frames? I repeated the code you provided for each button but Flash says I can’t use the same function multiple times…
Jen, a flashthusiast
February 27th, 2008 at 12:23 pm
Hey Chet,
The quickest way would be to make the three functions for the three buttons, and point them at the three frames. So I just renamed the function for the three instances:
stop();
my_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
my_btn2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(3);
}
my_btn3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(4);
}
John
February 29th, 2008 at 9:05 am
OK, I am pretty much the wettest behind the ears guy around with Flash. I used your tutorial on Flash CS3, and almost understood it, but got all to work. I’m now playing with something else where I want 4 buttons, each re-directing to a new URL. I tried the following to start:
stop();
foodbtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.bc.edu/dining”));
}
peoplebtn.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
function buttonClickHandler (event:MouseEvent) {navitageToURL (new URLRequest (”http://www.cbord.com”));
}
which makes sense to me, but get the following:
1084: Syntax error: expecting rightbrace before end of program.
my first thought was to add a different action to a different layer, but I can’t figure out how to get more than one layer to appear in the action toolbar (or am I way off?)
HELP!
Thanks,
John
John
February 29th, 2008 at 9:11 am
OK, so I can’t even get my code here correctly. It’s more like this:
stop();
foodbtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.bc.edu/dining”));
}
peoplebtn.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navitageToURL (new URLRequest (”http://www.cbord.com”));
}
AND the error is:
Scene 1, Layer ‘food’, Frame1, Line 7 1021: Duplicate function definition. function buttonClickHandler(event:MouseEvent):void{
Jen, a flashthusiast
March 1st, 2008 at 8:50 pm
Hi John,
It’s pretty much the same solution as Chets - the functions (function buttonClickHandler) need to have different names. Alsonitced that there was a little typo in the code (the first navigateToURL).
So the below code changes those two things, and it seems to work :)
stop();
foodbtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.bc.edu/dining”));
}
peoplebtn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (”http://www.cbord.com”));
}
Hope this helps,
Jen.
Kojin
March 5th, 2008 at 6:26 am
Hi there.
I’ve got quite similiar example, the only difference is its about gotoandplay/stop action. It looks like this:
stop();
but1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
gotoAndPlay(2);
}
but2.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
gotoAndStop(25);
}
First button works fine, but second one doesn’t. Instead of going straight into frame 25 and stoping there, it begins animation from frame 2 and stops at the last frame (becouse of stop action in frame 30).
Kevin
March 6th, 2008 at 8:25 am
hi, i cnt seem to get the hang of this. i got 5 buttons in frame 1, and i want each button to to go to different scenes!! how do i do that.
because i tried to make the buttons go to different frames, but for some reason, the 1st button takes me to frame 20 but then all the rest of the button ALSO keeps taking me to frame 20?? heres the code i used:
stop();
drill_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(20);
}
grinder_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(30);
}
Jason
March 8th, 2008 at 4:17 pm
When you make the function unique you need to changes it call too.
stop();
drill_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(20);
}
grinder_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(30);
}
So in:
grinder_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2); <— You add you 2 here as well.
Jen, a flashthusiast
March 8th, 2008 at 7:16 pm
Thanks Jason! I should have definitely tried my code before typing it into wordpress :) Great catch there.
Jean-Francois
March 8th, 2008 at 7:25 pm
Hey, Everyone….
I am a newbie to flash cs3 and as3. I’ve been building a flash website for the past week or so and so far things are going ok. However, I have a navigation menu with buttons I’ve as’d to navigate to a new url. Currently when the buttons are clicked they open the url in a new tab in my net browser; I am using the code below for these buttons:
function HomeBtn(event:MouseEvent):void {
var targetURL:URLRequest = new
URLRequest(”http://www.graemmegilmann.com/gghome/gg_home.swf”);
navigateToURL(targetURL);
}
home_btn.addEventListener(MouseEvent.CLICK, HomeBtn);
What I need to know is how I get these same button instances to open the new url in the same tab I’m already viewing. Any help would be much appreciated.
Thanks.
Kevin
March 9th, 2008 at 2:47 pm
Thanks Jason
D
March 9th, 2008 at 5:31 pm
I have a simpler question…I have a “Scene 1″ and a movie clip within the main timeline.
I have a button inside the movie clip and am trying to reference a “home” frame in the main timeline in “Scene 1″.
I have tried a number of things, but just can’t fuigure it out!
Please let me know and thanks in advance.
vips
March 11th, 2008 at 7:07 pm
Hi I m a newbie to flash cs3. I have worked on flash 5 b4. I need my button to take me to scene 2 from scene 1. Could u please help me with the code?
Thanks a ton!
marieta
March 13th, 2008 at 6:42 am
hi jen..Im pretty familiar with flash buttons and movie clips, unfortunately very little on scripting…i could get buttons to work but my question is ‘how to script a movie clip button within a movieclip? like where to include the actionscript whether in the movieclip, button or on the scene where the movieclip is’
enlightenment will be much appreciated…many thanks
Thomas
March 15th, 2008 at 10:52 am
Hello hello,
I’m new here so forgive me if I like askin stupid questions ;-) but I could really use some help on CS3 actionscript3 thing I’m tryin to work out.
For the BLOG page of my new website I made the top part in Flash and the thing is I need to get the three buttons that are in there workin…I copied the script:
monkey_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.flashthusiast.com/”));
}
and followed the instructions, of course I swapped monkey_btn for mixlawax_button and also renamed the url http://www.flashthusiast.com into http://www.mixlawax.com
AND IT WORKS!!!! :-)
Only thing now is I need the other two buttons to go to other URL’s as well and here’s where the problem starts.
When I copy paste:
stop();
mixlawax_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.mixlawax.com”));
}
home_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler2(event:MouseEvent):void {
navigateToURL(new URLRequest (”http://www.morecult.com”));
}
into the ‘actions’ pane and add it to the first frame and then press TEST MOVIE I get the following error:
Scene 1, Layor ‘actions’, Frame 1, Line 4 1093: Syntax error Navigate ToURL (new URLRequest(”http://www.mixlawax.com”));
1084: Syntax error: expecting rightparen before colon.
1084: Syntax error: expecting rightparen before rightbrace.
1093: Syntax error.
1084: Syntax error: expecting rightparen before colon.
1084: Syntax error: expecting rightparen before rightbrace.
I hope there is someone who can help me out, and yes I know I’m not Einstein hehe
Thanks in advance.
Thomas
PS: In fact my question is how do I make three buttons get three different URL’s in actionscript3??
Thomas
March 15th, 2008 at 1:06 pm
Consider my last post as not sent, got it fixed :-) thanks to Flashthusiast > categories ‘buttons’ duh sorry for my stupidity ;-)
All buttons work now, nice and easy :-)
Thanks!
Peace
Thomas
Mark
March 15th, 2008 at 1:48 pm
Does anyone know how to code the following:
If I want one button to control which frame to go on depending on 2 different selections. Basically, if I choose the color red in one drop down then yellow in the other drop down, when I select the go button, how would I make it go to frame 4 which has the mixed color. I am having a brain fart.
Thanks
Jason
March 16th, 2008 at 11:37 am
D,
I had this same issue and this is what I assigned to my button and it worked for me. This takes my movie to the first frame outside the movie clip.
function playMovieMass(event:MouseEvent):void
{
(root as MovieClip).gotoAndStop(1);
}
Mass_Play.addEventListener (MouseEvent.CLICK, playMovieMass);
Chad
March 18th, 2008 at 8:36 am
I’m a Newbie to Actionscript 3.
I’m trying to do a photo viewer, each photo is on it’s own frame in order, 50 photos total.
I have two buttons, advance and rewind, and can’t figure out how to simply go to next frame with the advance button and go to previous frame with the rewind button.
This is the direction I’m going with the code, it doesn’t work right and I can already see that there must be a much simpler way but I can only find examples where a button goes to a specified frame not simply to next or previous.
stop();
function imgAdvance(event:MouseEvent):void {
gotoAndStop(3);
}
forward_btn.addEventListener(MouseEvent.CLICK, imgAdvance);
function imgRewind(event:MouseEvent):void {
gotoAndStop(2);
}
rewind_btn.addEventListener(MouseEvent.CLICK, imgAdvance);
Chad
March 18th, 2008 at 8:53 am
Sorry I just noticed the second event listener was wrong.
function imgRewind(event:MouseEvent):void {
gotoAndStop(2);
}
rewind_btn.addEventListener(MouseEvent.CLICK, imgRewind);
jennicandance
March 18th, 2008 at 12:33 pm
Get advice Jen!! Thanks soooo much, I’ve been looking for these answers everywhere!
Lou
March 19th, 2008 at 12:49 pm
HI ! a newbie to Flash and AS3. I want to control the LABEL on my button but I can not get the syntax correct.
this.btn_Movie.visible = false;
works to make it visible … but the same code doesn’t work for .enabled or .label.
this.btn_Movie.label = “MyNewLabel”;
I get the following error:
1119:Access of possibly undefined property label through a reference with static type flash.display:SimpleButton
Tried to IMPORT the class:
import fl.controls.Button;
but then I get the error:
1172:Definition fl.controls:Button could not be found
Any help greatly appreciated! THANKS MUCH!!
Carl
March 22nd, 2008 at 5:32 pm
Add a button to your stage and then delete it. This will add a button to your library.
Ruby
March 25th, 2008 at 4:31 am
I have five text buttons linking to 5 different states on a website(home, about, news etc).
i have added the following script:
stop();
home_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(1);
}
about_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndPlay(11);
}
news_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler3);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndPlay(21);
}
portfolio_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler4);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndPlay(31);
}
links_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler5);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndPlay(41);
}
i have the following problem:
When i click a text button(doesn’t matter which one) it works fine. Then none of the buttons work after that. Assumedly because the script has not been added to the other states on the timeline. When i add the script to the five corresponding states on the timeline, i get compiler errors (duplicate script).
what’s the correct action to take?
Ingrid
March 25th, 2008 at 3:22 pm
I was having the same trouble as Ruby above me, I could get to one page but after that the script went nowhere. I tried changing my MouseDown handlers to increment by one and double-checked my button names and that fixed it for me. My layers are set up so that the action covers all of the frames.
Hope that helps.
Scripting confuses me but this article is great. I’m almost there! Thanks :)
Edo
March 25th, 2008 at 6:58 pm
Hi guys i’m new to the flash cs3.
After i press the button I don’t want the url to open in a new window ( want to keep it in the same window) how can i do that.
I been trying to add “_parent” but i’m getting an error msg
Tnx
jennicandance
April 3rd, 2008 at 9:22 am
What if I wanted to change the rollover state:
red.buttonMode = true;
red.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
function mouseOverHandler(event:MouseEvent):void {
alpha = 70;
}
This doesn’t work, but I’m confused on how to get it to work. Can anybody help me?
Esben Boye-Jacobsen
April 5th, 2008 at 11:01 pm
I was wondering if it is possible to somehow get the name of the instance from which the action came?
If I press the thisButton_btn, then it could be nice to get the instance name passed as an argument or something - is there some way to do that?
Thanks in advance :)
Braylon
April 10th, 2008 at 9:07 am
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Cartoon_fla::MainTimeline/Cartoon_fla::frame1()
Braylon
April 10th, 2008 at 9:28 am
What is wrong with this? I just want to simply move down the damn timeline! Thanks
stop();
fmr.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
fmr2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(3);
}
fmr3.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler3(event:MouseEvent):void {
gotoAndStop(4);
}
fmr4.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler4(event:MouseEvent):void {
gotoAndStop(5);
}
fmr5.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler5(event:MouseEvent):void {
gotoAndStop(6);
}
fmr6.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler6(event:MouseEvent):void {
gotoAndStop(7);
}
fmr7.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler7(event:MouseEvent):void {
gotoAndStop(8);
}
fmr8.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler8(event:MouseEvent):void {
gotoAndStop(9);
}
fmr9.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler9(event:MouseEvent):void {
gotoAndStop(10);
}
fmr10.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler10(event:MouseEvent):void {
gotoAndStop(1);
}
Jen, a flashthusiast
April 10th, 2008 at 10:38 am
Hi Braylon - make sure your mouseDownHandler’s match each other. For example for your last button it would be
fmr10.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler10);
function mouseDownHandler10(event:MouseEvent):void {
gotoAndStop(1);
}
More information in this post: http://flashthusiast.com/2008/03/13/adding-more-than-one-button-to-a-fla-file-while-rocking-it-in-actionscript-30/
Sam Browne
April 13th, 2008 at 5:03 pm
Hey i am an absolute noob at actionscript 3.0, and i want to make a button that works and links to another scene. Thankyou
Mary Anne
April 17th, 2008 at 4:11 pm
I really appreciate the lesson you have been giving here. I teach a section of a digital imaging class in which I teach students how to build animation, portfolios, and websites in Macromedia Flash. I use MX since that is what is available. I have a student in the class that uses Macromedia CS3. Is there a way to go into normal mode to add actions from preset action scripts like in Flash MX and 8? Also, we are having a hard time finding movie controls under Flash CS3. Any help on this would be greatly appreciated.
David Stephenson
April 19th, 2008 at 9:54 am
Thanks for putting up this tutorial Jen, I was struggling for over an hour trying to figure out how to create the previous and next buttons for a Flash CS3 presentation.
Ja
April 21st, 2008 at 8:08 am
Trying to get my buttons to work in CS3 using the new action script to no avail, my button code is this and it doesn’t for whatever reason move to frame 39.
stop();
aboutBtn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(39);
}
Please help.
Jay
April 21st, 2008 at 8:09 am
Oh and I get this error message
The class or interface ‘MouseEvent’ could not be loaded.
Jay
April 21st, 2008 at 8:20 am
When I use this code the button has no effect.
stop();
aboutBtn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndPlay(39);
}
this is the error message I get
The class or interface ‘MouseEvent’ could not be loaded.
Jen, a flashthusiast
April 21st, 2008 at 10:32 am
Hi Jay - Check that your publish settings are set to AS3. You would see that error message if its set to AS2. If that doesn’t do the trick, please let us know :) Thanks, Jen.
jc
April 22nd, 2008 at 12:29 pm
hey im a total newbie with flash cs3 and i am trying to make multiple buttons to link to several different sites i have tried the tutorial for the one monkey button to no avail seeing as the button didnt link at all i copyed everything word for word
i changed where the button would link to here is my actionscript:
function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”function mouseDownHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.google.com/”));
}
let me now any problems i have with it and any and all tips would be appreciated
jkern
April 22nd, 2008 at 12:53 pm
I can’t find anywhere that explains how to program a button to fast-forward 5 seconds or rewind 5 seconds with AS3. I get the logic (from what I’ve seen similar to this,) that you somehow call the current frame “n,” and you make a function akin to gotoAndPlay(n+5) seconds. I just don’t know the code to do this.
This is the best thing I have found for AS2:
on(press){
this.gotoAndPlay(this._currentframe+30);
slide01.gotoAndPlay(slide01._currentframe+30);
}
Can anyone AS3-ify this?
Jrose
April 23rd, 2008 at 12:32 pm
For those of you who are having problems jumping to difference scenes with a button, here’s how you do it.
button2.addEventListener(MouseEvent.CLICK, buttonClick2);
function buttonClick2(event:MouseEvent):void {
gotoAndStop(1,”Scene 2″);
}
obviously, you can also replace the frame number with a frame label as long as you use quotes, like this:
button2.addEventListener(MouseEvent.CLICK, buttonClick2);
function buttonClick2(event:MouseEvent):void {
gotoAndStop(”start”,”Scene 2″);
}
so you must use both the frame number and scene name with AC3.
JohnB
April 29th, 2008 at 2:08 pm
It tried this script and other variations but they do not work on Firefox, Opera on Windows, or Safari on Mac (and probably windows). I rolled back to Actionscript 2 (GETURL script) to get it to work, which it did except on Safari.
Is there a fix for this? I’ve done tons of research and have found none.
Turtle
April 30th, 2008 at 10:53 am
If I use AS2 - the first image in the slideshow works, the rest do not:
http://www.houstgrandopera.org
boheme.onRelease = function() {
getURL(”/page.aspx?pageid=12016951″, “_self”);
};
briten.onRelease = function() {
getURL(”/page.aspx?pageid=12017716″, “_self”);
};
budd.onRelease = function() {
getURL(”/page.aspx?pageid=12016918″, “_self”);
};
refuge.onRelease = function() {
getURL(”/page.aspx?pageid=12016966″, “_self”);
};
season.onRelease = function() {
getURL(”/page.aspx?pageid=12017620″, “_self”);
};
cornelius
April 30th, 2008 at 3:10 pm
to the flash gods,
i am using 2.0 and i am trying to link a drop down menu to my web pages.
my drop down menu is 4 buttons that i would like to use to load a movie clip into the main contentMC. i have been trying to figure this out for myself but i am a little confused. i am using 2.0 and all the tutorials teach you how to link to an outside url
so my question….
menuBack.resumeBtn.onRelease = function() {
loadMovie(”resume.swf”, contentMC);
};
menuBack is the movie clip name for the drop down menu. resumeBtn is the button inside the movie clip. contentMC is the movie clip that is on stage displaying the swf file.
the code that i have does not work. the buttons drop own but do not allow the swf files to load into contentMC.
when i have the proper working code do i.? put the code into the page actions or the movie clip (menuBack) actions?
any help would be greatly appreciated, i really want to do this on my own but i have hit a road block and i need to get around it.)
cornelius
May 1st, 2008 at 1:24 am
ignore the above comment.. i got it! unles
i was not using the proper instance name… duh!
the above code is correct just make sure that the instance names are correct,
Jayson
May 1st, 2008 at 11:37 pm
I’ve been trying to get these buttons to work with no luck at all haha.
I’m using this code
stop();
import flash.events.MouseEvent;
HomeButton.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void{
gotoAndPlay(1);
}
PortfolioButton.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void{
gotoAndPlay(40)
}
I’m getting this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at PersonalSite02_fla::MainTimeline/PersonalSite02_fla::frame35
please somebody help lol I am totally lost as to whats going on…thanks a bunch
B1
May 4th, 2008 at 6:28 am
I too am also a nOOb - especially AS3.
Have a simple 7 frame project - where we start with frame one, and after frame one is finished by clicking ENTER, the movie shoud got to frame two via: nextFrame ();
It does it for going to frame 2 and 3 and 4 and 5 - but it always skips frame 6, and goes on to the last frame 7.
It makes no sense. So want to know how we can change it so that if each frame has a Frame Label, we can do the same process of moving from frame to frame ( one frame at a time).
All help welcome ! Thanks !!! :)
webbedkitty
May 6th, 2008 at 8:02 am
Grrr, I’m new to Flash CS3 also, and I’m having difficulty with a flash banner template my client purchased. The flash file already has an action layer, i.e. falling dollar bills, and I have added the client logo, however, they want me to add a hotspot to be clicked and navigated to the clients home website, URL. Can I not have two actions layers?
Above the button (inv_btn) layer I made a separate actions layer. I put in the actionscript:
inv_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void {
navigateToURL(new URLRequest(”http://www.example.com”));
trace(”You clicked me.”);
}
And I get an error: The class or interface ‘MouseEvent’ could not be loaded.
What am I doing wrong?
Please help!
Jen, a flashthusiast
May 6th, 2008 at 10:52 am
If you see the error “The class or interface ‘MouseEvent’ could not be loaded” make sure your document is set to ActionScript 3.0 in publish settings.
webbedkitty
May 6th, 2008 at 11:09 am
Thanks, Jen. I think I’m writing 3.0 script for 2.0, whoops!
Does anyone know of any good Flash CS3 beginner tutorials?
Thanks!
Dwayne
May 13th, 2008 at 1:46 am
Hey Jen, what a lovely site you have here, I am a web developer/ designer but now I think I maybe a flashthusiats.
I am creating a computer game its a grand theft auto type thing, could you point me in yo some directions in which i can gather assets for me game.
Thank you
p.s webbedkitty this is a good flash beginners site
http://www.squidoo.com/Flash_Tutorial_hitTest
Enjoy
Super Dwayne
David
May 13th, 2008 at 2:35 pm
I’m having the exact same problem that Ruby did up above, that I’ll click a button, it’ll take me to another frame that has the same buttons on it but then the buttons no longer work. I’m assuming they should be buttons and not movie clips (?) I couldn’t quite understand what Ingrid did but if anyone can point out my errors, it would be SO apprecaited. Thanks.
Joe
May 13th, 2008 at 5:47 pm
Well, i have a template and it is flash 8 running on as 2.0. I used the
mybutton.onRelease = function() {
getURL(”mywebsite”);
};
When I test my movie and click the button I get a new internet explorer window with my site. This is all on flash cs3 but when i open the file on internet explorer or mozilla, when I click the button my new window doesn’t pop up (not because of pop up bloker). If I use the cs3 code you gave me, then all the other code in the rest of the template would need to be changed and I do not have a clue on how to.
Andrew
May 13th, 2008 at 10:34 pm
Hi, I had same prob as Ruby but fixed with same mouseDownHandler number so thanks.
I have two button set up same as each other, but the second one when I test movie runs through its 4 states (up, over, down and hit) continuously like it can’t stop! Why would it do that but the first one doesn’t?
Andrew
May 13th, 2008 at 10:43 pm
Just fixed it - made a new button set up exactly as previous one and it stops now. Damn Flash - why does it do that kind of thing?
Andrew
May 13th, 2008 at 11:03 pm
Sorry another problem has come up. Button 1 goes to frame 2 (correct) then button 2 goes to frame 3 (correct) but if I press on button 1 again nothing happens. Shouldn’t it go back to frame 2 with this script?
stop();
features_BTN.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
location_BTN.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);
function mouseDownHandler2(event:MouseEvent):void {
gotoAndStop(3);
}
David
May 14th, 2008 at 6:33 am
One other thing, I don’t know if this matters, but I was using gotoAndStop(10); on the MouseCLICK because if I used gotoAndPlay, it would cycle through to the end of the timeline. If I put a stop(); script on a different layer, it stays there, but the buttons still don’t work. Any help?
Matteo
May 16th, 2008 at 12:29 am
Hi, great work!
i’m using the code you’ve written in a flash intro, exactly for the button “skip intro” and it works well!
but is it possible to make the page open in the same window and not in a new one? where have i to modify the code?
many thanks!!!!
kipley
May 19th, 2008 at 6:34 am
Okay, I’ve spent hours on what used to be a 30-second task for me in AS2, and still no go. Any suggestions? I turned the word “Home” into a button, then changed the color for the Over and Down states, and then drew a rectangle for the hit area. Only problem is, every time I do this, only the hit area extending outside the text works. It’s almost like the text field masks the hit area. If I make a really big hit area, everywhere outside the text area works. But when I mouseover the text itself, the cursor doesn’t even recognize that it’s a button. What’s going on??? ANy help is much appreciated!
David
May 19th, 2008 at 8:28 am
In the button’s timeline, is the rectangle you drew in a layer above the button states? That should solve your problem.
pete
May 21st, 2008 at 10:52 am
If a button action said this before, what should it say now in CS3?
on (release){
getURL (clickTAG “_blank”);
}
nat
May 22nd, 2008 at 5:44 am
Hi Jen,
I am also very, very new to flash actionScript 3.0, and I needed to know how to set up buttons correctly, I could get one to work but the others weren’t - thank you such much for your info, and for everyone’s posts, I worked out what I was doing wrong (not numbering my event handlers!!) and now it’s all working a-ok. thanks so much!!!
I do have a different problem now, I’ve been searching the net for ages and just can’t find what I am after, I want to make my swf play/pause via one button and I am completely lost! - any help/thoughts would be v much appreciated!!
Sarah
May 28th, 2008 at 3:25 am
Hii .. im new to AC3 … i wanted to creat buttons .. each one of them goes to different frame.. my buttons are in one layer and the content in another one … anyways .. wut does this error mean ??
1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:SimpleButton.
i created a rectangle converted to button and gave it an instance name and wrote this code
this is my code :
import flash.events.MouseEvent;
btnHome.addEventListener(MouseEvent.CLICK, bClick);
function bClick(event:MouseEvent):void{
btnHome.gotoAndStop(1);
}
btnGallery.addEventListener(MouseEvent.CLICK,gClick);
function gClick(event:MouseEvent):void{
btnGallery.gotoAndStop(31);
}
ben
May 30th, 2008 at 5:22 am
Your instructions are so easy to follow. Thank you so many sites out there that make it really hard to understand. You are a champion !
Ben
James
May 30th, 2008 at 10:50 am
Hi I am really new (just few days) to Flash CS3. I am using a script to make a sliding menu bar. However, I could not make the buttons to function. I have tried different ways in using your script.
a. made a new action layer on the movie scene and attached the button script
b. go to edit button mode, made a new action layer and attached the script
The output gave me this message:
‘The class or interface ‘MouseEvent’ could not be loaded.’
The following is the script:
menu.onRollOver = menuOver;
function menuOver() {
this.onEnterFrame = scrollmenu;
delete this.onRollOver;
}
var b = stroke.getBounds(_root);
function scrollmenu() {
if(_xmouseb.xMax || _ymouseb.yMax) {
this.onRollOver = menuOver;
delete this.onEnterFrame;
}
if(menu._x >= 600) {
menu._x = 600;
}
if(menu._x <= -8) {
menu._x = -8;
}
var xdist = _xmouse - 400;
menu._x += Math.round(-xdist / 10);
}
The sliding menu bar script works fine without the button function (I know this sounds silly.. a menu bar without button function). Million thanks for your help! Really appreciate it!
the_other
June 5th, 2008 at 2:14 pm
CS3/AS3 is very different from version 4. I’m lot at this point and need some help.
I have a map with 50 buttons plotted on it. I would like for each individual buttons to launch either a new scene of another swf. I’ve given an instance name for each button “button_13″ and “button_14″ etc. How and where do I add these on the buttons?
Any help would be really appricated.
the_other
June 5th, 2008 at 8:01 pm
I forgot to mention that when I try to add any scripting below stop(); it gives me error and plays all scenes continuously without stopping at the begining of each scene.
Parker
June 12th, 2008 at 8:52 am
Ok, I just started actionscript 3 and im making a website. the top of each frame has HOME ABOUT BLOG PORTFOLIO CONTACT buttons. so on each frame i put this (of course for each frame the buttons had diff. instance names)
stop();
abouthome.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(2);
}
bloghome.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(3);
}
portfoliohome.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(4);
}
contacthome.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
function mouseDownHandler(event:MouseEvent):void {
gotoAndStop(5);
}
cs3 says i can not repeat the same function. i saw that someone named chet made a comment like this earlier, but the answer to his problem didnt even change the code. please help!
Chris K
June 17th, 2008 at 7:45 am
Hey. My problem is that I have a movie clip in ‘Scene 1′. It has a button in it that needs to navigate to a frame label that is not within the movie clip, but within ‘Scene 1′.
I saw some suggested script that could solve it above:
function playMovieMass(event:MouseEvent):void
{
(root as MovieClip).gotoAndStop(1);
}
Mass_Play.addEventListener (MouseEvent.CLICK, playMovieMass);
However, my adaptation of it didn’t work for me. My button instance is ‘nextBtn1′, the frame label that it needs to direct to is ’song menu 2′ and the movie clip is called ‘Songbook Menu 1′ if that is of any relevance. Any help is much appreciated!
Thanks
Michael
June 17th, 2008 at 10:26 am
I am experiencing the same problem as Andrew… when i click button 1 it takes me to frame 5 (correct), when I click button 2 it takes me to frame 16 (correct) but when I click on button 1 again, nothing happens. I have tried everything I can think of, double checked everything, and the actionscript looks correct:
stop();
function gotoAudio(event:MouseEvent):void
{
gotoAndStop(5);
}
btnAudio.addEventListener(MouseEvent.CLICK, gotoAudio);
function gotoVideo(event:MouseEvent):void
{
gotoAndStop(16);
}
btnVideo.addEventListener(MouseEvent.CLICK, gotoVideo);
Any suggestions on anything to try to fix this? Any thoughts are appreciated. Thanks!
goldie
June 22nd, 2008 at 3:38 pm
How do you create a back button in AS3? It all seems like common sense but it is killing me!! My next buttons and my home button both went smoothly.
Dave
June 25th, 2008 at 1:43 pm
Ok so Im a first time user of Flash and Im trying to create a simple training program for some co-workers. Some simple buttons with some simple video clips. I was excited until I found out that I have to use code for button functions. Can anybody please tell if there is another way to use buttons with having to input code?
Dave
June 25th, 2008 at 1:47 pm
Is there any way to create simple buttons with out inputing code?
Ezza
June 26th, 2008 at 8:02 pm
I am creating a game on flash, but having trouble with trying to make a button move from one place to another. I tried using a tween but it wouldn’t move when I played it! All i want it to do is move up and down, but it wont work! All my frames have actions applied to them. Do I have to change the button to a graphic or a movie clip, and what actionscript will i need?
Delatoni
June 29th, 2008 at 11:03 am
>How to link in normally in actionscript 3.0.
function hacks_nav(event:MouseEvent):void
{
gotoAndStop(”hack”)
}
hack_btn.addEventListener(MouseEvent.CLICK, hacks_nav);
*note: for “hacks_nav” you can put what ever you want in its place just make sure they are both the same.
*note: and on “hacks_btn” you just have to put the name of your button you are trying to link.
*note: and on “hacks” you can either use frame anchors like I did or you can use frame numbers. BUT if you use frames numbers just make sure you enter it like this (12) not like this (”12″).
*note: also if you want it to play instead of stop replace “gotoAndStop” with “gotoAndPlay” and it will start playing at that frame instead of going to and stoping.
—————————————————————————–
>How to link to fames on the main timeline from a button nested in a movie clip in action script 3.0.
function trail_nav(evt:MouseEvent):void {
MovieClip(parent).gotoAndStop(”home”);
}
trail_btn.addEventListener(MouseEvent.CLICK, trail_nav);
*note: for “trail_nav” you can put what ever you want in its place just make sure they are both the same.
*note: and on “trail_btn” you just have to put the name of your button you are trying to link.
*note: and on “home” you can either use frame anchors like I did or you can use frame numbers. BUT if you use frames numbers just make sure you enter it like this (12) not like this (”12″).
*note: also if you want it to play instead of stop replace “gotoAndStop” with “gotoAndPlay” and it will start playing at that frame instead of going to and stoping.
—————————————————————————–
>How to make a movieclip dragable in actionscript 3.0.
function tabledrag(event:MouseEvent):void
{
tableMC.startDrag(false);
}
function tabledrop(event:MouseEvent):void
{
tableMC.stopDrag();
}
tableMC.addEventListener(MouseEvent.MOUSE_DOWN, tabledrag);
tableMC.addEventListener(MouseEvent.MOUSE_UP, tabledrop);
*note: for “tabledrag” and “tabledrop” you can put what ever you want in its place just make sure they are both the same.
*note: and on “tableMC” you just have to put the name of your movie clip you are trying to make dragable.
Delatoni
June 29th, 2008 at 11:31 am
>Sorry also note that if you are linking from a button that nested in a movie clip that’s nested in another movie clip you have to alter the code to look like this.
function trail_nav(evt:MouseEvent):void {
MovieClip(parent.parent).gotoAndStop(”home”);
}
trail_btn.addEventListener(MouseEvent.CLICK, trail_nav);
*You are going to want to add another “parent” after MovieClip(parent.parent) like that.
——————————————————————————
>For a Transparent Background And Fullscreen Video’s
In Dreamweaver after you add your .swf file to your page click on the flash movie and in you properties panel look for “perameters” button and click on it and then type…
wmode = transparent
and then click ok and your done.
*note: or if you have a video in .swf that you want to have the fullscreen function work on it just enter this instead…
allowFullScreen = true
—————————————————————————–
Well that’s it I hope this help you guys. :)