3 Replies Latest reply on Feb 22, 2007 1:22 AM by Peter Lorent

    Unexplained Looping with tween

    Rich Rainbolt
      First let me say I am new to flash but I have done my homework, doing the tutorials and having purchased and read, (a good deal of),"Foundation ActionScript for Flash 8." OK so I think I've overlooked something basic in Flash and now that I'm knee deep in actionScript it is showing up.

      I want to do a simple effect of cross fading text over text and finally freezing on the final text.
      I have each piece of text on a different layer in a folder called "content" the top most folder is called actions where (duh), I have my actionScript. I have each text defined as a movie clip with _mc at the end of the variable name.

      In the beginning frame (frame 3 after I used the first two for loading status) I have a key frame for all pieces of text graphic etc.

      I have:

      // set flash up to locate tweening components
      import mx.transitions.Tween;
      import mx.transitions.easing.*;

      then I have a lot of initialization etc.
      //initialize all text & graphics to not appear
      txt01_mc._alpha = 0;
      txt02_mc._alpha = 0; .... all the other _mc set to 0

      then I have some variables etc.
      // declaire & initialize variables //
      var fadeIntxtSpeed:Number = 2.5;
      var fadeOutTxtSpeed:Number = 1.0;

      //debugg trace variables (nothing really important here)

      Then I have the tween code.
      var tweenTxt01:Tween = new Tween(txt01_mc, "_alpha", Strong.easeInOut, 0, 100, fadeIntxtSpeed, true);
      tweenTxt01.onMotionFinished = function():Void {
      var tweenTxtDone_Bool:Boolean = true;
      trace("Line 42 - the value of tweenTxtDone_Bool is "+tweenTxtDone_Bool);
      tweenTxt01.continueTo(0, fadeOutTxtSpeed);
      //kick off txt02 tween sequence//
      if (tweenTxtDone_Bool) {
      var tweenTxt02:Tween = new Tween(txt02_mc, "_alpha", Strong.easeInOut, 0, 100, fadeIntxtSpeed, true);
      tweenTxt02.onMotionFinished = function():Void {
      tweenTxt02.continueTo(0, fadeOutTxtSpeed);

      Originally I did not include the if condition expecting that if I nested the tweenTxt02:Tween within the first tween (following the onMotionFinishd event handler) everything would work. It did not and even with the if statement the actionScript loops on the first tween. (I keep getting "Line 42 - the value of tweenTxtDone_Bool is true") in my output window when I run it.

      Visually the first tween appears to work perfectly. I get a nice fade-up and then a fade back and the second movie clip(txt02_mc) pops in and out at different alpha values, none of which make sense to me.

      So any help would be appreciated. I hope I've included enough information,
      Oh I'm using Flash Professional 8 on a MAC (intel - under rosetta) and my publish settings are set to Flash Player 6 with ActionScript 2.0


      Rich Text Text
        • 1. Unexplained Looping with tween
          Peter Lorent Level 2
          When you use tween.continueTo() the onMotionFinished event will fire again. And using tween.stop() will immediately stop the tween without waiting for the tween.continueTo();
          Without reading the posted code extensively, I think you want something like this:
          var atween:Tween=new Tween(text1_txt,"_alpha",null,0,100,2.5,true);
          var btween:Tween=new Tween(text2_txt,"_alpha",null,0,100,2.5,true);
          var ctween:Tween=new Tween(text1_txt,"_alpha",null,100,0,2.5,true);

          Oh, and you can of course use easing on the tweens, I just use null to save typing.
          • 2. Unexplained Looping with tween
            Rich Rainbolt Level 1
            Thank you for your reply, and I did learn something new! Specifically that when I use .continueTo() it removes the .onMotionFinished() true setting. That seems obvious now - I was stuck thinking that the continue was not a new tween motion but part of the first one and the flag would not change. Thank you very much. If you have any ideas on what I could have done (de-bug wise) to discover this it would be greatly appreciated. When I tried to trace the property of the tween I got an error saying that it changed (or something like that - it was very late last night :-)
            • 3. Re: Unexplained Looping with tween
              Peter Lorent Level 2
              Debug-wise. Well, when working with event listeners the trace command can solve things quickly. If you used a trace in the onMotionFinished handler you would have seen immediately that the event fired twice.