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 << What is the mouse doing over the image?

Moving to the left of the image

Now it's not really working when it goes below 0, so we need to adjust our formula when the mouse pointer moves to the left of our box. Our first problem is that as we are moving to the left our range is starting at -1, and we would like it to start at 0. (It actually does start at 0, but unfortunately it overlaps with the code we have already written: that's where the funkiness is creeping in.)

To correct this, we need to add 1 to our _xmouse calculation before we perform the modulo. That gets us closer to what we want, but we still have negative numbers. Since we don't have any negative frames, we finally need to correct this by adding 36.

This may be seen in the following table (the red area shows the bit that we already have working, the grey areas show where the 36 frames to the left of the box are repeating):

Once again, you can try them out in a trace ActionScript statement to see how they perform as you move your mouse left of the QTVR movie. And this is the code to spin the movie:

onClipEvent (enterFrame) {
        _parent.gotoAndStop(36 + ((int(_xmouse / 100 * 36)+ 1) % 36));
}
      

Combining the formulas

We now have two formulas: one for zero and above, and the other for below zero. To combine these, we will make use of an if-else statement block. Also, a quick look at the formulas that we have been experimenting with shows that the int(_xmouse / 100 * 36) part gets used quite a bit (and we'll need to use it again in the if statement's condition test). Let's put that into a variable so that we don't have to calculate it over and over again. Here's the code for our driver Movie Clip:

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

This is all very well if your QTVR movie is of an object rotating anticlockwise (as seen from above), but if your object rotates clockwise then you have a problem. What you end up with is an object that seems to rotate from right to left as you move your mouse from left to right. (If you have a look at the series of images that we had for the diving helmet, you can see that our QTVR movie rotated clockwise.)

The effect we are after is similar to the experience of running your hand across a prayer wheel: you expect the surface that you touch to move in the same direction.

The simple solution is to subtract our 1 to 36 value from 37. This will give us a range that runs in the other direction (36 to 1). This is what we needed for the "Western Australia: Land and People" exhibition, but your Object VR may well run in the other direction. Use what you need. Here's our code so far:

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

Next >> Making the driver handle any movie length / Making the code simple

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.