# Animation class
{: .no_toc }

An **Animation** plays a silent AVI clip in a box on the form, such as the moving picture of a file copy or a search in progress.

![An animation with Center set to True and an opaque BackStyle that shows the first frame of the clip of this page's samples, a dark gray square of 16 by 16 pixels, in the middle of the control](/twinBASIC-docs/Reference/Contributed/VBCCR18/Images/Animation.png){:width="60" height="60"}

```tb check_build check_run arch=win32,win64
Dim Clip As String
Clip = WriteSampleClip()                ' a small silent AVI in the temporary folder
Animation1.LoadFile Clip
Animation1.Play                         ' repeats until StopPlay
Debug.Print Animation1.Playing
Animation1.StopPlay
Animation1.Unload                       ' the control lets go of the file
Kill Clip
' Output:
' True
```

In the samples of this page, **WriteSampleClip** writes a small silent AVI clip to the temporary folder and returns its path.

The control wraps the animation control of Windows (`SysAnimate32`), which plays an AVI clip that has no sound and is uncompressed or compressed by run-length encoding. It stands in place of the Animation of `MSCOMCT2.OCX`: the **Open**, **Close** and **Stop** methods of that control are [**LoadFile**](#loadfile), [**Unload**](#unload) and [**StopPlay**](#stopplay) here.

Of the [common members](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md), the control has those under [Name and place](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#name-and-place), [Window handles](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#window-handles), [Mouse](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#mouse), [Keyboard and focus](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#keyboard-and-focus), [Dragging the control](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#dragging-the-control), [OLE drag and drop](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#ole-drag-and-drop) and [Right-to-left](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#right-to-left), **RightToLeftLayout** included. It has no **Font**, **FontQuality** or **VisualStyles**.

* TOC
{:toc}

## Loading a clip

[**LoadFile**](#loadfile) loads a clip from a file, and [**LoadRes**](#loadres) from a resource, either of the program or of a library file. Each shows the first frame of the clip and replaces a clip that was loaded. [**Unload**](#unload) removes the clip.

**LoadFile** raises run-time error 53 when Windows cannot open the file as a clip. **LoadRes** raises run-time error 326 when there is no clip with that identifier, and 53 when the library file cannot be loaded.

```tb check_build
Animation1.LoadRes 101                  ' the clip 101 of the program
Animation1.LoadRes 7, "Clips.dll"       ' the clip 7 of a library
```

While a clip is loaded from a file, the control keeps the file open, and the file cannot be deleted. **Unload** lets go of it.

## Playing the clip

[**Play**](#play) starts the clip and [**StopPlay**](#stopplay) stops it, and [**Playing**](#playing) tells which of the two the control is doing. A clip that is loaded and not started is not playing. The event [**Change**](#change) is raised each time the clip starts and each time it stops, whether it ended or was stopped, and **Playing** then has the new state.

**Play** takes the number of times to play the clip and the frames to play. A clip that is already playing is stopped first.

```tb check_build
Private Sub Animation1_Change()
    If Animation1.Playing Then
        Debug.Print "started"
    Else
        Debug.Print "stopped"
    End If
End Sub
```

[**AutoPlay**](#autoplay) makes a clip start as soon as it is loaded.

## The look of the control

A new control plays nothing, and has [**AutoPlay**](#autoplay) and [**Center**](#center) set to **False** and a [**BackStyle**](#backstyle) of **CCBackStyleTransparent**.

With a transparent [**BackStyle**](#backstyle) the background color of the clip is not drawn, and the control's [**BackColor**](#backcolor) shows in its place; with an opaque one the clip keeps all its colors. With [**Center**](#center) set to **True** the clip is drawn in the middle of the control, and otherwise at its top left corner. Changing **AutoPlay**, **BackStyle** or **Center** loads the clip again, which stops a clip that was playing.

![Three animations with the first frame of the samples' clip, a dark gray square: with Center set to False and an opaque BackStyle it is at the top left corner of the control, with Center set to True in the middle, and with a transparent BackStyle the whole frame is its background color, so only the pale yellow BackColor shows](/twinBASIC-docs/Reference/Contributed/VBCCR18/Images/Animation_Look.png){:width="621" height="143"}

Properties
----------

### AutoPlay
{: .no_toc }

Whether a clip starts to play as soon as it is loaded. **Boolean**. Default: **False**.

### BackColor
{: .no_toc }

The background color of the control, which a clip with a transparent [**BackStyle**](#backstyle) shows. **OLE_COLOR**. Default: **vbButtonFace**.

### BackStyle
{: .no_toc }

Whether the background of the clip is transparent or the clip keeps its own colors. A member of [**CCBackStyleConstants**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#ccbackstyleconstants). Default: **CCBackStyleTransparent**. Another value raises run-time error 380.

### Center
{: .no_toc }

Whether the clip is drawn in the middle of the control. **Boolean**. Default: **False**, with which it is drawn at the top left corner.

### Playing
{: .no_toc }

Whether the clip is playing. **Boolean**, read-only.

Methods
-------

### LoadFile
{: .no_toc }

Loads a clip from a file and shows its first frame. A clip that was loaded is removed.

Syntax: *object*.**LoadFile** *FileName*

*FileName*
: *required* A **String**: the path of the AVI file.

### LoadRes
{: .no_toc }

Loads a clip from a resource and shows its first frame. A clip that was loaded is removed.

Syntax: *object*.**LoadRes** *ResID* [ , *FileName* ]

*ResID*
: *required* An **Integer**: the identifier of the clip's resource.

*FileName*
: *optional* A **String**: the path of a library or program file that has the resource. The default is the program itself.

### Play
{: .no_toc }

Plays the loaded clip, after stopping it if it was already playing. A clip that is not loaded plays nothing.

Syntax: *object*.**Play** [ *RepeatCount* ] [ , *StartFrame* ] [ , *EndFrame* ]

*RepeatCount*
: *optional* A **Long**: how many times to play the clip. The default is -1, which plays it until [**StopPlay**](#stopplay). A value of 0 plays nothing.

*StartFrame*
: *optional* An **Integer**: the number of the first frame to play, counted from 0. The default is 0.

*EndFrame*
: *optional* An **Integer**: the number of the last frame to play. The default is -1, the last frame of the clip.

### StopPlay
{: .no_toc }

Stops the clip, if it is playing.

Syntax: *object*.**StopPlay**

### Unload
{: .no_toc }

Removes the loaded clip and lets go of its file. The control then shows nothing.

Syntax: *object*.**Unload**

Events
------

### Change
{: .no_toc }

Raised when the clip has started playing and when it has stopped, by reaching its end or by [**StopPlay**](#stopplay). [**Playing**](#playing) has the new state. See [Playing the clip](#playing-the-clip).

Syntax: *object*\_**Change**( )

### MouseDown, MouseMove, MouseUp
{: .no_toc }

As the [common events](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#mousedown-mousemove-mouseup) of these names; *X* and *Y* are in twips, whatever the scale units of the control's container, measured from the top left corner of the control.

## See Also

- [Common members](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md) -- the members this control shares with the package's other controls
