Loading your QuickTime Object VR movie

The Object VR movie that you load doesn't necessarily need to be in a QuickTime format: it could be an avi, mpg, wmv or any other format that Flash MX likes. Just as long as it is a movie of an object rotating before the camera. These were the images that made up the DivingHelmet.mov file, created by the very talented Darren Mok of the Western Australian Museum:

Now to do the import of your video file. But first, we need to do a quick test import so that we can get the frame rate of the video. If you know what the frame rate of your mov (or avi, or whatever) is then you can skip this bit. If you are at all in doubt about the frame rate, this quick test import will save you a whole world of pain later.

Select frame 1 of your mov layer and hit Ctrl+R to load a resource in to your library and put it in your timeline. When the Import file selector dialog appears, go find your mov video file and open it. You will be presented with an Import Video dialog like this:

Make sure that you have selected the "Embed video in Macromedia Flash document" option. We don't want to do all this hard work and still need QuickTime!

Select OK and you will get the Import Video Settings dialog:

The important bit is where it says "Length: 36.00 secs, 1.0 frames/sec". Okay, remember that 1fps. Now cancel the dialog. We're going to change the frame rate of the Flash MX movie to match it. And make sure the "Synchronize video to Macromedia Flash document frame rate" is checked. You'll see why later.

The easiest way to change the frame rate is to double-click on the 12.0 fps box in your timeline. This will open up the Document Properties dialog where you can set the frame rate to match the frame rate of your QTVR movie (in this case, 1 fps).

Now go back and select frame 1 of the mov layer and do the import again as we did for the test import, but this time don't cancel it: OK the import. If you want to, you can fiddle with the import compression settings.

Since we will be scrubbing back and forth along the timeline, it is critical that you generate a Keyframe interval of 1. If you let Sorenson generate its own keyframes or set it to anything higher than one, when you scrub backwards through the animation it will only skip to frames that have keys. This is because when a video file is compressed, a complete image is stored only when there is a keyframe in the video. Every frame after that up to the next key only stores changes to the image ? Flash (or, more accurately, the Sorenson codec in Flash) only draws what has changed, and it can only start from a keyframe.

Change your frame rate back to whatever you were using. Remember that a higher frame rate gives you smoother looking object rotation, but at a cost of a higher CPU load for the computers that your Flash MX movie plays on. Your choice.

A final note on Flash MX frame rates: you can always play around with your frame rates when importing. Experiment with the values and try importing different video files. To see how our Object VR player will perform with your imported video, click and drag the playhead back and forth along the timeline. If you don't like what you see, you can always re-import the video with different settings until you find something that works well with the media that you have.

Save it.

What have we got so far?

All we have done here is create a Flash MX movie that contains a movie clip named qtvr that has 3 layers (actions, driver, and mov), and on the mov layer we have imported a QTVR movie (or any movie file that contains a rotating object).

We changed the frame rate of the Flash MX movie so that we would make each frame in the timeline contain one frame of the QTVR movie. The plan is to scrub back and forth along the timeline as your site visitor moves their mouse over the movie. This is why we needed the "Synchronize video to Macromedia Flash document frame rate" checked.

If you preview your movie now (Ctrl+Enter), you will see a rotating object. In our case it is a spinning helmet. Not really what we want, but it's a start.

Stopping the spin

Alright, now that we have the video imported, we need to control how it will spin under the user's control.

The first step is to pad out the driver layer frames in your qtvr Movie Clip so that they run the length of the QuickTime movie that you just imported, otherwise our driver object will only be in frame 1. In our case, we had a QTVR movie of 36 frames. So, in frame 36 of the driver layer insert some frames.

Now to add a stop() ActionScript command to stop the spin. Select frame 1 in the actions layer, go to the Actions window and add the code. You should be in Expert Mode (Ctrl+Shift+E in your Actions window), and your code will look like this:

stop();

While we're here, create a new Movie Clip and name it "driver". You know: "Insert > New Symbol..." (Ctrl+F8), set Name field to "driver", and choose a Movie Clip Behavior.

Go back to your qtvr Movie Clip and select frame 1 of the driver layer. Drag the driver Movie Clip on to the stage.

Open the driver Movie Clip object and draw in a box shape starting at the 0, 0 point. Give it a width of 100 and a height of anything you like because we won't be using the height. The width of this object will define how far the mouse has to move across the screen to cause the object to complete one full rotation. The 100 width will mean 100%.

The shape doesn't need a Stroke color, but make the Fill color red for now so that we can see it when we do some testing. Later on we will set the Alpha to 0% so that we can't see it. Ultimately, we don't want to see the shape or it will obscure the movie. I know we could drag it off the stage, but I want to put it over the QTVR movie so that it is easier to compare the width of the object to the size of the QTVR movie.

You may as well name the layer "invisible box".

Previewing this should show your movie stopped at the first frame and you should have a big red box somewhere as well.

The next few sections will make extensive use of the trace() ActionScript command. Learn to love the trace and it will reward you abundantly. Check it out in your Flash MX help file at "ActionScript Dictionary > T > trace".

Save now while you have a read.