Time Line Manipulation

Time Line Manipulation


This tutorial assumes you have uniSWF added to your current unity project.

In this tutorial we are going to go through the key features of timeline control using the uniSWF API. This example is located in "uniSWF/Examples/Tutorial 04 - TimeLine control".

UniSWF allows manipulation of a movieclips timeline through a very simple to use API, For more information check out the API reference MovieClip

Once you have opened the project enter the scripts folder and open the "Tut4_timelineControl" javascript file.  This file contains all the code for the above example. Rather than guiding you through the entire process of integrating the assets, we are going to look at some key areas of the code instead.

Set Up

The following code snippet gets a handle to the stage which is part of the MovieClipOverlayCameraBehaviour component. We are using this because it will attach the swf assets directly to the camera and allows us to work within pixel space.


stage = GetComponent(MovieClipOverlayCameraBehaviour).stage;
mc = new MovieClip( "uniSWF/Examples/Tutorial 04 - Timeline control/swf/Tut04_timeline.swf:TimelineExample" );
stage.addChild( mc );

Stop()

Here we are accessing the movieclip and applying the basic instruction to stop the playhead.

 mc.stop();

GotoAndStop()

This line tells the movieclip to stop at a particular frame. In this case it will stop at the very last frame of the movieclip's timeline. Check out the API MovieClip for further functionality

 mc.gotoAndStop( mc.totalFrames ); 

Play()

This moves the playhead along the timeline of the movieclip to animate the scene

 mc.play()

GotoAndPlay()

Begins playing of the movieclip at a specified position

 mc.gotoAndPlay(10);

FrameLabels

You can label the frames in the flash timeline to allow referencing using the uniSWF API. For example:


mc.gotoAndPlay( "start");
mc.gotoAndStop( "end" );



The example code ( "uniSWF/Examples/Tutorial 04 - TimeLine control") shows how to use these simple commands to orchestrate the timeline. For more information check out the API reference MovieClip