In this tutorial, RC covers how to create buttons that call to urls using Action Script 3.

Share & Enjoy


Similar Articles

 

  1. andreas (Reply) on Friday July 18, 2008

    HELP! No matter witch site I try i get this message in the “OUTPUT” bar.

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at AL_fla::MainTimeline/frame1()

  2. markm (Reply) on Friday July 18, 2008

    Hello all,

    I am very new at flash.
    I have a problem i have been working for hours, obsessed about getting this problem solved. No avail, help.

    I need a button to go to a URL, and you have the AS, but when I tried this it does not work for me.

    I took your code and put in my stuff and it still does not work. This is what I did.

    btn.addEventListener(MouseEvent.MOUSE_UP, goMidniteoilSite);
    function goMidniteoilSite(Event:MouseEvent):void {
    var MidniteoilURL:URLRequest=new URLRequest;
    ‘http://www.midniteoil.com/NEW/logos.html’;
    navigateToURL(MidniteoilURL);
    }

    I am getting a syntax error on this line ‘http://www.midniteoil.com/NEW/logos.html’;

    This all started when I found a flash intro I liked and went bought it and played inside and stuff. It was created with Flash 6 in AS1. I am working inCS4 and when I wanted to ad this button in AS3 it told me actions will not work from that bought intro flash. This also took a while to figure out.

    In process of elimination let me try a button in straight CS4 without anything from the Flash 6 and the code is still not working.

    I followed RC’s tutorial and still nothing. Can you folks help me so I can get my life back. Appreciate all the help.

  3. Leah (Reply) on Friday July 18, 2008

    I have tried every single code listed here in Flash CS4…all I want is for my button to open another flash html file I have created…this code worked beautifully on a previous project I did in CS3…but I get all kinds of syntax errors in CS4. What gives?

  4. Leah (Reply) on Friday July 18, 2008

    Nevermind! :) I got it to work….and I got the url to open in the same window. The code is as follows:

    homebutton.addEventListener(MouseEvent.MOUSE_UP,goLipstickSite);

    function goLipstickSite(Event:MouseEvent):void {
    var LipstickURL:URLRequest= new URLRequest(“LipstickStilettosSite.html”);
    navigateToURL(LipstickURL,”_self”);

    }

    **There must be a space between =, new, and URLRequest
    the quotation marks WILL work…(they did for me anyway) you don’t have to use apostrophes. The _self tag also worked wonderfully. Thank you so much RC and everyone else! :)

  5. artbum (Reply) on Friday July 18, 2008

    Has anyone concluded (like I have) that AS3 is a total hassle and waste of time??

    Before, all you needed was:

    on (release) {
    getURL(‘http://www.yahoo.com‘);
    }

    THAT’S IT! YOU WERE DONE! What’s with all this ‘function’ nonsense, and variables, and listeners, and gooblygocks and dorkyMcfuzzes?

    Thanks a lot ADOBE. Clients love it when we take 4X as long to do a simple task due to RE-learning shit we already knew.

  6. markyb (Reply) on Friday July 18, 2008

    Hi Actionscripters.. Im a designer struggling with a basic AS3 task…I cannot get rid of this Error #1009, driving me nutts!

    I want to use a series of buttons to link to different URLs. If i remove the “btnPrint” instance name, i can get this code to work for 1 button. But add the instance name back in, or try to add this code for more than 1 button, and up comes the Error #1009.

    here’s my script:

    // print button
    btnPrint.addEventListener(MouseEvent.CLICK, callLink);
    function callLink(event:MouseEvent):void {
    var url:String = “printing/”;
    var request:URLRequest = new URLRequest(url);
    try {
    navigateToURL(request, ‘_parent’);
    } catch (e:Error) {
    trace(“Error occurred!”);
    }
    }

    // photo button
    btnPhoto.addEventListener(MouseEvent.CLICK, callLink2);
    function callLink2(event:MouseEvent):void {
    var url2:String = “photography/”;
    var request:URLRequest = new URLRequest(url2);
    try {
    navigateToURL(request, ‘_parent’);
    } catch (e2:Error) {
    trace(“Error occurred!”);
    }
    }

    Testing the script shows no errors, and there are no errors when publishing. I only get this error #1009 when Flash Player has played the swf file.

    Ive checked my instance names and they are all there and have no typos. This script is on its own frame. Is there anything obvious Im doing wrong?!
    Please help!

  7. markyb (Reply) on Friday July 18, 2008

    …and I have just changed my script to use to single quotation marks; does not solve my problem

  8. Rudi (Reply) on Friday July 18, 2008

    Hello there.

    I’m a new actionscript user. I can do very, very basic stuff. I do use flash itself VERY often and I’m fairly good (if I may say so). My problem is very much like what some of you have. I created a flash website and on the one side I have my buttons. The problem is I don’t know what to do now!! Where do I go and what do I type? Do I need to define instance names for each button before I start the action script?

    PLEASE HELP!! Thanks

  9. John BianRosa (Reply) on Friday July 18, 2008

    Well, I read through all of the above and I keep getting this error – 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
    Am using CS4 adn this is my code…
    button.addEventListener(MouseEvent.MOUSE_UP, goLayersSite);

    function goLayersSite(Event)
    {
    var site = new URLRequest(‘http://www.xaverian.org‘);
    navigateToURL(site);
    }

    Have even tried (Event:MouseEvent):void

  10. John BianRosa (Reply) on Friday July 18, 2008

    Never Mind. thanks anyway. I changed the name ‘button’ to ‘btn1′ and it worked. Guess ‘button’ is a reserved word?

  11. Jenny (Reply) on Friday July 18, 2008

    THANK YOU!!!!
    I have done so much research in books and on the web trying to find out how to add a llink to a web banner. You would think its a big secret or something as difficult it is to find out how to do it. This is the first turtorial that actually explains the process and the code works! Thank you so much.

  12. www.simianart.com (Reply) on Friday July 18, 2008

    Brand new CS4: copied tutorial same to same. click on button does not open any browser whatsoever. Are there any other environmental settings like permissions blah blah?

  13. www.simianart.com (Reply) on Friday July 18, 2008

    AAH! I found it… when I saved the .fla in D:\ drive, it is failing. But when .fla is saved in “My Documents” (OS is on C: drive) it works!!! WTF!!!

  14. gama (Reply) on Friday July 18, 2008

    Thank you RC for your tutorial and clarifications notes. I appreciate the few people like you out there that takes the time to teach us.
    About some commentators in this blog, I find disconcerting those of you that made some nasty comment in this blob, is it some kind of power trip? Were is your empathy(the ability to “put oneself into another’s shoes,” in case you forgot)? People come from many different places and may or may not be prepared to tackle the problem at hand, but the mere fact that they posted their question no matter how dumb it may appear to you should deserve some respect. Be cool…

    And for some of you who critic the teacher why don’t you try teaching see if you can do better. I think constructive criticism is always welcome by anyone but insult never helps it is upsetting and is a waist of the reader’s time and yours. Be cool too.

  15. Andrew Wilson (Reply) on Friday July 18, 2008

    Getting error messages on multiple buttons:
    ArgumentError: Error #1063: Argument count mismatch on flash.net::URLRequest(). Expected 0, got 2.
    at awd_fla::MainTimeline/goInteractiveHandler()

    What am doing wrong?

    intr_btn.addEventListener(MouseEvent.MOUSE_DOWN, goInteractiveHandler);
    function goInteractiveHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(“interactive”,”_self”));
    }
    prt_btn.addEventListener(MouseEvent.MOUSE_DOWN, goPrintHandler);
    function goPrintHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(“print.html”,”_self”));
    }
    id_btn.addEventListener(MouseEvent.MOUSE_DOWN, goIDHandler);
    function goIDHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(“identity.html”,”_self”));
    }
    abt_btn.addEventListener(MouseEvent.MOUSE_DOWN, goAboutHandler);
    function goAboutHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(“about.html”,”_self”));
    }
    cont_btn.addEventListener(MouseEvent.MOUSE_DOWN, goEmailHandler);
    function goEmailHandler(event:MouseEvent):void {
    navigateToURL(new URLRequest(“mailto:work@andrewwilsondesign.com”,”_self”));
    }

  16. Shaun Thomson (Reply) on Friday July 18, 2008

    Hey RC – thanks for the video – it’s helping me a lot.

    I have two questions if you are able to help a little more…

    1) I notice there are property type windows down the bottom of the screen where you added the instance name. My workspace doesn’t have them, and I was wondering how to bring them up?

    2) the timeline for my button symbol just has ‘layer 1′, no ‘action layer’. How do I make an action layer?

    Cheers

    Shaun

  17. André Guerra (Reply) on Friday July 18, 2008

    Great tutorial!
    Got it how to do it before it even ended!
    Thanks a lot!

  18. \_- UAI -¯\ (Reply) on Friday July 18, 2008

    [quote]Comment by jason | July 22, 2008 @ 9:27 am

    Seriously… Ya need to be THAT spoonfed? Two people have ALREADY put the code up here, how about just reading?
    [/quote]

    Look, jason, I used to be pro at AS2 with Flash 8, but now with this cs3/4 I can’t even add actionscript to a button. It’s pretty confusing going with this change, sorry if it bothers you. (not)

  19. Jamie (Reply) on Friday July 18, 2008

    Great tutorial, but I’d like to load the html page into a certain area of the flash page–or maybe into an iframe–is there a way to do that via flash?? I’d so appreciate some help. Thank you!!!

  20. Xflash user (Reply) on Friday July 18, 2008

    WHY IN GODS NAME WOULD THEY TAKE AWAY SIMPLICITY FOR COMPLEXITY????

  21. Chris (Reply) on Friday July 18, 2008

    Pretty easy as described in the tutorial. Have the battle is paying attention!

  22. Al (Reply) on Friday July 18, 2008

    I’ve copied and I’ve pasted code after code after code. The amount of time I’ve put into assigning a simple URL to a button is absurd! The preceeding bantor, and this whole process is manic. I’ve been using Photoshop, and many other Adobe products, since Adobe was in their infancy. I have sworn by Adobe for years, and years. But this caviat is single-handedly making me wonder if the Adobe developers have gone to some remote location in Central America and sipped on the wrong Koolaid. Atmittedly, some folks are having a fair amount of success with this task. But, if you look at the number people who are having issues with this most basic of web development procedures, the number is disturbing. Adobe, you need to be able to click on your button and have a text box come-up with the title “Associate URL”. Period. This is freaking rediculous. And that is coming from a very adamant Adobe supporter. Devs, you’re creating serious bad karma here.

  23. andy (Reply) on Friday July 18, 2008

    How does this work with multiple buttons? if i have 5 buttons that go to different frames of the timeline do I put that script in for all 5 buttons on the same frame in the action layer? Do I only have to do that once?

  24. Michael (Reply) on Friday July 18, 2008

    FINALLY A SOLUTION!
    I am a VB6 Guy but I never saw something like this!
    (the change AS2 to AS3 with getURL is stupid!)

    That there is no function (right click-url-done)
    I am sitting now ~5 Hours and only your Video worked !!!

    Thanks a lot
    Michael
    PS: maybe only show the Source in the cam and not the full screen!

  25. Jim The WebGuy (Reply) on Friday July 18, 2008

    You know, that he is using “goLayersSite” because that is what he chose…you can use anything…you could have

    btn1.addEventListener(MouseEvent.MOUSE_UP, anyWordHere);

    function anyWordHere(Event:MouseEvent):void {

    var anyNameHere:URLRequest = new URLRequest(’http://www.layersmagazine.com’;
    navigateToURL(sameNameAsFUnctionHere);

    }

  26. tonny (Reply) on Friday July 18, 2008
  27. Nikki (Reply) on Friday July 18, 2008

    I have a two buttons that I want to link to two different frames in my timeline. How do I do this?

  28. easley homes for sale (Reply) on Friday July 18, 2008

    Hi, I just found your weblog via yahoo. Your article is truly pertinent to my life right now, and I’m really happy I found your website.

  29. Delma Lovins (Reply) on Friday July 18, 2008

    Quite a beautiful website. I recently built mine and i was looking for some ideas and you gave me a few. May i ask you whether you developed the website by youself?

    Thank you

  30. swapna (Reply) on Friday July 18, 2008

    hi !
    on (release){
    gotoandplay(“scene”,”frame”),
    }
    in my website their is 9 button but only 6 buttons are play …….file size is 8.9 mb
    plz give me solution…

  31. Josh (Reply) on Friday July 18, 2008

    I’ve been working on a new website for my work. I have learned everything without any knowledge of Adobe and feel I’ve been doing pretty awesome. Now, I’ve made my flash banners, I’ve added the Action Script to my button and everything looks like it should work, I have NO syntax errors :) but when I test my flash banner it shows a hand like it should be clickable but when I click, it doesn’t do anything! I have spent mucho time trying to figure this out and this video has been the closest to anything I’ve seen that would work. I’m quite frustrated and just want it to work….please help me.

  32. disco_dog (Reply) on Friday July 18, 2008

    thanks this worked for me for my school assignment, i couldnt read the screeen properly so i had to copy the text from someone else comment. please zoom in or make a better quality video on the final text please.

    cheers

  33. Nikki (Reply) on Friday July 18, 2008

    re: Flash Buttons with Action Script 3 video

    I couldn’t read the scripting on this video, the resolution was too low. Any chance you could paste in the code so I can see it properly?

    Thank you. I think this will help me program my button and I’ve been struggling!

  34. Eleazar (Reply) on Friday July 18, 2008

    Really useful. Thanks!



Planet Photoshop Photoshop World Kelby Training Lightroom Killer Tips NAPP Scott Kelby