Now that you know why and how you'd want to use Macromedia Flash video in a Shockwave 3D scene, you'll learn how to do it. First, you must get the video into Director. In Director MX, you could import a Flash MX movie and set that up to play the video. It would involve building a movie in Flash MX, adding a Video Clip to it, and using some ActionScript to play the streaming video.
In Director MX 2004, you can use Macromedia Flash Components. Flash Components are a bit like the standard behaviors in the Library. You do not have to know exactly how they work to use them, and with a few simple clicks they can do complex stuff for you. I went ahead and created a Flash Component for you that plays a video stream off a Flash Communication server. If you would like to create your own components, check out Macromedia Flash Developer Center.
If you haven't done so already, download the sample files at the beginning of the article. In the sample files, you will find some completed source files, along with a Macromedia Flash Component named FlashCom_StreamPlayer.swc. Place this component in the Director MX 2004/Configuration/Components folder. The next time you start Director MX 2004, it will be available in the Library palette as shown in Figure 2 below.
Figure 2. The FlashCom_StreamPlayer component
You can now drag the FlashCom_StreamPlayer component from the library to the cast or directly to the stage to make a sprite. In the Property inspector, specify the following settings (you can leave the other settings with their default values):
| autoPlay | autoPlay true |
|---|---|
| streamLocation | rtmp://216.104.212.40/experiencematters |
| streamName | riaseminar_high |
The streamLocation and streamName specify where to find the particular Macromedia Flash Communication Server and video stream. The autoPlay property specifies if the stream is automatically opened, or if it should wait for a command that you will send to it.
Rewind and play your movie. Provided that your Internet connection works properly, you will see Al appear on stage and start his lecture, though his image is distorted. The video stream you are going to use is 300 by 300 pixels, but you are playing it back in a 320 by 240 sprite. Since you are going to use the video as a texture for a Shockwave 3D model, it's best to use dimensions that are powers of two. Resize the sprite to 256 by 256 pixels; this will scale the video stream down a bit, but these dimensions give a good quality/performance ratio. Remember that all textures you use in your scene should fit into the video memory at once. Now Al's image displays correctly.
Note that if you are not using Director MX 2004 yet, you can use a Flash member and set up the streaming video yourself, or, you can even use a QuickTime or AVI video if you like. If you do, remember to set the member's Director to Stage value to false.
Next you use the image of this movie for a texture in a 3D scene. If you've read a tutorial on using Real Media in 3D before, you may expect this to be as simple as making a texture with the Macromedia Flash component member as source, and updating the texture. Unfortunately, this won’t work for much more than Real video members. There is another approach though that will work with a wide range of media, and it will even have a bit better performance than using the Real video method above.
Since you can make the video appear on Stage, grab that part of the Stage and use it for your texture. Be sure to set the directToStage property of the Macromedia Flash component to false. This approach may sound less elegant, but it works surprisingly well. It works for the Flash Component, as well as for regular Flash files, QuickTime files, AVI files, and so forth as long as the content can be rendered non-Direct-to-Stage. Unfortunately, this rules out the newly added Windows Media and DVD video added to Director MX 2004. Well, you can't have it all. Yet...
Even though this approach works, it's a bit odd to see the 3D scene with the video in it, and your original video sprite at the same time. Now you will hide the video sprite. There are two methods for doing this, one works for Director authoring and projectors; the othermethod works in the browser.
In authoring and in a projector, you can use a Movie in a Window (MIAW) to play the video and grab an image from it. You will create the movie and play your video stream, but don't open the window itself. The window will stay invisible, but the stream will play and you can grab an image from it!
Here is the theory on grabbing the appropriate part of the stage for your texture in practice. Create two movies. One of these movies will be your invisible MIAW. Make this movie 256 by 256 pixels and add the streaming video to it. In the other movie, create or import a 3D member and add the following behavior to it:
property pWorld
property pTexture, pImage
property pVideoWindow
on beginSprite me
pWorld = sprite(me.spriteNum).member
-- create new 256*256 texture from an image object
pImage = image(256,256,32)
pTexture = pWorld.newTexture("Streaming Texture", \ #fromImageObject,pImage)
-- use out texture for the screen
-- in this example, SCREEN IMAGE is already applied to our object
tShader = pWorld.shader("SCREEN IMAGE")
tShader.texture = pTexture
-- open a MIAW containing our video SWC, but DON'T open() it!
-- the video will run anyway, but we wont see it
pVideoWindow = window().new("video")
pVideoWindow.fileName = "MIAW.dir"
end beginSprite
on endSprite me
-- remove the window and the texture we created
pVideoWindow.forget()
pWorld.deleteTexture("Streaming Texture")
end endSprite
on prepareFrame me
-- eventhough our window is not visible, we can still grab its image
pImage.copyPixels((the stage).image,pImage.rect, pFlashSprite.rect)
pTexture.image = pImage
end prepareFrame
In Shockwave, you cannot use Movies in a Window (MIAW), but you can hide the video sprite through another trick. Expand the size of the stage to include the Macromedia Flash sprite, but simply crop out the sprite in the Shockwave window. Say you have a 600 by 400 pixel 3D sprite on the stage, and you want to use your 256 by 256 texture. To do so, increase the stage size to 856 by 400 pixels and place the Fash sprite in the added space. In the Publish Settings, set the General Setting to "Pixel Dimensions" at 600 by 400. In the Shockwave tab, set the Stretch Style to "No Stretching". This will crop the Flash sprite in the browser, but still lets the user grab the part of the stage the Flash sprite is on.
property pWorld
property pTexture, pImage
property pVideoSprite
on beginSprite me
pWorld = sprite(me.spriteNum).member
-- create new 256*256 texture from an image object
pImage = image(256,256,32)
pTexture = pWorld.newTexture("Streaming Texture", \ #fromImageObject,pImage)
-- use out texture for the screen
-- in this example, SCREEN IMAGE is already applied to our object
tShader = pWorld.shader("SCREEN IMAGE")
tShader.texture = pTexture
-- the sprite of our flash member
pVideoSprite = sprite(2)
end beginSprite
on endSprite me
-- remove the texture we created
pWorld.deleteTexture("Streaming Texture")
end endSprite
on prepareFrame me
pImage.copyPixels((the stage).image,pImage.rect, pVideoSprite.rect)
pTexture.image = pImage
end prepareFrame
You can download a complete version of the project using the sample files link at the beginning of the article. The sample files include the Flash Component that facilitates showing streaming flash video. Feel free to use it in this tutorial and in other projects. If you are not using Director MX 2004, you can not use the Flash Component. You can use any Flash file instead, or even a QuickTime video, just be sure to set the member's Direct-to-Stage property to false.
Using the techniques in this tutorial, you can now integrate Macromedia Flash video streams in your work without depending on your audience to install Shockwave and another large plug-ins, such as Real or QuickTime. Don't limit using the techniques for video in Shockwave 3D though. You can use the same techniques to apply any Flash movie as a texture in your movie with all the unique features of Flash MX 2004—scripted vector-animations, perfectly anti-aliased text, and even your local webcam view, you name it!