Archive for July, 2009

Mac + Adobe AIR 1.5.1 + Flex Builder 3.0.2 + Flex SDK 3.3 = No Run or Debug Without This Fix; UPDATE

If you’re using a Mac and trying to build AIR applications with the following:

  • Mac
  • AIR 1.5.1
  • Flex Builder 3.0.2.214193
  • Flex SDK 3.3

You won’t be able to Run or Debug from Flex Builder and you won’t really get an error explainging why…here’s a list of instructions from the logged bug on Adobe’s Flex Bug and Issue Management System: http://bugs.adobe.com/jira/browse/SDK-19707

NOTE: If you just go to run the AIR app with this setup it’ll silently fail…if you try to debug it you’ll get the following: “DEBUG: error dialog with text: “Process terminated without establishing connection to debugger. If the program is already running, close it before attempting to debug.

To fix it, follow these steps:

  1. Download the attached change.sh.
  2. Copy the change.sh into the root directory of the SDK, at the same level of the ant, asdoc, bin, frameworks, lib, etc. folders. This probably looks something like: “/Applications/Adobe Flex Builder 3.0.2 Plugin-in/Adobe Flex Builder 3 Plug-in/sdks/3.3″ or wherever you keep your Flex SDKs…
  3. Change the script to executable (chmod 755 change.sh) — open up terminal and cd to the directory where you just put the change.sh file and run the command in bold: chmod 755 change.sh
  4. Run the script (./change.sh) run the bold command in terminal to execute the script: ./change.sh
  5. Open up FB and create a HelloWorld AIR app and make sure the SDK for Flex 3.3 is selected for this project.
  6. Run the AIR app and make sure it opens.

Big thanks to Joann Chuang Anderson for this fix, as it was driving me nuts!

Post to Twitter Tweet This Post

, , ,

2 Comments

Java byte[] to ActionScript String - UPDATED

I recently needed to send a Java byte[] to Flex that ultimately needed to be converted to an ActionScript String on the Flex side. I wrestled with it for a bit before I realized that I needed to make the byte[] on the Java side encoded with UTF-8.

Here’s a quick EchoService I created in Java that takes a String parameter from Flex, converts it into a byte[], and then sends it back to Flex, as well as the accompanying Flex code that handles the service’s result and transforms the byte[] back into a String in ActionScript.

package com.wasi.services.test;

import java.io.UnsupportedEncodingException;

public class EchoService
{
	public String echo(String param)
	{
		return param;
	}

	public int echo(int param)
	{
		return param;
	}

	public byte[] echoStringToByte(String param)
	{
		System.out.println("echoStringToByte: " + param);

		byte[] byteArray = null;

		try
		{
			byteArray = param.getBytes("UTF-8");
		}
		catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
		return byteArray;
	}

}

And on the Flex side:

import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

private var echoStringToByteService:RemoteObject;

private function init():void
{
	trace("init");

	this.echoStringToByteService = new RemoteObject();
	this.echoStringToByteService.destination = "echoService";
	this.echoStringToByteService.endpoint = "http://localhost:8080/bds/messagebroker/amf";
	this.echoStringToByteService.showBusyCursor = true;
	this.echoStringToByteService.addEventListener(ResultEvent.RESULT, onEchoStringToByteServiceResult);
	this.echoStringToByteService.addEventListener(FaultEvent.FAULT, onEchoStringToByteServiceFault);
}

private function onEchoServiceSubmit(evt:MouseEvent):void
{
	trace("onEchoServiceSubmit");

	var str:String;

	str = this.echoStringTextInput.text;
	this.echoStringToByteService.echoStringToByte(str);
}

private function onEchoStringToByteServiceResult(evt:ResultEvent):void
{
	trace("onEchoStringToByteServiceResult");

	var byteArray:ByteArray;

	byteArray = evt.result as ByteArray;

	// both the readUTFBytes() and toString() methods give return you the string
	trace("onEchoStringToByteServiceResult readUTFBytes = " + byteArray.readUTFBytes(byteArray.bytesAvailable));
	trace("onEchoStringToByteServiceResult toString = " + byteArray.toString());

	this.echoServiceResultText.text = byteArray.readUTFBytes(byteArray.bytesAvailable);
}

private function onEchoStringToByteServiceFault(evt:FaultEvent):void
{
	trace("onEchoStringToByteServiceFault");
}

In order to run this you’ll need to:

  • Copy and paste the ActionScript listed above into a Flex Application tat calls the init() method on creationComplete.
  • Have BlazeDS or LCDS running on a server (as you can see in the definition of my RemoteObject in Flex I created a small Java web-app with a context root of /bds).
  • Configure remoting-config.xml by adding in the following destination node listed below.
<destination id="echoService">
	<properties>
		<source>com.wasi.services.test.EchoService</source>
		<scope>application</scope>
	</properties>
</destination>

NOTE: I removed a couple things for clarity and this code has not been retested to verify that it still runs, but you should get the idea.

Post to Twitter Tweet This Post

2 Comments

Flex Compile Error 1195

This was a simple issue that gave me a 5 minute headache b/c the error wasn’t clear enough, so I thought I’d share..if you ever run into the following Flex Compiler error:

1195 Attempted access of inaccessible method <methodName> through a reference with static type <fullQualifiedClass>.

…maybe you did what I did and changed a public function to a public set function, but forgot to change the implementation where you used it…so my interface was originally:

public function bar(str:String):void;

and then I changed the bar method to a setter method like this:

public function set bar(str:String):void;

so I also needed to change my implementation of that method from:

foo.bar("str");

to

foo.bar = "str";

…a simple mistake that led me to a slightly convoluted error that I hope helps someone else.

Post to Twitter Tweet This Post

No Comments

Apple Rocks!!!

…and here’s why.

So my iPhone’s home key has been sticky/non-functional for the last month or so…and my MBP’s open apple key cracked in 1/2…and my Mighty Mouse scroll wheel was not really working…so I went to the Apple Store and sat with the Genius Bar Doods, aka the tech guys for Apple, and here’s how it played out <=5 mins after starting my convo with the Genius Bar:

  1. Here’s a new iPhone sir…no questions asked…seriously, that’s what they did…that’s $300 bucks.
  2. Here’s a new key for your keyboard sir…lemme just…snap…ok, good as new.
  3. Here’s your Mighty Mouse all fixed…it feels as good as new.

All done inside of 1/2 hr at the Apple Store…I haven’t had that kind of service in years…Genius Bar Guy Jared and Personal Shopper Sarah, you guys are awesome! And three different Apple Employees said my “Boston Flex Camp” shirt rocked…come on…really, where the hell am I???

Oh, and b/c iTunes backs up every part of your iPhone, my new one now has everything my old one did in < 5 mins of being home…from the the layout of my apps to the 5 different alarm clocks to all the text message convos…all restored…so impressed!

I am proud to be an Apple g33k. ;-)

Post to Twitter Tweet This Post

No Comments

Set MAVEN_OPTS For All Terminal Sessions

I was just exporting the MAVEN_OPTS var before I ran any maven command, but then I decided to just stick it in my terminal session’s profile (thanks to quick tip from my buddy Jon Marston) — you can do this 2 ways on your mac:

1) Open Profile in Finder

  1. Open Finder
  2. Locate and open the file /etc/profile — that’s in your root hard drive, in the folder etc.
  3. At the end of the file, drop in the following line:

    export MAVEN_OPTS=-Xmx1024m

2) Open Terminal and Edit the Profile

  1. Open Terminal
  2. Enter in the following command:

    sudo nano /etc/profile

    This basically says that as a super user I want to edit the profile file in a poor man’s vi-like text editor — good phrase Marston.

  3. You’ll be asked for the super user’s password — if it’s your box then you know this — enter it and it’ll open profile.
  4. At the end of the file, drop in the following line:

    export MAVEN_OPTS=-Xmx1024m

  5. Hit CTRL + X to exit
  6. It’ll ask if you want to save, so hit Y.

DONE.

Post to Twitter Tweet This Post

No Comments

Maven2 Install Error: java.lang.OutOfMemoryError: Java heap space

If you ever run the maven command “maven install” and you run into the following error:

[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Java heap space
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.OutOfMemoryError: Java heap space

Try setting the MAVEN_OPTS memory to a larger max; eg:

Last login: Wed Jul  1 12:33:56 on ttys000
brian-rileys-macbook-pro:~ brianmriley$ export MAVEN_OPTS=-Xmx1024m
brian-rileys-macbook-pro:~ brianmriley$ cd /Users/brianmriley/projects/spring-hibernate/workspaces/emp-mgmt-console/SpringActionscript/trunk/core
brian-rileys-macbook-pro:core brianmriley$ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring ActionScript
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
...
[INFO] Installing /Users/brianmriley/projects/spring-hibernate/workspaces/emp-mgmt-console/SpringActionscript/trunk/core/target/spring-actionscript-0.8-SNAPSHOT.swc to /Users/brianmriley/.m2/repository/org/springextensions/spring-actionscript/0.8-SNAPSHOT/spring-actionscript-0.8-SNAPSHOT.swc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33 seconds
[INFO] Finished at: Wed Jul 01 14:58:34 EDT 2009
[INFO] Final Memory: 26M/115M
[INFO] ------------------------------------------------------------------------

Just keep in mind this is a one time dealio and you’ll have to set this each time you run a maven install.

Post to Twitter Tweet This Post

, , , , , ,

1 Comment