This example is an advanced demonstration of the YUI SWF utility features.
Note: This example of the YUI SWF Utility usage requires Flash Player 9.0.115 or higher. The latest version of Flash Player is available at the Adobe Flash Player Download Center.
In this example, we demonstrate how to embed a SWF on a page, pass it configuration parameters, and interact with it via ExternalInterface and the corresponding YUIBridge library in Actionscript.
First, include the following JS source files:
Next, create a container where the SWF will be placed. The size of the container will be the size of the SWF (in this case, we set it to 400 by 200 pixels). The current content of the container is what will be displayed if there is no Flash installed on the user's machine, or if the version of the Flash player installed does not match the minimum required.
Next, we create an instance of the swf and pass the parameters:
We also subscribe to the textAdded event, which the SWF dispatches when an addText method has been called on it:
Next, we specify the handler that is called when the "swfReady" event fires (because of the subscribe() call above). The handler calls a method on the swf called "addText", and passes a string value to it. (the method is exposed by the SWF using the YUIBridge library):
Finally, we also add a handler for the "textAdded" event, which the SWF fires when its "addText" method has been called:
You can download the source code for the sample swf and the YUIBridge library here.