| Author |
Message |
|
bit-101
Member
Joined: Mon Dec 26, 2005 6:10 pm Posts: 165
|
 Tracing to the output panel in AS3
I just came up with a solution to trace to the output panel in AS3.
http://www.bit-101.com/blog/?p=843
I modified the FlashOut class for AS3 (FlashOut3):
package org.flashdevelop.utils {
import flash.system.fscommand;
public class FlashOut3
{
public static function trace(msg:Object):void
{
fscommand("trace", msg.toString());
}
}
}
Put it in the same directory. You just need to add that dir to your AS3 class path with the -source-path command line arg to mxmlc.exe. Then you can say FlashOut3.trace(message); and it will appear in FD's output panel!
|
| Tue Aug 01, 2006 11:54 am |
|
 |
|
warhero
Member
Joined: Sun Jan 01, 2006 12:48 pm Posts: 26
|
I can't seem to get this to work. Can someone take a quick look at my test for this and see what's up? it's a really basic test. i'm trying to get it to work...
thanks. here is a link to the project. http://www.smithaaronlee.net/downloads/testFlex2Project.zip
|
| Sun Aug 13, 2006 10:51 pm |
|
 |
|
derean
Member
Joined: Tue Mar 14, 2006 4:53 am Posts: 81
|
the class included with the latest version (flex2/as3 beta) doesn't work, i've corrected the errors
Code: /** * Connects a flash movie to the FlashDevelop program. * Ported to AS3 by Keith Peters - http://www.bit-101.com/ * @author Mika Palmu * @version 2.7 */
package org.flashdevelop.utils { import flash.net.XMLSocket; import flash.events.DataEvent; import flash.events.Event; import flash.events.IOErrorEvent; import flash.events.SecurityErrorEvent; import flash.xml.XMLDocument; import flash.xml.XMLNode; import flash.utils.setInterval;
public class FlashConnect3 { /** * Variables */ private static var socket:XMLSocket; private static var messages:Array; private static var interval:Number; private static var swfUrl:String; public static var status:Number = 0; public static var host:String = "localhost"; public static var port:Number = 6969;
/** * Constants */ public static const INFO:Number = 0; public static const DEBUG:Number = 1; public static const WARNING:Number = 2; public static const ERROR:Number = 3; public static const FATAL:Number = 4;
/** * Opens the connection to the FlashDevelop program. */ public static function initialize():void { messages = new Array(); socket = new XMLSocket(); socket.addEventListener(DataEvent.DATA, onData); socket.addEventListener(Event.CONNECT, onConnect); socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError); socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError); interval = setInterval(sendStack, 50); socket.connect(host, port); }
public static function onData(event:DataEvent):void { FlashConnect3.status = 1; FlashConnect3.onReturnData(); }
public static function onConnect(event:Event):void { FlashConnect3.status = 1; FlashConnect3.onConnection(); }
public static function onReturnData():void {
}
public static function onConnection():void {
}
public static function onIOError(event:IOErrorEvent):void { FlashConnect3.status = -1; FlashConnect3.onConnection(); }
public static function onSecurityError(event:SecurityErrorEvent):void { FlashConnect3.status = -1; FlashConnect3.onConnection(); }
/** * Sends all messages in message stack to FlashDevelop. */ private static function sendStack():void { if (messages.length > 0 && status == 1) { var message:XMLDocument = new XMLDocument(); var rootNode:XMLNode = message.createElement("flashconnect"); while (messages.length != 0) { var msgNode:XMLNode = XMLNode(messages.shift()); rootNode.appendChild(msgNode); } message.appendChild(rootNode); socket.send(message); } }
/** * Adds a custom message to the message stack. */ public static function send(message:XMLNode):void { if (messages == null) initialize(); messages.push(message); }
/** * Adds a trace command to the message stack. */ public static function trace(msg:String, state:Number=FlashConnect3.DEBUG):void { var msgNode:XMLNode = new XMLNode(1, null); var txtNode:XMLNode = new XMLNode(3, escape(msg)); msgNode.attributes.state = state; msgNode.attributes.cmd = "trace"; msgNode.nodeName = "message"; msgNode.appendChild(txtNode); send(msgNode); }
} }
|
| Sun Aug 13, 2006 11:28 pm |
|
 |
|
Philippe
Admin
Joined: Wed Aug 31, 2005 7:27 am Posts: 7507 Location: Paris, France
|
It seemed to work fine but didn't check it extensively
- I updated the class in the ZIP, thanks.
|
| Mon Aug 14, 2006 6:34 am |
|
 |
|
derean
Member
Joined: Tue Mar 14, 2006 4:53 am Posts: 81
|
it wasn't compiling because state:Number could not be null since it isnt a reference, if you look at the original code
|
| Mon Aug 14, 2006 1:54 pm |
|
 |
|
warhero
Member
Joined: Sun Jan 01, 2006 12:48 pm Posts: 26
|
sweet so if I just update that FlashOut3 class it should trace to the output window in flashdevelop?
|
| Mon Aug 14, 2006 5:55 pm |
|
 |
|
warhero
Member
Joined: Sun Jan 01, 2006 12:48 pm Posts: 26
|
weird. I am getting this error:
Incorrect XML message: <policy-file-request/>
|
| Mon Aug 14, 2006 6:24 pm |
|
 |
|
warhero
Member
Joined: Sun Jan 01, 2006 12:48 pm Posts: 26
|
i am a little confused with FlashOut3 and FlashConnect3. Do I need to be using both of them somehow to be getting traces to the ouptput pannel? or are they meant to be used seperately?
I was just trying to use FlashConnect3.trace("test trace"); and that was giving me the above error message...
|
| Mon Aug 14, 2006 6:28 pm |
|
 |
|
Philippe
Admin
Joined: Wed Aug 31, 2005 7:27 am Posts: 7507 Location: Paris, France
|
warhero wrote: weird. I am getting this error:
Incorrect XML message: <policy-file-request/>
- FlashOut uses fscommand to communicate directly with FlashDevelop, so it must run hosted in the application (ie. in a tab).
- FlashConnect is a socket server the SWFs can connect to, so it can run anywhere.
The error you get is not weird: your SWF is probably not trusted so it asks permission to FlashConnect's socket server (which currently doesn't understand this request...).
- you can create the trust files automatically from the Files panel.
- or you can download the pre-release plugins in this thread which include an updated version of FlashConnect.
Edit: the patch is included in recent releases
Last edited by Philippe on Thu Dec 21, 2006 9:50 pm, edited 1 time in total.
|
| Mon Aug 14, 2006 6:38 pm |
|
 |
|
warhero
Member
Joined: Sun Jan 01, 2006 12:48 pm Posts: 26
|
thanks. that all makes sense now. Downloaded the patch and it works fine now.
|
| Mon Aug 14, 2006 6:44 pm |
|
 |
|
evl
Member
Joined: Fri Dec 02, 2005 3:01 pm Posts: 103
|
How exactly do I get the resulting SWF from an AS3 "Quick build" to run inside a tab?
Following the instructions provided I've got code-completion for AS3 and I can sucessfully compile the Hello World project but I'm stuck as to how I can get a simple trace to display.
|
| Fri Mar 30, 2007 8:17 am |
|
 |
|
Philippe
Admin
Joined: Wed Aug 31, 2005 7:27 am Posts: 7507 Location: Paris, France
|
evl wrote: How exactly do I get the resulting SWF from an AS3 "Quick build" to run inside a tab?
Following the instructions provided I've got code-completion for AS3 and I can sucessfully compile the Hello World project but I'm stuck as to how I can get a simple trace to display.
Currently the Quick Build can't run inside a tab - that's why FlashConnect will be prefered as it can receive traces from anywhere.
|
| Fri Mar 30, 2007 8:41 am |
|
 |
|
lostchild
Member
Joined: Thu Oct 19, 2006 12:22 am Posts: 18
|
I can get the trace in the output panel. But only if i put the whole org package in my project folder, instead of calling it from flashdevelop directory ... I have the ASCompletion.ClassPath set to
D:\Program Files\FlashDevelop\Library; F:\Development\__root__\AS3_intrinsic_classes in the program settings.
Looking at the attribute name - ASCompletion.ClassPath- i guess this path is just for code completion (?) if that' s the case it works fine for me. But when i try quickbuild with this code :
Code: package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import org.flashdevelop.utils.* // or import org.flashdevelop.utils.FlashConnect3 public class App extends Sprite { public function App() { init(); } private function init():void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT; FlashConnect3.trace("grrr....")
} } }
i get the following error -->
MxmlcShell command: -o;F:\Development\Flex2\FD_mxml\FlashConnectsSample\App.swf;--;F:\Development\Flex2\FD_mxml\FlashConnectsSample\App.as Loading configuration file F:\Development\__root__\flex_sdk_2\frameworks\flex-config.xml F:\Development\Flex2\FD_mxml\FlashConnectsSample\App.as(19): col: 4 Error: Access of undefined property FlashConnect3.
FlashConnect3.trace("grrr....") ^
Done(1)
This is the last main problem i have to deal with in FlashDevelop. Other than this everything is fine... any known issues like this ?
cheers ...
|
| Thu Apr 05, 2007 4:46 pm |
|
 |
|
Philippe
Admin
Joined: Wed Aug 31, 2005 7:27 am Posts: 7507 Location: Paris, France
|
For the AS3 Quick Build, you have to specify the additional classpathes after the @mxmlc tag:
http://www.flashdevelop.org/community/v ... php?t=1070
|
| Thu Apr 05, 2007 4:54 pm |
|
 |
|
lostchild
Member
Joined: Thu Oct 19, 2006 12:22 am Posts: 18
|
A week ago i tried that option also but it didn't work either =| .I guess i couldn't get this part at first :
Code: -library-path+=../../frameworks/locale/{locale} -source-path+=locale/{locale} -locale=en_US
I looked in the Flex SDK folder and library path. the source path arguments confused me a bit ... "{locale}" at first. Like "do i need to use this ? ..." And meanwhile i saw how to localise some Flex stuff =)
After trying relative library path, I tried the absolute path in the mxmlc arguments. And from now on i will be writing some happy code seeing the trace in the output =) thank you ...
|
| Thu Apr 05, 2007 6:20 pm |
|
|