4 Replies Latest reply on Aug 15, 2006 9:35 AM by Newsgroup_User

    Running a function on a different movieclip

    Josh_Pratt
      Here's how I've got my stuff laid out:

      main_mc (movieclip)
      - maincode(movieclip)
      - text1(movieclip)

      I've got a bunch of code on the maincode movieclip. On there I have a function called "enablebuttons", which enables buttons that are on that movieclip.

      On the text1 movieclip, I've got a button on which I would like to run the function "enablebuttons" on the maincode movieclip.

      Is this possible to do? Or will I have to make another function on the text1 movieclip and specifically enable the buttons on the maincode movieclip?
        • 1. Re: Running a function on a different movieclip
          .:}x-=V!P=-x{:. Level 3
          well depeding on if you have the button code in text1 on the timeline and those names are their instance name:
          _parent.maincode.enablebuttons();
          or if the button code is on the button
          _parent._parent.maincode.enablebuttons();
          • 2. Re: Running a function on a different movieclip
            Level 7
            Josh,

            > Is this possible to do? Or will I have to make another
            > function on the text1 movieclip and specifically enable
            > the buttons on the maincode movieclip?

            All your movie clips are simply objects, like any other object in
            ActionScript (an array, a sound, a text field, a date, etc.). As long as
            your movie clips have instance names, you can simply call them by name --
            from anywhere in the SWF -- and tell them what to do.

            Ideally, you should put most of your code into a dedicated layer of the
            main timeline, simply because that's the easiest place to find it.

            The only thing you really need to keep in mind is that ActionScript
            can't be run until the playhead has entered the frame in which the code
            resides. So if you had a function in a frame of clipB, which was inside of
            clipA on the main timeline, you could simply put ...

            clipA.clipB.functionName() on the main timeline

            ... unless that function was on, say, frame 15 of clipB and clipB was still
            on a frame less than 15.

            Make sense?


            David Stiller
            Adobe Community Expert
            Dev blog, http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: Running a function on a different movieclip
              Josh_Pratt Level 1
              That isn't working... I can't even seem to just try and enable a single button with code from the button.

              on the text1 timeline, I've got the button code:

              stop();

              back.onRelease = function() {
              _parent.maincode.enablebuttons();
              play();
              }

              This still doesn't enable the buttons, which it seems like it should.. I've also tried to substitute the '_parent.maincode.enablebuttons();' with all sorts of variations of:

              _parent.maincode.bio0.enabled = true; (bio0 is an instance name of a button)

              I have no clue why I can't get even a single button to reenable...
              • 4. Re: Running a function on a different movieclip
                Level 7
                Josh,

                > That isn't working... I can't even seem to just try
                > and enable a single button with code from the
                > button.

                It sounds like you're just groping in the dark, is all.

                > back.onRelease = function() {
                > _parent.maincode.enablebuttons();
                > play();
                > }
                > This still doesn't enable the buttons, which it seems
                > like it should..

                That depends entirely on the structure of your objects. Let's say back
                is a button. If so, it may be a button symbol. If so, it's an instance of
                the Button class. Look up the Button class -- does it have an onRelease
                event? Yes. :) Cool. So far, so good. Now we're in a function literal
                assigned to that event. The _parent property is invoked, so now we're
                looking at the timeline in which this button resides. If this parent
                timeline contains an object (a movie clip, say) with the instance name
                maincode, then that object will be checked for a function named
                enablebuttons().

                Is that your set up? Is that function inside maincode properly pathed
                back to this button? These paths are essentially the same as foldersn your
                hard drive. Thing of the hierarchy in terms of that analogy.


                David Stiller
                Adobe Community Expert
                Dev blog, http://www.quip.net/blog/
                "Luck is the residue of good design."