调试JavaScript注入在ActionScript(Flash Builder中) [英] Debug JavaScript injection in ActionScript (Flash Builder)

查看:222
本文介绍了调试JavaScript注入在ActionScript(Flash Builder中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个的InDesign CS6扩展在Adobe Flash Builder中4.6。出于某种原因,我的code(这对于长时间工作的罚款),现在引发错误 null不是一个对象。错误坐落在一个JavaScript注入(最后一行):

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
    }

我心中已经检查InDesign.app.doScript的参数为空,但一切正常。这是函数(内script.jsx),该被调用

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);
}

在这个地方我被困。我不知道在出现的错误。javascript的行

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

我是很新的动作,我似乎无法找到有关如何在ActionScript调试JavaScript注入documetation。此外,我真的不知道,哪些变量(如应用程序)都在里面的JavaScript code访问,哪些。(如控制台 - 我不能写的console.log)不

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.

任何帮助是极大AP preciated!

Any help is greatly appreciated!

推荐答案

首先检查this.jsxInterface如果它是一个有效的对象返回。您可以使用调试的模式,并设置一个断点出现。然后看this.jsxInterface [名]。

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].

我没有带,因为几年所做的任何扩展,但jsxInterface应该是不可达这一点。当你将它设置为一个变量上面。

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.

有关它的价值,我不会尝试调试的Flex Builder中的JS code。你可以做的是使用日志功能(的http:// debrouwere .github.io / Extendables /文档/包/日志/ DOC / readme.html文件),然后看你的Flex得到什么。要注意的是毫不奇怪,当你通过Flex对象,你居然收到了ExtendScript背景Flex对象。

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.

不过是短暂的,你的错误表示您正在尝试使用不存在(this.jsxInterface愚见)的对象。也许你JS code是蛮好的,也许是太参数,但问题应该设在inbetweens。

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.

这篇关于调试JavaScript注入在ActionScript(Flash Builder中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆