Friday, April 27, 2007

trace(); not working with flex_sdk_2?

It did not work for me either until the error messages stopped coming...

First error message was this:

C:\WINDOWS\system32\Macromed\Flash\Flash9c.ocx
Flex Builder cannot locate the required debug version of the Flash Player. You may need to install the debug version of Flash Player 9.0 or reinstall Flex Builder. Do you want to try to debug with the current version?


To fix this download and install Adobe Flash Player 9 — Debugger Version for your browser from
http://www.adobe.com/support/flashplayer/downloads.html.

Installed? Good. That stopped the above error message for me. Well, that was not enough. Then, I got this error message:

Failed to connect; session timed out.
Ensure that:
1. You compiled your Flash application with debugging on.
2. You are running the debug version of the Flash Player.


To fix above error I corrected build.xml to keep debugging on - debug="true".
<!--build_AS3.xml----------------------------->
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="AS3" basedir="." default="compile">
<property name="mxmlc" location="C:\flex_sdk_2\bin\mxmlc.exe" />
<property name="src.dir" value="${basedir}" />
<property name="bin.dir" value="${basedir}\bin" />

<target name="compile" description="compiles the tasks">
<mxmlc
compiler="${mxmlc}"
mainclass="${src.dir}\HelloWorld.as"
as3="true"
strict="true"
output="${bin.dir}\HelloWorld.swf"
benchmark="false"
debug="true"
/>
</target>
</project>

I was trying to debug below AS3 file.
//HelloWorld.as
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.events.Event;

public class HelloWorld extends Sprite
{

public function HelloWorld()
{
var btn:SimpleButton = new SimpleButton();
btn.name = "hit me";
btn.addEventListener("click", click);
addChild(btn);

var upSprite:Sprite = new Sprite();
upSprite.graphics.lineStyle(1,0xabc);
upSprite.graphics.beginFill(0xcde,1);
upSprite.graphics.drawRect(100,100,200,50);
btn.upState = upSprite;
btn.overState = upSprite;
btn.downState = upSprite;
btn.useHandCursor = true;
btn.hitTestState = upSprite;
}

public function click(event:Event):void
{
var display_txt:TextField = new TextField();
display_txt.text = "Hello World!";
addChild(display_txt);
trace(display_txt.text);
}

}
}
Yes, I got the trace output. It was "Hello World!"

No comments: