Tween Class Help

Hi everyone. I'm doing a website and I'm having trouble with
something. I have a movieclip that I want to animate using the
tween class. however, I want thetween to occur once the frame that
the code is on loads. This is a problem because I can't use
onEnterFrame because it will play thetween continuously. I need it
to play oncethe frame loads and only once. I tried using the
movieclip.onLoad function but it's not working for me. What am I
doing wrong? Here is the code that I'm using...

If the code is in an externally loaded Movie you need to
determine when the frame is available and the general way to go is
using the MovieClipLoader class.
If the code is in a already loaded movie then follow
naomind's recommendation

Similar Messages

  • AS 3 Tween Class help

    I could really use some help. I'm using AS 3 and am creating a simple vertical menu where 6 buttons reside. When any of the buttons is clicked it takes you to specific frame label. On each frame label I have some actionscript that once arrived at will animate a small triangle along the y axis to rest next to the button the user has just clicked. I am trying to use the Tween Class to aminate the small triangle. Here is what I have so far:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    var arrowTween:Tween = new Tween(arrow_mc, "y", Regular.easeOut, 20, 80, 2, true);
    The var created assigns the triangle a new end position. Here's where I need help. In the example above the 20 is the starting position and what I need is something that says whatever the current (this) position value is move to the desired end position value, which is 80 in the example.
    I'm up late trying to figure this one out. Any help or ideas to lead me in the right direction is greatly appreciated.

    Craig,
    Thanks for the help. I really appreciate it. However, I'm still having a bit of trouble. When I put in "current arrow_mc" I get syntax errors in the compiler errors box.
    1084: Syntax error: expecting rightparen before arrow_mc. 
    Here is the code I have put in:
    stop();
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    var arrowTween:Tween = new Tween(arrow_mc, "y", Elastic.easeOut, current arrow_mc.y, 39.5, 1, true);
    Any ideas?
    Mike

  • Component and tween class help

    Hi All,
    I have a simple component which is dynamically added to a
    movieClip (‘parent_mc’) and is then made a listener of
    that movieClip. I’m creating 5 different component instances
    and each one is given a unique ‘id_number’. The
    component uses a tween calss function for moving to a different x
    position. The ‘parent_mc’ broadcasts a message
    (this.broadcastMessage("moveComp", compId, newX); and only the
    component with the matching id moves to the new position.
    Everything works as expected but the problem I’m having
    is trying to call a function to let the 'parent_mc' know when the
    tween has finished. Can anyone help??
    Thanks,
    Ty
    This is a cut down of the components script.

    You didn't explain the 'obj' bit and how I define it.
    Anyway, I have done a work around by placing a movieClip in
    the component to handle the tween and call the moveFinished
    function in the component when it's done.
    There must be a way to call the same moveFinished function
    from within the moveComp.myTweenX.onMotionFinished function.
    Thanks for the responses.
    Ty
    The movieClip code is this:

  • Tween Class Easing AS modification help.

    hi guys im new here in the forums, ive been searching around about tween class easing in as2 and ive found this great tutorial http://www.republicofcode.com/tutori...enclasseasing/
    i need a help though, im not really a actionscript programmer, but i wanted to modify this code:
    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var myHoriTween:Tween = new Tween (myBall_mc,"_x",Strong.easeOut,0,400,2,true);
    myHoriTween.onMotionFinished = function (){
    how would i modify the code so my objects not only goes on a straight line(_x like in the code from 0x to 400x),
    what if i wanted a diagonal direction, it will start in x and ends in y?
    hope you could show me how its done thanks in advance!!

    to tween along a diagonal, tween both the _x and _y properties at the same time:
    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var myHoriTween:Tween = new Tween (myBall_mc,"_x",Strong.easeOut,0,400,2,true);
    var myVertiTween:Tween = new Tween (myBall_mc,"_y",Strong.easeOut,0,400,2,true);
    myHoriTween.onMotionFinished = function (){ }
    if you want to tween the _x and then tween the _y, use:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var myHoriTween:Tween = new Tween (myBall_mc,"_x",Strong.easeOut,0,400,2,true);
    var myVertiTween:Tween
    myHoriTween.onMotionFinished = function (){
    myVertiTween = new Tween (myBall_mc,"_y",Strong.easeOut,0,400,2,true);

  • HELP PLZ!! Array Button Menu that fades in/out content with Tweener or Tween Class...!!!

    OK.
    So I've been trying the last couple of days to make 2 different codes i had into one...
    The first on is using the Tweener class and everytime that I press a button it fades out the loaded content of the previous selection, waits for it to finish and then loads the content of the button pressed. Everything works fine with this part.
    The second code is the on that is using an Array to dynamicaly rollover, rollout and keep selected the buttons.
    It was also changing the content of the mc that everything is loaded on but without this fancy fade in - fade out...!!
    So i think its time for some code now...:
    Here are 2 different approaches:
    This is the code that uses the onMotionFinished of the Tween Class:
    var groupinfo:Array = [ {mc:about, toload:"mcHome"},
         {mc:service, toload:"mcService"},
         {mc:contact, toload:"mcContact"}];
    var activebtn:MovieClip;
    var holder1:MovieClip = _root.attachMovie("mcHome", "mcMain", 10);
    holder1._x = 0;
    holder1._y = 110;
    function doClick() {
    //          \/THE PROBLEM IS FROM HERE\/
         if (this != activebtn){
              var mcTween:Tween = new Tween(mcMain, "_alpha", Strong.easeOut, 100, 0, 1, true);
              mcTween.onMotionFinished = function() {
                   _root.holder1.attachMovie(this.p, "mcMain", 1);
                   var mcTween2:Tween = new Tween(mcMain, "_alpha", Strong.easeOut, 0, 100, 10, true);
    //          /\UNTIL HERE/\
         var prevbtn:MovieClip = activebtn;
         activebtn = this;
         this.gotoAndStop(FADEINSTOP);
         prevbtn.onRollOut();
    function init() {
       for (var element in groupinfo) { 
          // btn is a pointer to one of the nav buttons
          var btn:MovieClip = groupinfo[element].mc;      
          // have each button remember which library/mc it is supposed to load
          btn.p = groupinfo[element].toload;      
          // assign functions to each event
          btn.onRollOver = doRollOver;
          btn.onRollOut = doRollOut;
          btn.onRelease = doClick;
    init();
    And the Example:
    The onMotionTween code works ok with the tweening but doesn't change the movieclip.
    This is the code that uses the caurina Tweener Class with no onMotionFinished:
    var groupinfo:Array = [{mc:about, toload:"mcHome"},
                                {mc:service, toload:"mcService"},
                                {mc:contact, toload:"mcContact"}];
    var activebtn:MovieClip;
    var holder1:MovieClip = _root.attachMovie("mcHome", "mcMain", 10);
    holder1._x = 0;
    holder1._y = 110;
    function doClick() {
    //          \/PROBLEM FROM HERE\/
         if (this != activebtn) {
              Tweener.addTween(mcMain,{_alpha:0, time:1, transition:"easeOutQuart"});
              var holder2:MovieClip = _root.attachMovie(this.p, "mcMain2", 11);
              holder2._alpha = 0;
              holder2._x = 0;
              holder2._y = 110;
              Tweener.addTween(mcMain2,{_alpha:100, time:1, delay:1, transition:"easeOutQuart"});         
              mcMain = mcMain2;
    //           /\TO HERE!!!/\
         var prevbtn:MovieClip = activebtn;
         activebtn = this;
         this.gotoAndStop(FADEINSTOP);
         prevbtn.onRollOut();
    function init() {
         for (var element in groupinfo) {
              // btn is a pointer to one of the nav buttons
              var btn:MovieClip = groupinfo[element].mc;
              // have each button remember which library/mc it is supposed to load
              btn.p = groupinfo[element].toload;
              // assign functions to each event
              btn.onRollOver = doRollOver;
              btn.onRollOut = doRollOut;
              btn.onRelease = doClick;
    init();
    Other Example:
    The Tweener code works perfectly this first time but the second time removes the conent and does just the fade in.
    The code for the buton group i got it from                     here...
    Please could someone help me with this thing!!
    I think its a great piece of dynamic code if we can eventualy make it  work properly!!
    Thanksss!!!
    Shorten the code...  Left only the part that needs mod!!

    clbeech, Thank you but doesnt do anything either....!!It is a  bit usefull but... !!
    The problem is that the code cant give the "this.p" to the movieclip...
    Here is the mess i've made with few changes from your part... and alot of treces to wich detected that the this.p is can't get in the onMotionFinished function...
    its only the doClick function:
    function doClick() {
         trace ("---------vars after click----------")
         trace ("activebtnStart  "+  activebtn);
         trace ("this.p  OutPre:  " + this.p);
         if (this != activebtn){
              trace ("mcMainAlphaBefore:  " + mcMain._alpha);
              trace ("mcMainBefore:  " + mcMain);
              var mcTween:Tween = new Tween(mcMain, "_alpha", Strong.easeOut, 100, 0, 1, true);
              mcTween.onMotionFinished = function() {
                   holder["mcMain"].removeMovieClip();
    //               trace ("mcMainStart:  " + mcMain);
    //               trace ("mcMain2Start:  " + mcMain2);
    //               trace ("mcMainAlphaStart:  " + mcMain._alpha);
    //               trace ("mcMain2AlphaStart:  " + mcMain2._alpha);
                   trace ("this:  " + this);
                   trace ("this.p  Pre:  " + this.p);
                   holder.attachMovie(btn.p, "mcMain", 1);
                   holder.alpha = 0;
                   trace ("this.p  After:  " + this.p);
    //               mcMain = mcMain2;
                   new Tween(mcMain, "_alpha", Strong.easeOut, 0, 100, 10, true);
    //               mcMain._alpha = 100;
    //               trace ("mcMainEnd:  " + mcMain);
    //               trace ("mcMain2End:  " + mcMain2);
    //               trace ("mcMainAlphaEnd:  " + mcMain._alpha);
    //               trace ("mcMain2AlphaStart:  " + mcMain2._alpha);
         trace ("this.p  OutAfter:  " + this.p);
         var prevbtn:MovieClip = activebtn;
         activebtn = this;
         this.gotoAndStop(FADEINSTOP);
         prevbtn.onRollOut();
         trace ("this.p  "+  this.p);
         trace ("this  "+  this);
         trace ("prevbtn  "+  prevbtn);
         trace ("activebtn  "+  activebtn);    
    Pfff.....
    I think its best to Attach the .fla!!
    Please have a look on it if you have anytime..!!
    Thanks for your interest..

  • Need help with AS 2 Tween class

    Hi,
    I'm using the tween class just fine, but I want my tween to
    move on a curve.
    I can't seem to figure out how to achievve this.
    I get the math to do this sort of thing, and I think I could
    manage it with
    AS3, but the project requires the use of AS2. I'm having
    issues
    transitioning what I know to what I need.
    Can anyone help??
    Thanks,
    KB

    you can use the tween class to update an object property and,
    if you have a parametric equation for your curve, you can use your
    tween's onMotionChanged event to update your object's _x and _y
    properties.

  • Tween Class fails

    Hi,
    i was looking for some help with tween class beacuse i have a strange problem. I'm working with AS3, when i test my project, sometimes the Tween fails, sometimes it works. It's really strange, i don't know why. The animation stops before the end point. The most strange for me is why sometimes it works and sometimes no?
    My code is geting a little complex, then i tried to do the same process in a simple model, and the result was the same, i run the model many times, in 5 or 3 % the animation finished before the correct end point. Does anybody with the same problem?
    Thanks in advanced!
    Henrique.

    Thanks clbeech!
    In fact, i was using one code line (var nameTween:Tween = new Tween(...)) and calling this line many times by a Timer event. But, how can i use diferent names for the tween var? May i use a counter like var nameTween[counter]:Tween = new Tween(...)?
    My code is a little big and confuse, i'll try to solve the problem without publish the code. If i don't find a solution, i'll organize it and them put it here.
    Thanks a lot!
    H.

  • Is there a bug in the as3 tween class

    Is there a bug in the as3 tween class that causes tweens to stop before completing. I read that there is and that a 3rd party tween class should be used. I'm just starting out learning as3 and experimenting but this would be good to know when I move onto more complex projects.
    Also the solution for this was to make your function global. Does this simply mean place your function in the top level of your movie.
    I have done research on this topic but I found many conflicting answers.
    Any assistance is welcome thanks in advance.

    the tween declaration (if you need one) must be placed within the scope of the function.  so, if the below function f() is defined in a movieclip, you can use any of the 3 (but don't use the last):
    ///////// most common use ////////////////////////////////////////
    var t:Tween;
    function f(){
    t=new Tween(...)
    /////// next most common use /////////////////////////////////////////
    //no declaration needed because the tween is not referenced anywhere outside the function so need not be assigned a variable
    function f(){
    new Tween(...)
    /////////// least common, not good coding, but possible ////////////
    // var t:Tween;  // declared on the root timeline, for example
    function f(){
    MovieClip(root).t=new Tween(...)
    p.s.  please mark correct/helpful answers

  • External swf and the tween class

    i have an external swf which i import into my main swf using
    the loadMovie command. my external swf has some tween class
    animations in it. if i run the main movie, the external swf movie
    runs fine of course...but the tween classes are not loaded. am i
    missing somthing?
    here is the code from the external swf file which is applied
    to a clickable movie clip of course.
    this.onRollOver = function() {
    rewind = false;
    play();
    var squaretween = new mx.transitions.Tween(previewthumb,
    "_xscale", mx.transitions.easing.Elastic.easeOut, 0, 1200, .5,
    true);
    var squaretween = new mx.transitions.Tween(previewthumb,
    "_yscale", mx.transitions.easing.Elastic.easeOut, 0, 1200, .5,
    true);
    squaretween.onMotionFinished = function() {
    loadMovie("hotairlarge.swf",
    "_root.homecontainer.printworkcontainer");
    any help would be great!

    try inserting the following to line 1,frame 1 your main swf:

  • Tween Class - calling Function

    What am I doing wrong?  I have been using the Tween Class in AS2 for years.  This is how I have been using it.
    //Beginning of my Flash file
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    function fadeon(mcname:String) {
        new Tween(mcname, "_alpha", Strong.easeOut, 0, 100, 1.5, true);
    //This is placed on Frames where I want to call this particular Tween
    fadeon(mymovieclipsname);
    Similiar setup for AS3 with no errors when I run it.  The only problem is it doens't work. 
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    function fadeon(mcname:String):void {
        new Tween(mcname, "alpha", Strong.easeOut, 0, 100, 1.5, true);
    //on Frames where I want to call this particular Tween
    mymovieclipsname.fadeon();
    if I run this portion the same as AS2 I get this lovely Compiler Error message.
    1067: Implicit coercion of a value of type flash.display:MovieClip to an unrelated type String.
    Any thoughts or help wold be greatly appreciated.

    Note that a better solution for AS3 is to simply create a Class that does the tween (to itself), then apply that to each bullet and leave the parent out of it. I'd probably have done the same thing in AS2 as well, but I learned As1>As3>As2, so my experience is not representative.
    Here's the Class that I use to do this (note I didn't use a Tween for this task as they have the danger to go out of memory before the tween is done unless you store a reference to them):
    package view.effects {
    import flash.display.Sprite;
    import flash.events.Event;
    //view.effects.SimpleFadeIn
    public class SimpleFadeIn extends Sprite {
      public function SimpleFadeIn() {
       super();
       addEventListener(Event.ADDED_TO_STAGE, startFade);
      protected function startFade(e:Event):void {
       alpha = 0;
       addEventListener(Event.ENTER_FRAME, doFade);
       addEventListener(Event.REMOVED_FROM_STAGE, cleanUp);
      protected function doFade(e:Event):void {
       if (alpha < 1) {
        alpha += .04;
       } else {
        cleanUp(e);
      protected function cleanUp(e:Event):void {
       removeEventListener(Event.ENTER_FRAME, doFade);
       removeEventListener(Event.REMOVED_FROM_STAGE, cleanUp);
    Note that the reason the path to the Class is there in a comment is so team members can copy and paste it into the Base Class for a MC they want to apply this behavior to.

  • Tween class - tweening from curent position

    Hi, I've been looking at the tween classes and I was
    wondering how I could use it to tween an object that i already
    placed on the stage? So using it's current position and tweening to
    a new position. Is there a way of doing it by simply using a term
    that flash understands (eg _xPosition)?
    Cheers
    Ray
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    new Tween(ball_mc, "_x", Elastic.easeOut, 300, 50, 3, true);
    new Tween(ball_mc, "_y", Elastic.easeOut, 100, 50, 3,
    true);

    I think I asked for help a little quick there.
    this._x
    it looks like that is what I was after.
    Ray

  • Tween class animations - modifying elasticity

    I am fairly new to Flash, and couldn't find the help I needed through a search.
    I am using the Tween class to move objects when buttons are clicked. I am using elastic easing as the animation ends, and it looks ok. But am I able to modify the elasticity at all? I like the effect, but it is a little strong and I would like to reduce the bounce at the end.
    Can I do this, or by using this method of animation am I losing the fine control that I would have by using the timeline and I just have to suck it up?

    Well the easing you provide for the tween is just a reference to a function. So you can search the web and find your own functions. Robert Penner is famous for a large number of really great easing methods. Or you can just muck a bit with the built in functions. I put two small clips on the stage, clip0 and clip1. Then this code:
    import fl.transitions.*;
    import fl.transitions.easing.*;
    var myTween0:Tween=new Tween(clip0,"x",Elastic.easeOut,100,500,2,true);
    myTween0.start();
    var myTween1:Tween=new Tween(clip1,"x",myEase,100,500,2,true);
    myTween1.start();
    function myEase(t:Number, b:Number, c:Number, d:Number):Number {
    return Elastic.easeOut(t, b, c, d, .5, .9);
    The the top one is the default and the lower one is my "modified" version. If you check out the help files for the Elastic classes easeOut method it requires the first four arguments (time, start value, end value of the prop, and duration) as do all tween functions. But the last two a and p are specific to elastic easing. The first is the amplitude of the sine wave and p is the period of the sine wave. I don't know what the units are on either of those, but I'm guessing pixels (or twips) and either seconds or milliseconds. So you could just fiddle with those numbers.
    I'm not sure if there is anyway to send those numbers directly through the Tween constructor -- regardless of whether I used the built in functions or made my own.

  • Tween Class not working in Projector

    Hi all...
    I have a very strange problem. I have a slideshow that uses
    the Tween class to fade between jpg images. In the swf file and in
    the standalone flash player, everything works just great. However,
    when I make a projector file from the fla, either from within
    Flash, or from the standalone player, the transitions stop working.
    This behavior is identical on both a PC and a Mac.
    Does anyone have a clue why projector would behave
    differently?
    Thanks.
    Lance Ong

    In your custom UIComponent class, your never added your myAction instance. Try this for the MyUIComp constructor:
    public function MyUIComp() {
        myAction = new MyAction();
        this.addChild(myAction);
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • Timeline like navigation  using tween class

    I am a beginner, please help!
    So I want to create a timeline nav like this site:
    http://us.leica-camera.com/photography/m_system/m9/
    timeline is a 40 x 40px color filled movie clip that use as the playhead. 
    featContent is the movie clip that contains the feature content.
    I make the timeline controls the feature contents to slide (using tween class) to the next feature. No problem on this, but I can't make the feature to slide when click on the button.
    Please shed some lights!  Thank you very much!
    function loadFeature(node){
          var m = 0;
          this.createEmptyMovieClip("featNav",50);
          this.timeline._xscale = 1;
         this.createEmptyMovieClip("featContent",10);
          this.featNav._x = featNav_x;
          this.featNav._y = featNav_y;
          featl = node.childNodes.length;
               fBtnW = (featNav_w/featl);
               duration = 10*featl;
          for(var x=0; x < featl; x++){
               //create nav buttons
               feat[x] = node.childNodes[x];
              this.button = this.featNav.attachMovie("menu_btn","featBtn"+x,x+  1);
               this.button.menu_txt.text = feat[x].attributes.name;
               this.button.menu_txt.embedFonts = true;
               this.button.menu_txt.autoSize = true;
               this.button.menu_txt.setTextFormat(menuTxtFmt);
               this.button.mask_mc._width = this.button.menu_txt._width;
               this.button._x = 20 + fBtnW*x;    
              this.button.curNum = x;
               //onClick
               this.button.mask_mc.onRelease = function(){
                    if (this._parent._parent._parent.overlay._y > -this._parent._parent._parent.overlay._height){
                         removeOverlay();
                    feat = this._parent._parent._parent.featContent;
                   count = this._parent.curNum;
                    newX = -Stage.width*count;
                    moveTimeline = new Tween(this._parent._parent._parent.timeline, "_xscale", None.easeIn, (422*count), 1850, (duration-10*count), true);
                    slideFeature = new Tween(feat, "_x", Regular.easeOut, feat._x, newX, 0.4, true);
               var t_listen = new Object;
               t_listen.onMotionChanged = function(target){
               if (count == 0){
                    for(var i=0; i < featl; i++){
                         if (target.obj._xscale > (422*i)){
                              newX = -Stage.width*i;
                              slideFeature = new Tween(target.obj._parent.featContent, "_x", Regular.easeOut, target.obj._parent.featContent._x, newX, 0.4, true);
               var moveTimeline:Tween;
               moveTimeline = new Tween(this.timeline, "_xscale", None.easeIn, 1, 1850, duration, true);
               moveTimeline.onMotionFinished = function(){
                         moveTimeline.start();
          moveTimeline.addListener(t_listen);

    Nevermind, I think I found what I needed. Thanks guys!

  • New Flash8 Tweening Class?

    Hello Community,
    I have been using a pretty cool technique for controlling
    motion / alpha / scale of various instances on my stage with this
    technique where you read in the MX Tweening Class and then set up
    these variables that changes the motion / alpha / scale over time.
    And, if I place these variables into a function and call that
    function on an event (pushing a button, for example) the animation
    over time event happens. I cannot get this technique to work with
    (what appears new) the FP8 Tweening Matrix thingy.
    Below (first part) is some sample code of the old way, in MX,
    I did this:
    I cannot get something similar to this to work in Flash Pro 8
    (FP8) with these funky matrix thingies that this class is now built
    within.
    For example, I need to have these import (class) lines at the
    beginning, but then how do I create the same sort of animation in
    the function?
    import flash.geom.Transform;
    import flash.geom.Matrix;
    I guess, basically, what I am trying to ask here is: How do
    you create animation via the (what was formerly known as) the Tween
    Class in FP8?
    Any help/info would be appreciated.
    Thanks for your time,
    -john

    I agree with LuigiL ...you didnt set the variable fInt, so
    those wont work. I use the Tween class in Flash8 daily just
    fine.

Maybe you are looking for

  • Macbook mid 2010 top case for white macbook 4,1

    Can i replace the whole topcase assembly (keyboard plus trackpad) of my white MacBook 4,1 early 2008 with a topcase assembly (keyboard plus multitouch trackpad ) from a mid-2010 macbook?? my topcase is cracked and i want to replace it..

  • WebLogic and SSL: supplying private key password upon startup

    Hello, Does BEA have an API I can use to customize the WebLogic Server startup? I have a password callback function that I would like the WebLogic Server to call when it needs the password for decrypting the server certificate private key... -- POCO

  • BIG PROBLEM: Multiple (loop) NOTIFY COMMITS for same VO instance

    Dear forum, I have a big problem with 1 of my VO. When I insert a record using AddProjectView this works fine. The record is persisted successfully. When I insert another record using AnotherView (e.g. different table) a commit is also done on AddPro

  • JDev 11g - ADF - PanelDashBoard

    Hi All, We have panelDashBoard in our application. we are facing issues in aligning content inside panelBox under DashBoard. Please check the below code <af:switcher facetName="#{attrs.maximized ? 'maximized' : 'restored'}" id="dcs1"> <f:facet name="

  • DBMS_XMLSCHEMA commands concurrent executing

    Java class methods execute statements 'DBMS_XMLSCHEMA.registerSchema' and 'DBMS_XMLSCHEMA.deleteSchema' on Oracle 9i through JDBC using Jboss 4.0.0. Several users may request these service simulaneously and the following happens: one or both actions