Any help/suggestion please.
It looks that I'm unfortunate enough that experinced users/moderators or folks who know something about this haven't seen this post.
....well still waiting for some help on whether its possible or not.
From what I know calling the ActionScript code from JSX is not possible at the moment.
The only thing you can do is invoke a function defined in JSX from ActionScript and work with the return values in AS.
A good guide for me was this blog post:
But be aware, the communication between AS and JSX is really fragile, as the article explains you have to take several measures (hex encoding / JSON.stringify) to make it work. I have it working for my application Prisma and will probably release this part of it as open source soon on my github account: Code Adventure Github Account
I will probably also write a post on my blog about that topic, since it is really important for most extensions and there are no definitive guides on how to do it correctly yet ;-)
Have you solved this yet? If not, I'd be willing to take the time to explain how.
@malive No not yet. I'd left that case. Please tell what you have.
The solution follows. I will be showing the HostObject.eval technique, instead of the CSXSInterface.instance.evalScript technique, as it is much easier for passing and returning complex parameters such as class objects.
This example assumes that the JS is in a file called InDesign,jsx in the source folder:
- Never pass InDesign objects from AS to JS, instead, pass hostObjectDelgates ((e.g., myPage.hostObjectDelegate), as in my example. If even one JS function gets passed an InDesign object, then bad things happen all over. Very bad things...
- Even when in JS you return (or rather, appear to be returning) an InDesign object to AS, you are in fact returning a "Specifier" (conceptually, a sort of logical pointer). Therefore, in AS you must instantiate a new object of the desired return type, and then set its hostObjectDelegate property to the value returned by the JS function. See my example, below.
- If you need to pass an InDesign enum from AS to JS, you must pass its value, and not the enum itself. E.g.,
- JS cannot return an Array to AS which AS sees as a native AS Array object. The JS Array will be converted to a HostObject with indexed values (myObj, myObj, etc.). The debugger does not show a "length" property, but it is indeed there and can be referenced in the AS code.
My response may be overkill for you, but I thought it might be nice for someone to post a complete example of all (?) aspects of calling between AS and JS. I must state here that 90% of what I have written is based on posts by Harbs and Davide Barraca. Most were cookbooks which have since been taken down by Adobe...
public class AS2JSInDesign
[Embed(source="InDesign.jsx", mimeType= "application/octet-stream" )]
private static var _inDesignJsxProxyClass:Class;
private static var _inDesignJsxInterface:HostObject;
_inDesignJsxInterface = HostObject.getRoot(HostObject.extensions);
public function callJSFromAS():void
// This demonstrates how to pass InDesign objects to JS and how to receive them as return values
// NEVER pass an actual InDesign object between AS and JS.
// Instead, use the HostObjectDelegate, which is sort of like a logical pointer
var firstPage:Page = new Page();
firstPage.hostObjectDelegate = _inDesignJsxInterface.getFirstPage(app.documents.activeDocument.hostObjectDelegate);
public static function performCallback():void
// Note that InDesign will crash if you even think of mentioning the New York Yankees...
_inDesignJsxInterface.causeCallback('Go Red Sox!');
public function myCallback(value:String):void
Alert.show("Received value = ' + value, "Callback Result",Alert.OK, Sprite(mx.core.Application.application));
JS (in file InDesign.jsx in the src folder):
callingClass = myCallingClass;