如何在网页中跟踪ActionScript?

时间:2012-02-24 16:27:16

标签: flash debugging actionscript

我有Firefox,Firebug,Flashbug和* .fla + * .as文件的flash widged。是否可以使用跟踪槽作为带有可变监视等的代码进行调试?怎么样?

修改

我有一个flashbug,可以看到trace命令输出。但是我需要像其他调试器一样逐步进行调试,而Flash Professional也可以使用独立的Flash电影。

2 个答案:

答案 0 :(得分:3)

您可以简单地使用Flash调试器。 :)见this article from Adobe

或使用MonsterDebugger

答案 1 :(得分:0)

我正在使用ExternalInterface,因为我认为可能有一种比我以前的方法更好的访问控制台的方法,我发现ExternalInterface.call的第一个参数可以指定的不仅仅是打电话的功能。

我编写此函数是为了简化使用JavaScript consoletrace的简化:

Console.log(...);

或者在条件编译块中:

CONFIG::DEBUG {
    Console.log(...);
}

/**
 * @author    zzzzBov <zzzzbov@gmail.com>
 * @version   0.1
 * @since     2012-02-24
 */
package com.zzzzbov.debug {
    import flash.external.ExternalInterface;

    /**
     * `com.zzzzbov.debug.Console` is a debugging tool to interface with web browsers' developer consoles.
     */
    public class Console {

        /**
         * The hidden utility method to make `ExternalInterface` calls to JavaScript.
         * 
         * @param type the type of console function that will be called
         * @param args the array of arguments to pass to the console[type] function
         */
        private static function console(type:String, args:Array = null):void {
            //prevents an additional `null` from being passed as an argument when the second parameter is skipped
            if (args === null) {
                args = [];
            }
            //Checks that the ExternalInterface is available and that console[type] exists
            if (ExternalInterface.available && ExternalInterface.call('function () {return !!(console && ("' + type + '" in console));}')) {
                //calls the console[type] function with the provided arguments.
                ExternalInterface.call.apply(ExternalInterface, ['console.'+type].concat(args));
            } else {
                //calls `trace` if console[type] isn't available
                trace.apply(null, [type].concat(args));
            }
        }

        /**
         * Checks the truthiness of {@param expr}; if the assertion fails, it also prints out {@param args}.
         * 
         * @param expr an expression to test
         * @param args the message to print to the console
         */
        public static function assert(expr:*, ... args):void {
            console('assert', [expr].concat(args));
        }

        /**
         * Clears the console of messages
         */
        public static function clear():void {
            console('clear');
        }

        /**
         * Writes the number of times that count was executed. The {@param title} will be printed in addition to the count.
         * 
         * Warning: No IE support
         * 
         * @param title A title for a particular counter
         */
        public static function count(title:String = null):void {
            console('count', title != null ? [title] : []);
        }

        /**
         * Writes the arguments to the console.
         * 
         * Warning: No IE support.
         * 
         * @param args the arguments to print in the console
         */
        public static function debug(... args):void {
            console('debug', args);
        }

        /**
         * Prints an interactive listing of all properties on {@param obj}.
         * 
         * @param obj the object to expand
         */
        public static function dir(obj:*):void {
            console('dir', [obj]);
        }

        /**
         * Prints an XML source tree of an HTML or XML element.
         * 
         * Warning: No IE support; source tree may not be fully supported.
         */
        public static function dirxml(node:*):void {
            console('dirxml', [node]);
        }

        /**
         * Writes the arguments to the console as an error message.
         * 
         * @param args the arguments to print in the console
         */
        public static function error(... args):void {
            console('error', args);
        }
        /**
         * Writes a message to the console and opens a nested block for future console messages.
         * 
         * Warning: No IE support. Call {@link #groupEnd()} to close the block.
         * 
         * @param args the arguments to print in the console
         */
        public static function group(... args):void {
            console('group', args);
        }

        /**
         * Writes a message to the console and opens a collapsed, nested block for future console messages.
         * 
         * Warning: No IE support. Call {@link #groupEnd()} to close the block.
         * 
         * @param args the arguments to print in the console
         */
        public static function groupCollapsed(... args):void {
            console('groupCollapsed', args);
        }

        /**
         * Closes the block most recently opened by {@link #group(...)} or {@link #groupCollapsed(...)}.
         * 
         * Warning: No IE support.
         */
        public static function groupEnd():void {
            console('groupEnd');
        }

        /**
         * Writes the arguments to the console as an informational message.
         * 
         * @param args the arguments to print in the console
         */
        public static function info(... args):void {
            console('info', args);
        }

        /**
         * Writes the arguments to the console.
         * 
         * The first argument may use a printf-like syntax for substituting subsequent arguments into a formatted message.
         * 
         * @param args the arguments to print in the console
         */
        public static function log(... args):void {
            console('log', args);
        }

        /**
         * Turns on the JavaScript profiler.
         * 
         * Call {@link #profileEnd()} to stop profiling and print the profiler report.
         * 
         * @param title the title to print in the header of the profile report
         */
        public static function profile(title:String = null):void {
            console('profile', title != null ? [title] : []);
        }

        /**
         * Turns off the JavaScript profiler and prints the profiler report.
         */
        public static function profileEnd():void {
            console('profileEnd');
        }
        /**
         * Creates a new timer with the given name.
         * 
         * Warning: No IE support. Call {@link #timeEnd(name)} to stop the timer and print the elapsed time.
         * 
         * @param name the name of the timer to start
         */
        public static function time(name:String):void {
            console('time', [name]);
        }

        /**
         * Stops the timer with the provided name and prints the elapsed time to the console.
         * 
         * Warning: No IE support. Call {@link #time(name)} to start a timer of a given name.
         * 
         * @param name the name of the timer to stop
         */
        public static function timeEnd(name:String):void {
            console('timeEnd', [name]);
        }

        /**
         * Writes the arguments to the console as a warning.
         * 
         * @param args the arguments to print in the console
         */
        public static function warn(... args):void {
            console('warn', args);
        }
    }
}

如果您发现任何问题或有任何建议,请告诉我。