Home > Articles

  • Print
  • + Share This
This chapter is from the book

Exploring the Support Classes

In each chapter in this book, I include this "Exploring the Support Classes" section as a behind-the-scenes look at the support files. You certainly don’t have to study how everything was built, but I feel responsible to at least provide an architectural overview of all the code. If you’re interested in adding features to this project or just want to learn more about how I chose to program this project, this section should be interesting.

I’ve produced the class diagram in Figure 3.24. Keep this figure handy as you read the following overview.

The two pieces we’ve built for the project in this chapter are the main.swf (far left) and the various captionType.swf templates (far right). We also created the external .flv and .xml files that get loaded at runtime. Notice that all captionType.swf templates implement the interface file named ICaption.as. There you’ll see the three required methods each captionType.swf must implement. Recall, too, that inside our main.swf we created a symbol called CaptionHolder, which was associated with the CaptionHolder class (center). The main thing the CaptionHolder class does is load the particular captionType.swf filename specified when the main.swf triggers the init() method on its instance of the CaptionHolder class (shown as captions_clip).

Figure 3.24

Figure 3.24 This diagram shows where your main file and captionType templates fit and how they relate to the EventChannel and CaptionHolder class files.

Before you call init() on the CaptionHolder instance, you must first create an instance of the EventChannel class. You’ll see that the CaptionHolder class has an EventChannel instance (shown as a variable named eventChannel in the CaptionHolder class). In addition to loading the appropriate captionType.swf, the CaptionHolder also sets up listeners for events broadcast from the EventChannel. When the EventChannel broadcasts that a new caption should appear, CaptionHolder triggers the showText() method in the captionType.swf template.

The EventChannel does several things. First, it first loads an optional .xml file full of captions (if specified in main.swf). The EventChannel then sets up listeners for every event that can be broadcast from the media type you’re using; this is because it supports the FLVPlayback or MediaPlayback components plus plain Sound objects. If you send a reference to an FLVPlayback component when you first call the EventChannel’s init() method, all the events for FLVPlayback components are listened for. If you pass a reference to the MediaPlayback component, a different set of events are listened for. This means you can use the EventChannel as a proxy for any media type. Normally, you’d use addEventListener() on an instance of the FLVPlayback component, but this way you can use addEventListener() on the EventChannel instance. This has several advantages: The EventChannel hijacks the ready event and fires that event only after the .xml is fully loaded (and therefore is really ready). The EventChannel also merges the cue points in the .xml into ActionScript cue points. Finally, the EventChannel broadcasts a cuePoint event for regular Sound instances—something that’s not built in to Flash’s Sound class.

So, the EventChannel class channels all the event types that the different media types broadcast. Therefore, you can set up listeners if you want. In addition, the CaptionHolder instance is listening for all the possible events that should trigger the showText()—that is, so the text changes in your captionType.swf template.

The thinking behind the EventChannel class was that I wanted a unified way to listen for all the types of events related to captions. FLVPlayback components have a cuePoint event, but they’re not the same as a cuePoint events broadcast from the MediaPlayback component. In addition, .flv files generated by Captionate broadcast events for onCaption and onMarker. Using the EventChannel means you don’t have to think about how these syntaxes vary: You just channel them all to the CaptionHolder and the events you want to listen for are channeled to your captionType.swf display.

  • + Share This
  • 🔖 Save To Your Account