4 Replies Latest reply on Apr 14, 2007 12:39 PM by Greg Dove

    two onPress on the same clip

    Level 7
      a movieclip mc has onPress=f1 in its timeline;
      in the main line this clip is used as
      attachMovie("mc","mc",1)
      mc.onPress=f2

      From what I see in this case f2() is not called

      Is this how it is supposed to be?
      How do I make mc.onPress to work too?


        • 1. Re: two onPress on the same clip
          kglad Adobe Community Professional & MVP
          that looks like you have a movieclip mc and are attaching a movieclip with the same instance name of path. show your code.
          • 2. Re: two onPress on the same clip
            Level 7
            In the library I have a movieclip called "mc" created using Insert new
            Symbol -- Movie Clip and exported for AS as "mc".

            In this movieclip timeline
            onPress=function(){trace("from clip")}

            In the main timeline:
            attachMovie("mc","s",1)
            s.onPress=function(){trace("from main")}

            On clicking the clip this returns "from clip"

            if I comment out code in the movieclip, then it returns "from main"

            So it looks like the same logic as in overimposing clips - one screens the
            other


            "kglad" <webforumsuser@macromedia.com> wrote in message
            news:evqmpf$l96$1@forums.macromedia.com...
            > that looks like you have a movieclip mc and are attaching a movieclip with
            the same instance name of path. show your code.


            • 3. Re: two onPress on the same clip
              Greg Dove Level 4
              Try replacing your 2 onPress assignments with trace('from clip') and trace('from main')

              I suspect you will see that both run... but the order might give you a clue as to what is happening. The code for the assignment in your main clip is running before the code in your attached Movie.
              • 4. Re: two onPress on the same clip
                Greg Dove Level 4
                Oh I think I understand what you want to do .... no you can only assign onPress to one function. But you can 'append' functionality by referencing the current assigned function.

                So you want to keep what the default onPress behaviour in the library symbol but also add something else when you attach different instances.

                I think I've done that type of thing in the past with:

                s.onPress = function() {
                s.onPress(); //this would be what the default behaviour already was
                //new Code here

                }

                The problem here also could be the timing, because if the first assignment hasn't yet been made inside the attached clip (which seems to be your experience), you won't be able to do that. There would need to be a delay until the code inside the attached movie has run first. You could get around this by just having a regular function that represents the default behaviour inside the attached clip and assigning every newly attached clip with that as its onPress handler with or with some additional code for as required for different instances. Hope that makes sense