13

I'm new to flex, and trying to write some demo applications. Now I have a very newbie question: How to output some log to console(or somewhere else I can see) in a flex application?

In other language, I can use:

System.out.println("mylog");
console.log("mylog");

But I don't know how to do the same in flex.

Freewind
  • 193,756
  • 157
  • 432
  • 708

4 Answers4

31

As mentioned here, you can achieve this by doing

import flash.external.ExternalInterface;
ExternalInterface.call("console.log", "YourString");
Community
  • 1
  • 1
SleepyCal
  • 5,739
  • 5
  • 33
  • 47
16

You have several options here:

Florent
  • 12,310
  • 10
  • 49
  • 58
1

The easiest way would be using "trace", a top level function, which you can use having an IDE and a Flash Debug Player running. An other solution would be the ThunderBolt logger.

Florian Salihovic
  • 3,921
  • 2
  • 19
  • 26
1

I favour a class specific tracer called "TTrace" which can be enabled and disabled per a class. And I also write it for 1st line of each function I create. Tracing a story has often saved me on remote debugging where you cannot replicate errors that clients give you. You can then just enable or disable ttrace to clean up your outputs and enable them in the area you are updating or correcting.

SVN: https://code.google.com/p/darceys-as3-components/

ZIP: http://code.google.com/p/darceys-as3-components/downloads/list

To use TTrace

  // var definition
  private var t:Ttrace;

  // Inside constructor
  t = new Ttrace(true,"",true,false,"Debug console title",600,300);
  t.ttrace("hello");
  addChild(t);


  // Var dump
  t.ttrace("myvar = " + myVar);

  // Warning
  t.warn("warning");

  // Error
  t.error("An error has occured in .......");

Parmaters are:

  Ttrace(
        enabled:Boolean,
        applicationName:String="",
        useDebugBox:Boolean=false,
        debugBoxVisible:Boolean=true,
        debugBoxTitle:String="",
        debugBoxWidth:Number=800,
        debugBoxHeight:Number=400

)

Darcey
  • 1,949
  • 1
  • 13
  • 22