7 Replies Latest reply on Nov 23, 2012 8:55 AM by kglad

    Code Explanation

    MrDave19

      hello adobe,

       

      for a long time i was working with flash, but unfortunately i dont know coding and to learn actionscript 2.0 is very hard for me cause my english isnt that good, so i want somebody to please explain me this code, im trying to make a pro website with flash, and i found one, but there are some crazy codes that i dont understand, so if someone can explain me this code i will be very happy. what means .this? _parent? "item" and stuff, please explain.

       

       

      onClipEvent (load)

      {

          num = 1;

          this.title2.gotoAndStop(num);

      }

      on (rollOver)

      {

          if (_root.menuPosition != num)

          {

              this.gotoAndPlay("s1");

          } // end if

      }

      on (releaseOutside, rollOut)

      {

          if (_root.menuPosition != num)

          {

              this.gotoAndPlay("s2");

          } // end if

      }

      on (release)

      {

          if (_root.menuPosition != num)

          {

              this._parent.song_sound.start();

              _root.menuPosition_prev = _root.menuPosition;

              _parent["item" + _root.menuPosition].gotoAndPlay("s2");

              _root.menuPosition = num;

              _root.bg.colorChanger("s1");

              if (_root.cont._currentframe == 1)

              {

                  _root.cont.play();

              }

              else

              {

                  _root.cont.content.gotoAndStop("s" + num);

              } // end if

          } // end else if

      }

        • 1. Re: Code Explanation
          prodigalmaster Level 2

          'this.' is the object the code is refering to. Usually what executes the code, e.g. if the code is on a movieclip, this. is the name of the movieclip meaning for example this._alpha = 5;0 makes the movieclip 50% see-through/transparent. When it is not focusing on a movieclip or object, it will be _root. which is the highest level. All movieclips are on the _root. --- and so here, _root is the stage and everything on it. MC1 is a movieclip within the stage and MC1B is a movieclip WITHIN MC1, this code changes the MC1B rotation within the MC1 movieclip within _root but nothing else: _root.MC1.MC1B._rotation = 90;

           

          _parent accesses the 'above' movieclip, for example _root.MC1.MC1B._parent would be going from root(the stage) to MC1 (the movieclip) to MC1B (the movieclip within MC1) back to MC1 (because MC1 is a 'parent' of MC1B, while MC1B is a 'child' of MC1).

           

          "item" is not part of the language but is defined by the programmer. It is the name of a movieclip. So if you change the name of a movieclip identifier in the properties of it to MC1 then you must access it within the code by MC1 (if MC1 is within another movieclip, you must type that movieclip name then a dot (.) then MC1 then another . and then what you want to change for that movieclip).

           

          Look up the Actionscript documentation, there are reference books for particular things such as this. or _parent and also other books to explain and help you understand them.

           

          Look up tutorials for your specific job but don't expect people on a forum to write the code for you. Thanks.

          • 2. Re: Code Explanation
            MrDave19 Level 1

            thank you very much but unfortunately i dont understand 90% , but ill try to use translate.google.com ..

             

            i was looking for that tutorials but.......

            and what is this MC1?

            • 3. Re: Code Explanation
              prodigalmaster Level 2

              MC1 is just an example of a name of the movieclip that you or I create.

               

              To change the properties of the movieclip it must have a name, it can be almost anything you want like MC_thisIsAMovieClip or mcPlayer or mcItem

              • 4. Re: Code Explanation
                MrDave19 Level 1

                if still someone can explain me this code, will be great, please.

                • 5. Re: Code Explanation
                  kglad Adobe Community Professional & MVP

                  :

                   

                   

                  // there are 5 snippets of code here.  onClipEvent, onRollOver, onReleaseOutside, onRollOut and onRelease
                  // this first snippet executes when the movieclip to which the code is attached, loads (ie, starts).

                  onClipEvent (load)

                  {

                  // a variable (num) is initialized to 1

                      num = 1;

                  // this object must have a child movieclip named title2 and that movieclip is directed to frame 1 (which is superfluous because all movieclips start on frame 1).

                      this.title2.gotoAndStop(num);

                  }

                  // this 2nd snippet executes when the mouse rolls over this movieclip

                  on (rollOver)

                  {

                  // the _root timeline must have a variable named menuPosition.  the next line of code is checking is menuPosition is not equal to num

                      if (_root.menuPosition != num)

                      {

                  // if they are not equal, the rolled over movieclip (this), goes to and plays the frame labeled "s1" (ie, the "on" animation.)

                          this.gotoAndPlay("s1");

                      } // end if

                  }

                  // the 3rd and 4th snippets

                  on (releaseOutside, rollOut)

                  {

                  // same conditional as above

                      if (_root.menuPosition != num)

                      {

                  // go to and play "s2" (ie, the "off" animation.)

                          this.gotoAndPlay("s2");

                      } // end if

                  }

                  // last snippet executes when movieclip is clicked.

                  on (release)

                  {

                  // same conditional

                      if (_root.menuPosition != num)

                      {

                  // there's a sound instance (song_sound) on the parent of the clicked movieclip that starts playing

                          this._parent.song_sound.start();

                  //menuPosition_prev on _root is assigned the menuPosition on _root

                          _root.menuPosition_prev = _root.menuPosition;

                  //the parent of the clicked movieclip has a movieclip named "item"+_root.menuPosition which is directed to "s2".  (ie, the previously clicked button changes display from the currently clicked movieclip to being "unclicked".)

                          _parent["item" + _root.menuPosition].gotoAndPlay("s2");

                  // update menuPosition on _root

                          _root.menuPosition = num;

                  //movieclip bg on _root has a function colorChanger that accepts a string and is passed "s1".

                          _root.bg.colorChanger("s1");

                  //movieclip cont on _root is checked for its current frame and if == 1, the conditional is true

                          if (_root.cont._currentframe == 1)

                          {

                  //cont plays

                              _root.cont.play();

                          }

                          else

                          {

                  // else direct the child movieclip content of cont to goto and play "s"+num

                              _root.cont.content.gotoAndStop("s" + num);

                          } // end if

                      } // end else if

                  }

                   

                  this same code is probably added to each movieclip button with the only change being num (in the load snippet) is different for each button.

                   

                  this is classic coding from online for-sale templates and displays inferior coding skill by the author.

                   

                  i strongly suggest you NOT use this to learn actionscript.   if you made the mistake of purchasing this and now need to understand it in order to edit it to do what you want, you have my sympathies.

                   

                  in the future, never buy a template.  i've never seen one that's worth purchasing unless you are sure you will not need to edit it or the seller will edit it for you at a reasonable cost.

                  • 6. Re: Code Explanation
                    MrDave19 Level 1

                    kglad thank you very much for reply, i appriciated!

                    • 7. Re: Code Explanation
                      kglad Adobe Community Professional & MVP

                      you're welcome.