User Guide
88 Chapter 3: Cross-Product Extensions
Accessing proxy objects
If you want to access a proxy object outside of an auto-release block, you must use
the
RemoveFromAutoReleasePool() function. The RemoveFromAutoReleasePool()
function manually removes an object reference from the auto-release pool before exiting the
auto-release block.
In this example, the reference to the object defined as
selObject is removed:
RPCMethods.CreateAutoReleasePool();
var selObject = fw.selection.get(0);
RPCMethods.RemoveFromAutoReleasePool(selObject);
RPCMethods.DestroyAutoReleasePool();
Now you can use the selObject object outside the auto-release block.
Note: You must remember to release the selObject object when you are done with it.
Additionally, you can nest auto-release blocks, that is, you can create an auto-release block and
then call a function that creates its own auto-release block. The
ReleaseObject() function
iterates through an object’s properties and releases any proxy objects it finds.
A simple RPC example
This example creates a 200 x 200 pixel rectangle in Fireworks when a button in a Flash
application is pressed.
To build a Flash application that uses RPC to create a Fireworks object:
1 Download the supporting ActionScript stub files (a series of supporting ActionScript files) from
the Macromedia website, you need to put them in your working directory (where the new FLA
file will reside).
2 Then, in Flash MX 2004 or Flash MX Professional 2004, open a new document.
3 In the first frame, add the following in the Actions panel to link the general fireworks stub file
to the movie when it is published:
#include "fwstubs.as"
4 Create a simple button which will activate the RPC script.
5 Insert the button in the first Frame, in the middle of the stage.
6 Attach the following ActionScript code to the button to activate the RPC code when the button
is pressed:
on(press){
RPCMethods.CreateAutoReleasePool();
var fw = new Fireworks();
//Hide all panels - this function commented out as it will crash if run
from inside Fireworks
//fw.setHideAllFloaters(true);
//Define the document objects the long way
var res = new Object();
res.units = "inch";
res.pixelsPerUnit = 72;
var size = new Object();
size.x = 220;
size.y = 220;