A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Tween vs. actionscript

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Posts
    343

    Tween vs. actionscript

    Hi there
    I am creating a flash file that has many long tweens... With each additional tween I had (because of the image I'm tweening) the swf gets bigger and bigger... I was wondering if there is some actionscript that I could use instead of tweening to make the same effect but to minimize the file size.

    All I'm doing is scrolling a series of images from up to down, side to side. The images fade in... scroll and fade out...

    Thanks gang!
    Losse
    Losse

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    You can use the Action Script tween class

    example:
    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    
    // Move MovieClip Down the y axes
    var myTween:Tween = new Tween(who, "_y", mx.transitions.easing.Regular.easeIn, 5, 100, 3, true);
    
    // FadeIn
    var myTween2:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 0, 100, 3, true);
    
    // FadeOut
    var myTween3:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100, 0, 3, true);
    hope this helps

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Thanks man! That works... how do I make it so that "who" stays at opacity 100 for like 3 seconds and then fade out...
    Losse

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Also I just tried it and it seems like it's just doing the mytween3... I only see it fade from 100% to 0%...
    Losse

  5. #5
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    those where example's but here is some code that will fadeOut then back in

    Code:
    function FadeOutIn (who){
    var myTween2:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
    myTween2.onMotionFinished = function(){
         var myTween3:Tween = new Tween(who, "_alpha",mx.transitions.easing.Regular.easeIn, 0, 100, 3, true);
    }
    }

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    whoa... pardon my ignorance... I'm a bit new to actionscript... So how does it all tie in together?
    Losse

  7. #7
    Senior Member RangrJay's Avatar
    Join Date
    Sep 2005
    Location
    Las Vegas
    Posts
    163
    what will happen is when that method is called, it'll start that first tween. Then onMotionFinished() it will set off the second method to fade it in.

    As for the 3 second timer deal, you got two options, set an Interval for x amount of time, or create empty keyframes, and on x keyframe call that first function to initiate the tweens. (first option is recommended for best performance and orginization)
    Xero Patience Studios
    Web Design
    Software Development
    Graphic/Logo Design

  8. #8
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    well... here's the interesting thing... I have about 6 images that will tween like I've been explaining... every additional tween starts 1.5 seconds before the previous one ends... So that they blend into eachother (assuming the fade out is 3 seconds and the fade in is 3 seconds also).
    Losse

  9. #9
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    Hi all. let's say I have an animation using the motion tween. On the last frame of the animation I can write a code like movie_mc.gotoAndPlay("about") or something. How can i make an animation using the mx transitions to do the same thing? A code that would be like " when the animation is finished movie_mc.gotoAndPlay("about")). I'm asking because by using mx transitions you only have one frame. Any help? Thank you

    ps: i've seen the onMotionFinished there but i don't really know how to use it. Tried it and no luck. I use (like the unprofessional that I am) empty frames in an empty movieclip, and i calculate the duration of the animation and depending on how many fps my flash file has, i crate the empty frames. Thats embarasing i know.
    Last edited by cristi_b_1; 03-19-2007 at 10:43 PM.

  10. #10
    Senior Member RangrJay's Avatar
    Join Date
    Sep 2005
    Location
    Las Vegas
    Posts
    163
    well... here's the interesting thing... I have about 6 images that will tween like I've been explaining... every additional tween starts 1.5 seconds before the previous one ends... So that they blend into eachother (assuming the fade out is 3 seconds and the fade in is 3 seconds also).
    Are you perfoming a fadeIn, fadeOut tween one time on each MC? if so, then try this.

    Code:
    //Put in your actions layer
    var counter:Number = 0;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    function CreateTimer():Void
    {
      setInterval(StartFading, 1500);
    }
    
    function StartFading():Void
    {
      counter++;
      switch (counter)
      {
        case 1:
          var myTween1:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 2:
          var myTween2:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 3:
          var myTween3:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 4:
          var myTween4:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 5:
          var myTween5:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 6:
          var myTween6:Tween = new Tween(who, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case default:
          break;
      }
    }
    Hi all. let's say I have an animation using the motion tween. On the last frame of the animation I can write a code like movie_mc.gotoAndPlay("about") or something. How can i make an animation using the mx transitions to do the same thing? A code that would be like " when the animation is finished movie_mc.gotoAndPlay("about")). I'm asking because by using mx transitions you only have one frame. Any help? Thank you
    Code:
    myTween.onMotionFinished() = function():Void
    {
      myMC.gotoAndStop("frame");
    }
    Last edited by RangrJay; 03-19-2007 at 11:07 PM.
    Xero Patience Studios
    Web Design
    Software Development
    Graphic/Logo Design

  11. #11
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    ok i did it :P

  12. #12
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Hi there... thanks again... I got this error

    Code:
    **Error** Scene=Scene 1, layer=image, frame=1:Line 39: Unexpected 'default' encountered
             case default:
    
    **Error** Scene=Scene 1, layer=image, frame=1:Line 42: Unexpected '}' encountered
         }
    
    Total ActionScript Errors: 2 	 Reported Errors: 2
    Losse

  13. #13
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Does anyone know why I got these errors?
    Losse

  14. #14
    Instructional Designer
    Join Date
    Feb 2005
    Location
    Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
    Posts
    299
    Before mere mortals can render an opinion on the cause of an effect, some information about precipitating events is required (error messages are not always indicative). When you post a file, the probability (and quality) of answers is immediately higher.
    Tomas

  15. #15
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    Quote Originally Posted by losse
    Hi there... thanks again... I got this error

    Code:
    **Error** Scene=Scene 1, layer=image, frame=1:Line 39: Unexpected 'default' encountered
             case default:
    
    **Error** Scene=Scene 1, layer=image, frame=1:Line 42: Unexpected '}' encountered
         }
    
    Total ActionScript Errors: 2 	 Reported Errors: 2
    1) you have this
    case default:

    should be
    default:


    2) you can remark out the "}" on line 42.

  16. #16
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Thanks Gang... Here is the entire code... Now I don't get errors but when I open it I don't see anything happening!

    Code:
    #include "lmc_tween.as"
    //Put in your actions layer
    var counter:Number = 0;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    function CreateTimer():Void
    {
      setInterval(StartFading, 1500);
    }
    
    function StartFading():Void
    {
      counter++;
      switch (counter)
      {
        case 1:
          var myTween1:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 2:
          var myTween2:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 3:
          var myTween3:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 4:
          var myTween4:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 5:
          var myTween5:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        case 6:
          var myTween6:Tween = new Tween(mv_house1, "_alpha", mx.transitions.easing.Regular.easeIn, 100,0, 3, true);
          break;
    
        default:
          break;
      }
    }
    Losse

  17. #17
    Instructional Designer
    Join Date
    Feb 2005
    Location
    Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
    Posts
    299
    If you do not get a response soon, please post a copy of the lmc_tween.as. Obviously, your code to tween the alpha is not working. The reason is probably obvious to some, but not to me. If I see the code that the displayed code cooperates with, it might help.

    Otherwise, you might want to check path assumtions with a trace or two.
    Tomas

  18. #18
    Senior Member
    Join Date
    Aug 2000
    Posts
    343
    Thomas, would you like to send me an email and we can try to resolve this via email?
    Losse

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center