Object VR in Flash MX

A detailed tutorial on building an easy-to-use QuickTime Object VR player for Flash MX - without the QuickTime plugin.

click here to get more tutorials

01 Introduction
02 What should the QTVR player do? / How should the player be structured?
03 Useful reading / Designing the player
04 Loading your QuickTime Object VR movie
05 What have we got so far? / Stopping the spin
06 What is the mouse doing over the image?
07 Moving to the left of the image / Combining the formulas
08 Making the driver handle any movie length / Making the code simple
09 Using the Object VR player
10 What about a loader for this?
11 Conclusion / About the authors / Copyright

Previous << Moving to the left of the image / Combining the formulas

Making the driver handle any movie length

Throughout all of our examples here, I have focussed on only one QTVR movie: the one supplied by the Western Australian Museum. It has 36 frames in it and runs at 1 fps. Your Object VR will inevitably have a different length and changing the magic numbers of 36 and 37 that we have used here to other magic numbers that relate to the number of frames in other movies will only lead to pain. So let's fix that.

The _parent object has a _totalframes property which lets us know how many frames are in the parent Movie Clip. In our case, when we use the code _parent._totalframes in our driver clip's enterFrame event handler, Flash MX looks at the qtvr clip and checks to see how many frames it has (36 for ours, yours will probably be different).

Replacing 36 with _parent._totalframes, and 37 with (_parent._totalframes + 1) gives us our new code:

onClipEvent (enterFrame) {
        framePos = int(_xmouse / 100 * _parent._totalframes);
        if (framePos < 0) {
                _parent.gotoAndStop(_parent._totalframes + 1 - (_parent._totalframes + ((framePos + 1) % _parent._totalframes)));
        } else {
                _parent.gotoAndStop(_parent._totalframes + 1 - (1 + (framePos % _parent._totalframes)));
        }
}
      

This lets our driver clip handle any length QTVR movie as long as we have the same number of frames in the driver and mov layers. If the driver layer has more frames than the mov layer, the Object VR will disappear for some frames. If the mov layer has more frames than the driver layer, the Object VR will get stuck when it hits a frame where the driver doesn't exist.

Making the code simple

Those of you who can remember back to high school algebra will be able to see that these formulas can be simplified further by multiplying out and cancelling terms with opposite signs, resulting in our final clockwise code:

onClipEvent (enterFrame) {  //clockwise
        framePos = int(_xmouse / 100 * _parent._totalframes);
        if (framePos < 0) {
                _parent.gotoAndStop(1 - ((framePos + 1) % _parent._totalframes));
        } else {
                _parent.gotoAndStop(_parent._totalframes - (framePos % _parent._totalframes));
        }
}
      

And applying the same process to our anticlockwise code gives:

onClipEvent (enterFrame) {  //anticlockwise
        framePos = int(_xmouse / 100 * _parent._totalframes);
        if (framePos < 0) {
                _parent.gotoAndStop(_parent._totalframes + ((framePos + 1) % _parent._totalframes));
        } else {
                _parent.gotoAndStop(1 + (framePos % _parent._totalframes));
        }
}
      

This makes it really easy to build an Object VR player for any QTVR movie of any length by simply grabbing the code that is appropriate for the rotation of your video file and pasting it on to your driver clip.

Time to wrap things up. Let's have a quick look at how to use our player.

Next >> Using the Object VR player

01 Introduction
02 What should the QTVR player do? / How should the player be structured?
03 Useful reading / Designing the player
04 Loading your QuickTime Object VR movie
05 What have we got so far? / Stopping the spin
06 What is the mouse doing over the image?
07 Moving to the left of the image / Combining the formulas
08 Making the driver handle any movie length / Making the code simple
09 Using the Object VR player
10 What about a loader for this?
11 Conclusion / About the authors / Copyright

© 2003 Glasson Murray Group Pty Ltd (ACN 098 651 542), Western Australia. All rights reserved.