6 Replies Latest reply on Apr 9, 2007 11:28 AM by crazyjoemilan

    function outside object

    MaesHanne
      Hi,

      How can I use a function that is declared outside the object or layer?
      I that way I can group all my functions into one layer.

      Thanks
        • 1. Re: function outside object
          crazyjoemilan Level 2
          don't build your animations on the main timeline, build objects on the main timeline with their own animations. That way, all your code is on frame 1.

          Say I build a button with the instance name "myButton" On the main timeline, to control its actions, I would write...

          myButton.onRelease = function() {
          //whatever you want
          }

          if "myButton" was in a movie clip called "myMovie" I would just add the myMovie to it...

          myMovie.myButton.onRelease = function() {
          //whatever
          }

          there are some things that break this rule, like the stop(); function. its much easier to put this on the individual movie timelines than to run loops to see which frame your at to decide if you should stop. But formatting your files this way will give your code a nice organized feel, and be easier to edit later.
          • 2. Re: function outside object
            MaesHanne Level 1
            I know, I do it to.
            That whas not my question.
            My question was:
            I am making a little game (with only 1 frame on the main timeline), but I wanne split the actionscript into different layer
            for example: one layer with al the movement functions, another with al the attacking functions and a third with the interaction with the player (the if (Key.isDown(Key.UP) like thing).
            How can I (int the interaction layer) refer to a movement function in the movement layer?

            Thanks, and sorry for the bad formulation
            • 3. Re: function outside object
              crazyjoemilan Level 2
              layers aren't referenced. movieclips and buttons are, but not layers. if you have code on the same frame, it doesn't matter which layer its on - except for procedural matters, but you should be watching those if it were on one fram anyway, so no biggie.
              • 4. Re: function outside object
                MaesHanne Level 1
                I did not know that
                Thanks for the help it was very usefull
                • 5. Re: function outside object
                  crazyjoemilan Level 2
                  glad I could help.
                  • 6. function outside object
                    crazyjoemilan Level 2
                    glad I could help. -- then doublepost.