ActionScript Interaction

If you load your own swf files into the engine you might want to interact with it, to allow for more specialized behavior - e.g. an animation starting when the page the clip resides on becomes visible. Here is how to connect your code to the engine.

= Setup / Connecting =

To get a reference to the engine, all you have to do is add a function to the root of your swf, named. This will give you a reference to the  instance the element resides in. There are three variants, one with only the engine reference, one which also passes the  the element resides on, and finally one which additionally also passes the actual   wrapping the SWF.

This function is called by the engine as soon as the swf is done loading, passing the paramater so that the swf can work with it later on (or right away, of course). It normally makes sense to store the reference in some local variable. For more information on the received interface and functionality it provides, please refer to the API.

= Referencing other elements =

If you wish to communicate between a loaded swf and another element in the book there are three steps:

1. Enable the ElementIDs plugin.

2. In the XML set the  attribute of the element that should be referenced, e.g. to.

3. In the swf that should reference the element use the following code to get a reference:

If you have two swfs that should communicate, you can use the  property of the   element (using its interface):

Then you can access everything in your swf using the  variable.

= Using events =

To give an example on using events, here is how you would check when the page the swf resides on becomes visible:

For more event types see the API.

= Sources =

To compile your code when using the interfaces/classes, make sure to have the sources that come with the releases placed in your include path, and you'll need to import them by adding the following statement at the very top of your code:

For the swf interaction you need the  class:

And for the second example to work (using the event) you'll additionally need

Alternatively, if you don't care for the types you can just declare all of the variables of type  (or  ), of course. Using the classes is much recommended, though, otherwise typos or wrong assumptions can be a real pain.