Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
biodapesada

Can I synchronize TimelineMax/TweenMax with MainTimeline time?

Recommended Posts

I load a swf file in my application, and the swf have some tweens (TweenMax). The problem happens when I play and stop the object, like this:

var swfloader:SWFLoader = SWFLoaderObject; //SWFLoaderObject is my swf loaded
var tweens:Array = tweenMaxClass.getAllTweens();

for each(var tween:* in tweens) {
    tween.seek(0); //0 is example
}

swfloader.rawContent.gotoAndPlay(0); //0 is example

The objects are out of sync, and can not correctly resume animations, either by stress processor or other problem.

Link to comment
Share on other sites

I'm not quite sure I understand your question. Are you wanting things to be frame-by-frame synchronized with a particular MovieClip? If so, remember that Flash MovieClips are always frames-based whereas GSAP is time-based. So if the processor gets bogged down, Flash's MovieClips will actually play slower whereas GSAP will dynamically change values to reflect the appropriate time. You can, of course, set useFrames:true for your tweens/timelines but be sure to adjust the durations accordingly. If you're still having trouble, please post a very simple FLA that clearly demonstrates the problem with the least code possible. Thanks!

  • Like 1
Link to comment
Share on other sites

Thanks! The useFrames parameter helped me to synchronize the frames. The problem is exactly that you said. I converted the tweens of the object loaded to frames.
 
The code that I made:
var swfloaderObject:SWFLoader = SWFLoaderObject; //Loaded swf
convertTweensOf(swfloaderObject);

function convertTweensOf(swfLoader:SWFLoader):void {

    var tweenMaxClass:Class = swfLoader.getClass("com.greensock.TweenMax"); //get the TweenMax in the swfloader
    var _tweensConverted:Array = new Array();

    swfLoader.rawContent.addEventListener(Event.ENTER_FRAME, function enterFrameFunc(e:Event):void {
        
        if(swfLoader.rawContent.currentFrame == swfLoader.rawContent.totalFrames) {
            swfLoader.rawContent.removeEventListener(Event.ENTER_FRAME, enterFrameFunc);
        }
        
        var tweens:Array = tweenMaxClass.getAllTweens(); //Get tweens of the object

        for each(var tween:* in tweens) {
            
            var verify:Boolean = false;
            for(var i:int = 0; i < _tweensConverted.length; i++) {
                if(tweens[i] == tween) {
                    verify = true;
                    break;
                }
            }            

            if(!verify) {
                
               var paramsInfo:Object = tween.vars;
               if(!paramsInfo["useFrames"]) {
                   paramsInfo["useFrames"] = true; //Set true
                   paramsInfo["delay"] = int(paramsInfo["delay"]*swfLoader.rawContent.loaderInfo.frameRate); //Convert seconds to frames
                   tween.pause(0); // pause to start
                   tween.kill(); //kill current tween
                   tween = new tweenMaxClass(tween.target, Math.round((tween.duration()*swfLoader.rawContent.loaderInfo.frameRate)), paramsInfo); //add new tween with frame cont
                   _tweensConverted.push(tween); //push new tween to control
                
               }
            }
         }
    
    });

}

 

May have some error written in the above code.

 

Now, the first code, when I play the object tweens and the tweenmax, they are synchronized.

 

Sorry for my English. I'll try to take more care next time.

 

Thanks again!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×