0

I'm working on a InDesign CS6 Extension in Adobe Flash Builder 4.6. For some reason my code (which worked fine for a long time) now throws the error null is not an object. The error is located in a javascript injection (last line):

public class Script {
    private static var _instance:Script;

    [ Embed (source="script.jsx", mimeType="application/octet-stream") ]
    private var ScriptClass:Class;
    private var jsxInterface:HostObject;

    public function Script() {
        if (Script._instance) {
            throw new Error("only single instance allowed");
        }
        Script._instance = this;
        this.init();
    }

    public static function getInstance():Script {
        return _instance;
    }

    private function init():void {
        Log.log("HostObject.mainExtension: "+HostObject.mainExtension);
        for each (var s:String in HostObject.extensions) {
            Log.log("Extension: "+s);
        }

        this.jsxInterface = HostObject.getRoot(HostObject.mainExtension);
        this.jsxInterface.eval(new ScriptClass().toString());
    }

    public function getScript(name:String):Object {
        return this.jsxInterface[name];
    }

    public function exec(name:String, args:Array = null):Object {
        return InDesign.app.doScript(
            this.jsxInterface[name], ScriptLanguage.javascript, args, UndoModes.AUTO_UNDO); // <-- this is where the error appears
    }

I'v checked the arguments of InDesign.app.doScript for null, but everything is ok. This is the function (inside script.jsx) that is being called:

function prepareForImageExport(params) {
    var pageItem = params[0];
    var prefix = params[1];
    var bounds = params[2];
    var ax = params[3];
    var ay = params[4];

    pageItem.visible = true;

    // create tmp container
    var container = app.activeDocument.rectangles.add(app.activeDocument.activeLayer);

    container.name = prefix+container.id;
    container.geometricBounds = bounds;
    container.strokeWeight = 0;
    container.strokeColor = app.activeDocument.swatches.item("None");
    container.fillColor = app.activeDocument.swatches.item("None");
    container.visible = true;
    container.transparencySettings.blendingSettings.opacity = 100;

    // create a duplicate of the pageItem in the tmp container
    var copyItem = pageItem.duplicate(app.activeDocument.activeLayer);
    copyItem.transparencySettings.blendingSettings.opacity = 100;
    copyItem.locked = false;
    container.geometricBounds = bounds;
    container.move([ax,ay]);
    copyItem.visible = true;

    app.select(copyItem);
    app.cut();
    app.select(container);
    app.pasteInto();

    app.scriptArgs.setValue("container", container.name);
}

At this place I'm stuck. I don't know in which line of the javascript the error appears.

I'm very new to ActionScript and I can't seem to find a documetation about how to debug Javascript injections in ActionScript. Also I don't really know, which variables (like app) are accessible inside the javascript code and which ones (like console - I can't write console.log) are not.

Any help is greatly appreciated!

Florian Gössele
  • 4,376
  • 7
  • 25
  • 49

2 Answers2

0

You should first try to check that the arguments/params sent to javascript are valid(not null or undefined there) after that try to log every line in the JS code to see where it crashes, I am not sure how the JS code is executed in your case(I did not made extensions) but if it uses the HtmlLoader then you can access the window object of the loader and add to it a log function or a console object that has a log function.

simion314
  • 1,394
  • 16
  • 29
0

Check first this.jsxInterface if it's a valid object returned. You can use the debug as mode and set a breakpoint there. Then look at this.jsxInterface[name].

I havn't made any extensions since a couple of years but jsxInterface should be reachable without "this." as you set it as a variable above.

For what it's worth, I would not try to debug the js code within Flex Builder. What you can do is use a log function (http://debrouwere.github.io/Extendables/docs/packages/logging/doc/readme.html) then look at what you receive from Flex. Beware that unsurprisingly when you pass Flex Objects, you actually receive Flex objects in the ExtendScript context.

But to be brief, your error signifies that you are trying to use an object that doesn't exist (this.jsxInterface in my humble opinion). Maybe you js code is just fine, maybe the parameters too but the problem should be located in the inbetweens.

And for flex logging you can use "trace()" but you need to be in a debug mode.

Loic
  • 2,173
  • 10
  • 13
  • Thanks for the answer, unfortunately it didn't help. I swapped the javascript code to actionscript and came across a new issue: http://stackoverflow.com/questions/30322899/random-errors-in-actionscript-memory-overflow – Florian Gössele May 19 '15 at 10:23
  • Sorry it was no help. – Loic May 19 '15 at 15:02
  • 1
    Check this : http://blogs.adobe.com/cssdk/category/cssdk/indesign-extensions and specially hostObjectDelegate – Loic May 19 '15 at 15:21