17 Replies Latest reply on Nov 6, 2009 1:04 PM by Robin Davies Designer

    Actionscript 2 Troubles

    Robin Davies Designer Level 1

      Hi there,

       

      If anyone has some advice, it would be greatly appreciated. My client bought a flash file that turned out to be a bit of a surprise and has lead to hours of fruitless testing to get the file to work.

       

      The file she purchased is here.

      http://flashden.net/item/animated-cubes-mouse-illumination-as2/44429

      I managed to tweak the file to do what the client had asked for, but upon trying to use the file and make it link from Scene 1 to Scene 2, I have had nothing but errors.

      The code is below. Is it possible to add a link to this? The cursor has a roll-over feature that is at odds with the button behavior that I am trying to add.

      Any advice would be greatly appreciated. Thanks everyone.

       

      //hide InfoText from Animation

      InfoText._visible = false;

       

      //set cube width and height

      CubeWidth = 14;

      CubeHeight = 14;

       

      //set stage width and height

      StageWidth = 600;

      StageHeight = 343;

       

      //create cubes to fill screen verticaly and horisontaly

      for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){

          for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){

              t = attachMovie("CubeAnimation", "Cube" + i, this.getNextHighestDepth());

              t._x = (CubeWidth + 1) * i;

              t._y = (CubeHeight + 1) * j;

              t._width = CubeWidth;

              t._height = CubeHeight;

              t.onRollOver = OverCube;

              t.onRollOut = OutCube;

              t.MinimumAlpha = t._alpha = 30 + Math.random()*20;

              t.GoingBrighter = Math.round(Math.random()*1);

              t.onEnterFrame = CubeEnterFrame;

              t.useHandCursor = false;

          }

      }

       

      //iluminates cube when mouse over it

      function  OverCube() {this.gotoAndPlay(2);}

       

      //deluminates cube when mouse over it

      function OutCube() {this.gotoAndPlay(7);}

       

      //illuminate and deluminate cubes on every frame

      function CubeEnterFrame() {

          if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}

          if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}

          if (this._alpha <= 30){this.GoingBrighter = 1;}

          if (this._alpha >= 50){this.GoingBrighter = 0;}

      }

        • 1. Re: Actionscript 2 Troubles
          kglad Adobe Community Professional & MVP

          that's poor coding but you should be able to add onPress and onRelease handlers to that:

           


           

          //hide InfoText from Animation

          InfoText._visible = false;

           

          //set cube width and height

          CubeWidth = 14;

          CubeHeight = 14;

           

          //set stage width and height

          StageWidth = 600;

          StageHeight = 343;

           

          //create cubes to fill screen verticaly and horisontaly

          for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){

              for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){

                  t = attachMovie("CubeAnimation", "Cube" + i, this.getNextHighestDepth());

          t.ivar = i;

          t.jvar = j;

          t.onPress=function(){

          //do whatever based on this.ivar and this.jvar

          }

          //likewise for onRelease

           

                  t._x = (CubeWidth + 1) * i;

                  t._y = (CubeHeight + 1) * j;

                  t._width = CubeWidth;

                  t._height = CubeHeight;

                  t.onRollOver = OverCube;

                  t.onRollOut = OutCube;

                  t.MinimumAlpha = t._alpha = 30 + Math.random()*20;

                  t.GoingBrighter = Math.round(Math.random()*1);

                  t.onEnterFrame = CubeEnterFrame;

                  t.useHandCursor = false;

              }

          }

           

          //iluminates cube when mouse over it

          function  OverCube() {this.gotoAndPlay(2);}

           

          //deluminates cube when mouse over it

          function OutCube() {this.gotoAndPlay(7);}

           

          //illuminate and deluminate cubes on every frame

          function CubeEnterFrame() {

              if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}

              if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}

              if (this._alpha <= 30){this.GoingBrighter = 1;}

              if (this._alpha >= 50){this.GoingBrighter = 0;}

          }

          1 person found this helpful
          • 2. Re: Actionscript 2 Troubles
            Robin Davies Designer Level 1

            Wow. Thanks so much. I will try that.

            • 3. Re: Actionscript 2 Troubles
              Robin Davies Designer Level 1

              Thanks so much for the code tweaking. The errors have been reduced to a syntax error on the actionscript layer (it is actionscript 2). I have checked the code a few times as best as I can and I don't seem to be able to figure it out despite trying a number of times.

               

              Should I be defining more than I am with the t.ivar = 1 code?

              Thank you and sorry for asking what is more than likely a stupid question.

               

               

               

              //hide InfoText from Animation

              InfoText._visible = false;

               

              //set cube width and height

              CubeWidth = 14;

              CubeHeight = 14;

               

              //set stage width and height

              StageWidth = 600;

              StageHeight = 343;

               

              //create cubes to fill screen verticaly and horisontaly

              for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){

                  for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){

                      t = attachMovie("CubeAnimation", "Cube" + i, this.getNextHighestDepth());

              t.ivar = i;

              t.jvar = j;

              t.onPress=function(){

              gotoAndPlay("scene2",1);

              }

              t.onRelease=function(){

              gotoAndPlay("scene2",1);

              }

               

                      t._x = (CubeWidth + 1) * i;

                      t._y = (CubeHeight + 1) * j;

                      t._width = CubeWidth;

                      t._height = CubeHeight;

                      t.onRollOver = OverCube;

                      t.onRollOut = OutCube;

                      t.MinimumAlpha = t._alpha = 30 + Math.random()*20;

                      t.GoingBrighter = Math.round(Math.random()*1);

                      t.onEnterFrame = CubeEnterFrame;

                      t.useHandCursor = false;

                  }

              }

               

              //iluminates cube when mouse over it

              function  OverCube() {this.gotoAndPlay(2);}

               

              //deluminates cube when mouse over it

              function OutCube() {this.gotoAndPlay(7);}

               

              //illuminate and deluminate cubes on every frame

              function CubeEnterFrame() {

                  if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}

                  if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}

                  if (this._alpha <= 30){this.GoingBrighter = 1;}

                  if (this._alpha >= 50){this.GoingBrighter = 0;}

              }

              • 4. Re: Actionscript 2 Troubles
                kglad Adobe Community Professional & MVP

                1.  if you have a syntax error the compiler should be indicating which line has the error.

                 

                2.  don't use the goto funtions and don't use scenes for navigation.  use the goto methods and use frame labels.

                 

                3.  surely you don't want to execute the same code no matter which t is pressed and surely you don't want to execute the same code on press and on release.

                1 person found this helpful
                • 5. Re: Actionscript 2 Troubles
                  Robin Davies Designer Level 1

                  Than you as always for the advice. I will do a little more research on goto methods and using frame labels, and will modify the other code. Can I get away with just putting a function onRelease or do I need the onPress as well?

                   

                  The error is a little more puzzling. It says symbol=(the movie clip with actions in timeline); layer:syntax error. This file is the only one on the layer. Again, this file was supplied so I am doing my best to work with it.

                   

                  Once again, thank you so much.

                  • 6. Re: Actionscript 2 Troubles
                    kglad Adobe Community Professional & MVP

                    the goto methods would be:

                     

                    _root.gotoAndPlay("frame1_scene2");  // be sure to label that frame.

                     

                     

                    can you copy and paste the exact error message?

                    • 7. Re: Actionscript 2 Troubles
                      Robin Davies Designer Level 1

                      It simply says:

                      Symbol=CubesBackground, layer: syntax error

                       

                      CubesBackground is actually the movie clip file with the actions embedded within it on the timeline.

                      • 8. Re: Actionscript 2 Troubles
                        kglad Adobe Community Professional & MVP

                        there's no syntax error in the code posted in your last message.

                        • 9. Re: Actionscript 2 Troubles
                          Robin Davies Designer Level 1

                          I see now... there is actually a period at the end of the line that I 

                          missed:

                          Symbol=CubesBackground, layer: syntax error.

                           

                          is this period the cause of my problems?

                           

                          I have changed the structure of my FLA file. Instead of 2 scenes I now 

                          have 1 scene with the function based on your advice below:

                           

                          root.gotoAndPlay("frame1scene2");  // be sure to label that frame.

                           

                          I converted scene 2 into a /movie clip and brought it into the 

                          timeline of scene one.

                           

                          Because of this syntax error, the animation is playing start to finish.

                          Is it the period (.) causing the problems?

                           

                          Thank you again for all of your help.

                           

                           

                           

                           

                           

                           

                          //hide InfoText from Animation

                          InfoText_visible = false;

                           

                          //set cube width and height

                          CubeWidth = 14;

                          CubeHeight = 14;

                           

                          //set stage width and height

                          StageWidth = 600;

                          StageHeight = 343;

                           

                          //create cubes to fill screen verticaly and horisontaly

                          for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){

                              for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){

                                  t = attachMovie("CubeAnimation", "Cube" + i, 

                          this.getNextHighestDepth());

                          t.ivar = i;

                          t.jvar = j;

                           

                          t.onPress=function(){

                          _root.gotoAndPlay("animatedClip")

                          }

                          //likewise for onRelease

                           

                                  t._x = (CubeWidth + 1) * i;

                                  t._y = (CubeHeight + 1) * j;

                                  t._width = CubeWidth;

                                  t._height = CubeHeight;

                                  t.onRollOver = OverCube;

                                  t.onRollOut = OutCube;

                                  t.MinimumAlpha = t._alpha = 30 + Math.random()20;

                                  t.GoingBrighter = Math.round(Math.random()1);

                                  t.onEnterFrame = CubeEnterFrame;

                                  t.useHandCursor = false;

                              }

                          }

                           

                          //iluminates cube when mouse over it

                          function  OverCube() {this.gotoAndPlay(2);}

                           

                          //deluminates cube when mouse over it

                          function OutCube() {this.gotoAndPlay(7);}

                           

                          //illuminate and deluminate cubes on every frame

                          function CubeEnterFrame() {

                              if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}

                              if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}

                              if (this._alpha <= 30){this.GoingBrighter = 1;}

                              if (this._alpha >= 50){this.GoingBrighter = 0;}

                          }

                          • 10. Re: Actionscript 2 Troubles
                            kglad Adobe Community Professional & MVP

                            i don't see any errors in that last message involving a period.  there are two Math.random() lines that have errors.

                             

                            t.MinimumAlpha = t._alpha = 30 + Math.random()20;

                             

                            looks like it should be

                             

                            t.MinimumAlpha = t._alpha = 30 + Math.random()*20;

                             

                            and i don't know what this line should be but, it's wrong:

                             

                            t.GoingBrighter = Math.round(Math.random()1);

                            • 11. Re: Actionscript 2 Troubles
                              Robin Davies Designer Level 1

                              Once again, I can't thank you enough for your advice. I can't tell you 

                              how much of my time I have had to spend on this.

                              • 12. Re: Actionscript 2 Troubles
                                kglad Adobe Community Professional & MVP

                                you're welcome.

                                 

                                if you're still able, please mark this thread as answered.

                                • 13. Re: Actionscript 2 Troubles
                                  Robin Davies Designer Level 1

                                  I will do so but as I am still trying to solve this issue with this 

                                  script. I am still getting an syntax error so the file is not actually 

                                  playing on press, it is running straight through the entire timeline. 

                                  I am trying to work this out here but it is incredibly frustrating at 

                                  this point. I am used to working with symbols on the stage and 

                                  timeline instead of a page of script which probably isn't helping 

                                  things any.

                                   

                                  Once again, thanks so much for the help and I will be sure to mark the 

                                  thread once I finish.

                                  • 14. Re: Actionscript 2 Troubles
                                    kglad Adobe Community Professional & MVP

                                    what error message?  if you're seeing the same one you previously posted, it's because of something elsewhere.

                                    • 15. Re: Actionscript 2 Troubles
                                      Robin Davies Designer Level 1

                                      Yes, still this error message.

                                      Symbol=CubesBackground, layer: syntax error.

                                       

                                      CubesBackground is a movie clip that contains the Actionscript on the 

                                      timeline.

                                      (this is an actionscript2 file)

                                       

                                      I was looking in the script for the problem. Should i elsewhere than 

                                      the Symbol that was indicated?

                                      • 16. Re: Actionscript 2 Troubles
                                        kglad Adobe Community Professional & MVP

                                        comment out the code you've been showing in this forum and test your fla.  does the error message disappear?

                                        • 17. Re: Actionscript 2 Troubles
                                          Robin Davies Designer Level 1

                                          I actually have tried tweaking the file a little, and imported my 

                                          frames inside the movie clip, and made an action on clip that advances 

                                          the frame as desired. It works without error with the exception that 

                                          the scripted cubes remain on the stage. You can view here:

                                           

                                          http://www.robindavies.ca/animatedcubes_A_orangeClipNu.html

                                           

                                          Is it possible to make a function that would make my symbols ( "Cube" 

                                          graphic and "CubeAnimation" movie clip ) go to an alpha of 0% on 

                                          release?

                                          The cubes are already scripted to change in appearance so it would 

                                          seem this is possible.

                                           

                                          I know that this solution to the problem is more than likely less than 

                                          ideal from a best practices standpoint, but at least it is a solution.

                                          I have tried to make additional functions below to the code without 

                                          success.

                                          Thanks for any helpful ideas.

                                           

                                           

                                           

                                          //hide InfoText from Animation

                                          InfoText._visible = false;

                                           

                                          //set cube width and height

                                          CubeWidth = 14;

                                          CubeHeight = 14;

                                           

                                          //set stage width and height

                                          StageWidth = 600;

                                          StageHeight = 343;

                                           

                                          //create cubes to fill screen verticaly and horisontaly

                                          for (i = 0; i < (StageWidth / (CubeWidth + 1)); i++){

                                               for (j = 0; j < (StageHeight / (CubeHeight + 1)); j++){

                                                    t = attachMovie("CubeAnimation", "Cube" + i, 

                                          this.getNextHighestDepth());

                                                    t._x = (CubeWidth + 1) * i;

                                                    t._y = (CubeHeight + 1) * j;

                                                    t._width = CubeWidth;

                                                    t._height = CubeHeight;

                                                    t.onRollOver = OverCube;

                                                    t.onRollOut = OutCube;

                                                    t.onRelease = ClickCube;

                                                    t.MinimumAlpha = t._alpha = 30 + Math.random()*20;

                                                    t.GoingBrighter = Math.round(Math.random()*1);

                                                    t.onEnterFrame = CubeEnterFrame;

                                                    t.useHandCursor = false;

                                               }

                                          }

                                           

                                          //iluminates cube when mouse over it

                                          function  OverCube() {this.gotoAndPlay(2);}

                                           

                                          //deluminates cube when mouse over it

                                          function OutCube() {this.gotoAndPlay(7);}

                                           

                                          function ClickCube() {gotoAndPlay("Frame2");}

                                                

                                          //illuminate and deluminate cubes on every frame

                                          function CubeEnterFrame() {

                                               if (this.GoingBrighter == 1){this._alpha = this._alpha + 0.5;}

                                               if (this.GoingBrighter == 0){this._alpha = this._alpha - 0.5;}

                                               if (this._alpha <= 30){this.GoingBrighter = 1;}

                                               if (this._alpha >= 50){this.GoingBrighter = 0;}

                                          }