7 Replies Latest reply on Oct 22, 2007 6:21 AM by sararas

    simple button link

    sararas
      I'm trying not to cry. I feel like I've been totally blindsided by ActionScript 3.0. All I want to do is add a freakin link to a website on a button.

      I can't find any simple tutorials. Please will someone help me? Either with a sample code snippit or a resource?

      Here is what I HAVE found, but it does not work:


      btn.addEventListener(MouseEvent.CLICK, clickHandler);

      function clickHandler(event:MouseEvent): void{
      navigateToURL(new URLRequest( http://www.adobe.com/));
      }


      I have named the mc on my stage "btn". I get the following two errors:

      '{' expected

      and

      Unexpected '}' encountered


      I'll send happy thoughts your way for any help....

      btw, I removed the quotes around the URL because it was displaying badly in this message.
        • 1. Re: simple button link
          hciguy Level 1
          Don't cry, buy an AS 3.0 book :) Flash CS3 will make designers do more code....anyhow....use the following code:

          btn.addEventListener(MouseEvent.CLICK, clickHandler);

          function clickHandler(event:MouseEvent): void{
          var url:String = " http://www.adobe.com";
          var request:URLRequest = new URLRequest(url);
          try {
          navigateToURL(request);
          }
          catch (e:Error) {
          // handle error here
          trace("Error");
          }
          }
          • 2. Re: simple button link
            sararas Level 1
            It didn't work.... I'm attaching a link to a screenshot of what I've done. And I'm such a novice, I don't even know if the word "try" was a part of the code, or if you were suggesting I try the following code. :|

            screenshot

            I'll buy a book, for sure. Any suggestions? I don' mind learning to code, I feel SO helpless right now, like the technology I once knew and loved is leaving me behind....
            • 3. Re: simple button link
              hciguy Level 1
              Okay. As for the book, I bought the O'Reilly AS 3.0 Cookbook which is pretty good. There is a new O'Reilly book by Colin Moock coming out June 15th by O'Reilly: Essential AS 3.0. I have ordered the latter. I'd recommend them both if you can handle books that aren't dumbed down too much....

              Yes, try was supposed to be there :)

              Two questions:

              1. Did you choose AS 3.0 document for this document when you made it?

              2. Your publish settings (in Flash tab) set to AS 3.0?

              I believe it is compiling it as AS 2.0 or something rather than 3.0, maybe? Because that code I gave you works just fine for me....
              • 4. Re: simple button link
                sararas Level 1
                *gasp* It works.

                I did choose AS3 because I'm using a FLV to progressively download a video, I believe an AS3 document is required for that?

                As for the publish settings....it was set to Flash 6 & Actionscript 1.0. I changed those options and it works. Fantastic.

                YAY! Thanks so much for your help, and for the book references!
                • 5. Re: simple button link
                  hciguy Level 1
                  You're welcome.
                  • 6. Re: simple button link
                    TnaE
                    What can I add to this script to make it open the link in the same window?
                    • 7. Re: simple button link
                      sararas Level 1
                      My guess would be to add

                      ,"_blank"


                      to this ilne:

                      try {
                      navigateToURL(request,"_blank");
                      }