6 Replies Latest reply on May 2, 2011 9:06 AM by bnimon

    (newb question) problems creating a link and/or a function in AS3

    bnimon Level 1

      So I've gone through a few different websites looking for a way to make a symbol a link, and I keep running into the same problem. I am using action script 3.

       

      For example, I got this code from this page: http://scriptplayground.com/tutorials/as/getURL-in-Actionscript-3/

      logolink.addEventListener(MouseEvent.CLICK, callLink);  // changed movieClipName to logolink
      function callLink:void {   var url:String = "index.php"; // changed from var url:String = "http://site";
        var request:URLRequest = new URLRequest(url);   try {     navigateToURL(request, '_blank');   } catch (e:Error) {     trace("Error occurred!");   } }

       

      It makes the symbol (logolink) a link (changed the mouse cursor to a pointer), but it kills my animations and errors out saying (all on line 4...the function callLink line): "expecting leftparen before colon", "expecting identifier before leftbrace", and "expecting rightparen before leftbrace".

       

      I am very new to AS, and I tried a few things like adding an unused parameter, and a couple other things (trying to satisfy the above errors), but then I get "call to possibly undefined method addEventListener through a reference with static type Class"

       

      What am I doing wrong? I am a very experienced programmer (just new to AS). I'm sure it's something simple (it always is). I guess it's time to pick up a book about this stuff. I'm surpised at how little explaination there is available on the web compared to a lot of other languages.

        • 1. Re: (newb question) problems creating a link and/or a function in AS3
          Rothrock Level 5

          The handler function for an event needs to recieve an event:

           

          function callLink(e:MouseEvent):void{}

           

          You don't say which version of Flash you are using. The best documentation however is in Flash. Just put the cursor on addEventListener and press F1.

           

          Usually I scroll down to the bottom of the help entry and there will be examples. It does differ a bit between AS2/3 and CS4/5.

          1 person found this helpful
          • 2. Re: (newb question) problems creating a link and/or a function in AS3
            bnimon Level 1

            i am pretty sure that is one of the things i tried (from an example on another website). it gave me the "possibly undefined" error. But i wont get a chance until monday to give it a try. By the way, how can anything in programming be "possibly undefined" either it is or its not. programming doesnt work too well with "possiblies" thrown into the mix. Sorry for the misstypings....this forum entry system is not very Android compatible. i cant go back and fix things.

            • 3. Re: (newb question) problems creating a link and/or a function in AS3
              Ned Murphy Adobe Community Professional & MVP

              It's possible that what you are calling logolink is actually the class name of the object instead of the instance name.  If it is a manually placed object, the instance name is what you assign to an object via the Properties panel after it has been placed on the stage.

               

              logolink.addEventListener(MouseEvent.CLICK, callLink);  // changed movieClipName

               

              Granted, indicating "possibly undefined" is a bit erroneous, but you'd have to have come from the world of AS1/2 to appreciate that you are at least being told something is wrong.  And if you were to go into your Flash Publish Settings and select the option to Permit Debugging, for that error it would add the line number for the code with the problem.  AS1/2 would more likely just not work and leave you to wonder why.

               

              Maybe saying "possibly undefined" is another way of saying ... "you might be trying to use a proper bit of code, but it's not proper here", rather than just outright saying "you messed up, fool, figure it out"

               

              I'd like to see further improvements in the error messaging.  Too often the compiler knows exactly what tripped it up, but gives a generic message that forces you to search for whatever the heck it's talking about.  But hey, as I said, compared to AS1/2, what it does now makes life easier.

              • 4. Re: (newb question) problems creating a link and/or a function in AS3
                bnimon Level 1

                That's probably what it is. I set a class in the library, and not an instance in the stage (do I have that right?).

                 

                I forgot to mention (it was asked earlier). I am using CS5 and publishing Flash Player 10 (not sure which he cared about).

                 

                So, from what I gather, AS3 is much more complicated (for example a link for a symbol in AS2 took only a line or two of code, and now it takes 9), but it has better debugging and is more powerful. Seems odd. In other languages that I've used, as they mature over time they get better debugging and more power, but they get simpler as well (especially for really common tasks -- like adding a simple link :-P).

                • 5. Re: (newb question) problems creating a link and/or a function in AS3
                  Ned Murphy Adobe Community Professional & MVP

                  Just consider that AS3 is still an infant... the "mature over time" aspect has yet to happen...  With each new version of Flash they are still adding new things to the language, not refining what's already in it (unfortunately).

                  • 6. Re: (newb question) problems creating a link and/or a function in AS3
                    bnimon Level 1

                    Thanks for the help guys. It was the instance name instead of the class name that solved it. It also needed the "(e:MouseEvent)" so thanks to both of you.

                     

                    I still have a lot to learn, and this forum is extremely helpful!