5 Replies Latest reply on Apr 25, 2013 4:15 PM by kglad

    Actionscript 3.0 question

    jarnot9 Level 1

      Hi, all

       

      I absolutely do not know Actionscript 3.0 syntax and need to fix this FAST (of course).

       

      I named my instance, and used this code snippet. It works:

       

      thirtyYearFixed.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);

       

      function fl_ClickToGoToWebPage_3(event:MouseEvent):void

      {

          navigateToURL(new URLRequest("http://www.adobe.com"), "_blank");

      }

       

       

       

      this is the previous code, actionscript 2.0 which is pulling dynamic data from the xml:

       

      on(release) {

          getURL(clickTAG + "?*", "_blank");

       

      THE QUESTION:

       

      how do I get it to link to the clickTAG, dynamic data (instead of http://www.adobe.com)

       

      tia,

       

      jarnot

        • 1. Re: Actionscript 3.0 question
          kglad Adobe Community Professional & MVP

          where (or how) is clickTAG in the actionscript 2.0 version.

           

          once that's converted to as3 (or, if it's already done), use:

           

           

          thirtyYearFixed.addEventListener(MouseEvent.CLICK, fl_ClickToGoToWebPage_3);

           

          function fl_ClickToGoToWebPage_3(event:MouseEvent):void

          {

              navigateToURL(new URLRequest(clickTAG + "?*", "_blank"));

          }

          • 2. Re: Actionscript 3.0 question
            jarnot9 Level 1

            Thanks for your help.

             

            I know my problem is when I am using multiple buttons because it works if I only use the first button (thirtyYearFixed.) I just don't know what the correct syntax is supposed to look like:

             

            thirtyYearFixed.addEventListener (MouseEvent.CLICK, buttonSymbol_click);

            function buttonSymbol_click (evt:MouseEvent):void {

            trace(loaderInfo);

            var clickTAG:String = loaderInfo.parameters.clickTAG;

                 // Check for malicious code injections, only use URLs if they begin with http: or https:

                 if ((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                          {

                          var req:URLRequest = new URLRequest(clickTAG);

                          navigateToURL(req, "_blank");

                          }

            }

            fifteenYearFixed.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

            //function buttonSymbol_click(event:MouseEvent):void

            {

                var clickTAG:String = loaderInfo.parameters.clickTAG;

                if((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                {

                    var req:URLRequest = new URLRequest(clickTAG);

                    navigateToURL(req, "_blank");

                }

            }

            fiveOneArm.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

            //function buttonSymbol_click(event:MouseEvent):void

            {

                var clickTAG:String = loaderInfo.parameters.clickTAG;

                if((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                {

                    var req:URLRequest = new URLRequest(clickTAG);

                    navigateToURL(req, "_blank");

                }

            }

            seeMoreRates.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

            //function buttonSymbol_click(event:MouseEvent):void

            {

                var clickTAG:String = loaderInfo.parameters.clickTAG;

                if((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                {

                    var req:URLRequest = new URLRequest(clickTAG);

                    navigateToURL(req, "_blank");

                }

            }

            buttonMovie.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

            //function buttonSymbol_click(event:MouseEvent):void

            {

                var clickTAG:String = loaderInfo.parameters.clickTAG;

                if((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                {

                    var req:URLRequest = new URLRequest(clickTAG);

                    navigateToURL(req, "_blank");

                }

            }

            • 3. Re: Actionscript 3.0 question
              kglad Adobe Community Professional & MVP

              if each button is supposed to do the same thing, use:

               

               

               

               

               

              thirtyYearFixed.addEventListener (MouseEvent.CLICK, buttonSymbol_click);

              fifteenYearFixed.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

              fiveOneArm.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

              seeMoreRates.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

              buttonMovie.addEventListener(MouseEvent.CLICK, buttonSymbol_click);

               

              function buttonSymbol_click (evt:MouseEvent):void {

              trace(loaderInfo);

              var clickTAG:String = loaderInfo.parameters.clickTAG;

                   // Check for malicious code injections, only use URLs if they begin with http: or https:

                   if ((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                            {

                            var req:URLRequest = new URLRequest(clickTAG);

                            navigateToURL(req, "_blank");

                            }

              }


              • 4. Re: Actionscript 3.0 question
                jarnot9 Level 1

                Yup. Thanks! It works. This is what it looks like:

                 

                thirtyYearFixed.addEventListener (MouseEvent.CLICK, onClick);

                fifteenYearFixed.addEventListener (MouseEvent.CLICK, onClick);

                fiveOneArm.addEventListener (MouseEvent.CLICK, onClick);

                seeMoreRates.addEventListener (MouseEvent.CLICK, onClick);

                buttonMovie.addEventListener (MouseEvent.CLICK, onClick);

                AL.addEventListener (MouseEvent.CLICK, onClick);

                AK.addEventListener (MouseEvent.CLICK, onClick);

                AZ.addEventListener (MouseEvent.CLICK, onClick);

                AR.addEventListener (MouseEvent.CLICK, onClick);

                CA.addEventListener (MouseEvent.CLICK, onClick);

                CO.addEventListener (MouseEvent.CLICK, onClick);

                CT.addEventListener (MouseEvent.CLICK, onClick);

                DE.addEventListener (MouseEvent.CLICK, onClick);

                FL.addEventListener (MouseEvent.CLICK, onClick);

                GA.addEventListener (MouseEvent.CLICK, onClick);

                HI.addEventListener (MouseEvent.CLICK, onClick);

                ID.addEventListener (MouseEvent.CLICK, onClick);

                IL.addEventListener (MouseEvent.CLICK, onClick);

                IN.addEventListener (MouseEvent.CLICK, onClick);

                IA.addEventListener (MouseEvent.CLICK, onClick);

                KS.addEventListener (MouseEvent.CLICK, onClick);

                KY.addEventListener (MouseEvent.CLICK, onClick);

                LA.addEventListener (MouseEvent.CLICK, onClick);

                ME.addEventListener (MouseEvent.CLICK, onClick);

                MD.addEventListener (MouseEvent.CLICK, onClick);

                MA.addEventListener (MouseEvent.CLICK, onClick);

                MI.addEventListener (MouseEvent.CLICK, onClick);

                MN.addEventListener (MouseEvent.CLICK, onClick);

                MS.addEventListener (MouseEvent.CLICK, onClick);

                MO.addEventListener (MouseEvent.CLICK, onClick);

                MT.addEventListener (MouseEvent.CLICK, onClick);

                NE.addEventListener (MouseEvent.CLICK, onClick);

                NV.addEventListener (MouseEvent.CLICK, onClick);

                NH.addEventListener (MouseEvent.CLICK, onClick);

                NJ.addEventListener (MouseEvent.CLICK, onClick);

                NM.addEventListener (MouseEvent.CLICK, onClick);

                NY.addEventListener (MouseEvent.CLICK, onClick);

                NC.addEventListener (MouseEvent.CLICK, onClick);

                ND.addEventListener (MouseEvent.CLICK, onClick);

                OH.addEventListener (MouseEvent.CLICK, onClick);

                OK.addEventListener (MouseEvent.CLICK, onClick);

                OR.addEventListener (MouseEvent.CLICK, onClick);

                PA.addEventListener (MouseEvent.CLICK, onClick);

                RI.addEventListener (MouseEvent.CLICK, onClick);

                SC.addEventListener (MouseEvent.CLICK, onClick);

                SD.addEventListener (MouseEvent.CLICK, onClick);

                TN.addEventListener (MouseEvent.CLICK, onClick);

                TX.addEventListener (MouseEvent.CLICK, onClick);

                UT.addEventListener (MouseEvent.CLICK, onClick);

                VT.addEventListener (MouseEvent.CLICK, onClick);

                VA.addEventListener (MouseEvent.CLICK, onClick);

                WA.addEventListener (MouseEvent.CLICK, onClick);

                WV.addEventListener (MouseEvent.CLICK, onClick);

                WI.addEventListener (MouseEvent.CLICK, onClick);

                WY.addEventListener (MouseEvent.CLICK, onClick);

                function onClick (evt:MouseEvent):void {

                var clickTAG:String = loaderInfo.parameters.clickTAG;

                     // Check for malicious code injections, only use URLs if they begin with http: or https:

                     if ((clickTAG.substr(0, 5) == "http:") || (clickTAG.substr(0, 6) == "https:"))

                              { navigateToURL(new URLRequest(clickTAG + "?" + evt.currentTarget.name), "_blank");

                              }

                }

                • 5. Re: Actionscript 3.0 question
                  kglad Adobe Community Professional & MVP

                  you're welcome.

                   

                  p.s.  there are easier ways to code that (though i wouldn't change now if i were you):

                   

                  var stateA:Array = ["AL","AK","AZ","AR","CA","CO",...];

                  for(var i:int=0;i<stateA.length;i++){

                  stageA[i].addEventListener(MouseEvent.CLICK,onClick);

                  }