I have an Object and i want to apply two motion tween .I try to append them to a Timeline but i encounter some issues.When i test it,the most of the times i have to click many times in order to have results.Also a strange thing happening,if i set the elapse time for the second tween more than 1 second ( actually more than 0.5 ) it works.I work in flash cs4 and the class is linked to a Object.
package {
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Border开发者_StackOverflow社区 extends MovieClip
{
private var myTimeline : TimelineMax = new TimelineMax( );
public function Border( ) {
}
public function doAnimate ( ev : MouseEvent )
{
myTimeline.append(TweenMax.to(this, 0.5, { width : 400 } ) );
myTimeline.append(TweenMax.to(this, 0.5 , { height : 400 } ) ); // <--
}
public function deAnimate ( ev : MouseEvent )
{
myTimeline.reverse( );
}
}
}
The Main class
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Document extends MovieClip {
public function Document( ) {
right.addEventListener( MouseEvent.CLICK , border.doAnimate );
left.addEventListener( MouseEvent.CLICK , border.deAnimate );
}
}
}
You created your TimelineMax instance immediately (above your constructor), and it starts playing right away but you don't populate it until later (apparently on MouseEvent.CLICK). So you're positioning your tweens in the timeline before the virtual playhead. For example, imagine that the playhead of the timeline is at 5-seconds when you put your tweens into it at the 0-second spot. It is explained more fully at http://forums.greensock.com/viewtopic.php?f=1&t=3842&p=15044#p15044. The solution is pretty simple: just restart() your TimelineMax in your doAnimate() method. That'll obviously make the virtual playhead move to the beginning. There are some other ways you could handle this too, but I think the simplest thing in your situation is to restart() the timeline. Feel free to ask questions in the dedicated forums at http://forums.greensock.com (we work hard to get stuff answered there promptly).
精彩评论