5 Replies Latest reply on Jul 17, 2006 2:32 PM by blemmo

    Just a very simple question

    angusyyl
      Just a very simple quesiton, please give me a hand~
      Here is my Flash ActionScript included in the first keyframe on the main Timeline, and it contains a button and a movie clip called "myButton_btn" and "myClip_mc" respectively.

      myButton_btn.onPress = function() {
      trace("Activation button is pressed");
      myTraceTest();
      };
      function myTraceTest() {
      trace("myTraceTest function is executed");
      myClip_mc.onMouseDown = function() {
      trace("I now have POWER!");
      };
      }


      The problem I encounted was that when I tested the movie, and I clicked on the myButton_btn at the first time, the output window only showed

      Activation button is pressed
      myTraceTest function is executed

      shouldn't it be

      Activation button is pressed
      myTraceTest function is executed
      I now have POWER!
      ?
      For each of the 2nd,3rd .. click on the myButton_btn, the output window then showed

      Activation button is pressed
      myTraceTest function is executed
      I now have POWER!
      ........It then worked properly!

        • 1. Re: Just a very simple question
          blemmo Level 1
          The function myTraceTest assigns the MC's onMouseDown event, it doesn't execute this event. So the output for the first button click is right, because the MC doesn't listen for mouseDowns at that moment. After that, the MC receives onMouseDown events, so when you click again on the button, the MC now gets the event and shows the output.

          greets,
          blemmo
          • 2. Re: Just a very simple question
            angusyyl Level 1
            quote:

            Originally posted by: blemmo
            The function myTraceTest assigns the MC's onMouseDown event, it doesn't execute this event. So the output for the first button click is right, because the MC doesn't listen for mouseDowns at that moment.


            ummm...I get what you mean...
            but I wonder... why the MC doesn't listen for mouseDowns at that moment as the function myTrace had assigned the onMouseDown event to the MC even for the 1st click...
            shouldn't all the actions within the function myTraceTest be executed, including myClip_mc.onMouseDown = function() {
            trace("I now have POWER!");
            };
            , even for the 1st click?

            hope you understand what I mean.....my English is not really good:)
            really thanks for your help:)

            • 3. Just a very simple question
              blemmo Level 1
              Well, you are listening for an event, so the event must actually take place to start the assigned actions. The first click executes your function, and the onMouseDown event gets assigned to the MC. That means, from that time on, it will listen for that event. It won't execute right away, because the event onMouseDown triggered by the 1st click happened before the assignment, so the MC didn't receive it. Only the next MouseDown will trigger it.
              You can change the onMouseDown to onMouseUp, then the assigned event will fire in the 1st click, because when you let the mouse go, the event you just assigned will actually take place, and the assignment of the listener was before that. You'll see that onMouseDown, the first 2 lines will show, and if you wait a bit, nothing more happens. Only when you let the mouse go it shows the "power" line.

              So it comes down to the fact that onMouseDown is executed before onPress. If you look at the output, you'll see that after the 1st click, the "power" line comes before the "activated" lines, so the onMouseDown event must trigger before the onPress. That's why the actions assigned in onPress can't react on the previous onMouseDown. Time does only flow in one direction...

              hth,
              blemmo
              • 4. Re: Just a very simple question
                angusyyl Level 1
                quote:

                Originally posted by: blemmo
                So it comes down to the fact that onMouseDown is executed before onPress. If you look at the output, you'll see that after the 1st click, the "power" line comes before the "activated" lines, so the onMouseDown event must trigger before the onPress.


                Wow!! I finally understand it!! :)
                But, another question arise..... how do you know the onMouseDown is executed before onPress? I found a similar case with using onMouseUp and onRelease, and the former is executed before the latter one....Ummm..is there any rule for this? I mean ...are all the events for MovieClips executed earlier than those for Buttons?

                Thank you again!!! :)
                • 5. Re: Just a very simple question
                  blemmo Level 1
                  Hm, can't answer this for sure. MCs also have an onRelease event, so it shouldn't be a button vs. MC thing. Maybe it is because a MouseDown or -Up is a more general thing, it happens when the mouse is used. OnRelease or onPress are bound to certain objects, so maybe they come later because they just affect specific instances. But that's just a guess... When in doubt, just try it out by letting each event trace a message, and see in which order they appear.

                  greets,
                  blemmo