Create a Windows Service for Flex Server

There are many reasons why you may want to add a JRun server instance to the Windows Services panel. I”ve found that its very handy on production machines in a cluster. If one fails, it recovers nicely without me having to help. Here is how I do it.

JRun provides an executable for managing its server instances called jrunsvc.exe. You can find it in the jrun_install_root\bin directory. Open a command line window to this directory and execute jrunsvc along with some of these options:

-install jrun_server [service-name [service-display [service-description]]]
Installs the JRun server as a Windows service. The Windows service name, Windows service display name, and Windows service description fields are optional. If a name contains spaces, use quotation marks.
The Mask:jrunsvc -install server_name “service display name” “service description”

The Example:

jrunsvc -install flexsamples “Flex Sample Applications Server” “Flex Samples”

-remove service-name
Removes the named Windows service, if you installed it using this utility. You can mark the service for deletion on system start.
-stop service-name
Starts the named service, if it is not already started.
-start service-name
Stops the named service, if it has started.

-console service-name
Runs the service from the console rather than from the Windows service Control Manager. Use this option for debugging.
-config path-to-jvm.config
Specifies a path to the JVM configuration file used by the Windows service.
Overrides the default, jrun_root\bin\jvm.config, to determine the JVM configuration.
Lists all options.

This table is from the JRun Documentation with some modifications.

That is it! Now, when ever the server is restarted, the necessary Flex servers will start as well.


Dynamic FlashPaper

I was recently trying to create a document collaboration tool for one of my clients. In order to make it a bit easier for the user, I decided I would use FlashPaper to display the uploaded documents they are discussing. It took a couple of hours to figure it out but its pretty simple in the end.

First, you have to have the FlashPaperConnect .dll. Contribute 3, and some other products comes with the FlashPaperConnect .dll that makes it all possible. Contribute also registers the dll on your system, so all you do is CFOBJECT the FlashPaperConnect2.object.2 component.

Like so:

<cfobject type="com" name="FlashPaper" class="FlashPaperConnect2.object.2" action="create">

The method you need to call is BeginConversion(). Its arguments are the source file, destination file; include outline; paper size; and something else. I”m still looking for documentation on this and if it violates the EULA. But until then…

<cfset FlashPaper.BeginConversion(''c:\temp\doc1.doc'',''c:\temp\doc1.swf'',0,210,297)

This seems to work.

Good luck.


Using useHandCursor in Flex

While working on a recent Flex project I found a code sample that someone created because they were having trouble getting the useHandCursor to work. It was pretty obvious what they were trying to do, take a look:

<mx:Canvas width="176" height="87">
<mx:Link height="100%" width="100%" />
<mx:Image width="100%" height="100%"
mouseDown="doThis()" />

They obviously wanted to call an event handler when someone clicked on the image, but because they couldn”t get useHandCursor to work, they used an alternative method, albeit not all that pretty.

The solution is rather simple though. Just add a mouseOver event to the component and set it to the following:


Works pretty much anywhere.

UPDATED For Flex 2:

You may have noticed that the above does not work in Flex 2. This process has been replaced. It is now done through a set of properties that are inherited from the Sprite class.


Add these properties to your component and you”re all set. Now, that was easy!


Local SharedObject

“When you create a SharedObject, Macromedia Flash Player creates a new directory for the application and domain, and creates an empty *.sol file that stores the SharedObject data. The default location of this file is in a subdirectory of the user”s home directory; for example: c:/Documents and Settings/username/Application Data/Macromedia/Flash Player/web_domain/lso.mxml.swf/. While usually predictable, the location of the StoredObject file can be anywhere that Flash Player has access to within its sandbox and can have any name that Flash Player assigns to it.

By default, Flash can save locally persistent SharedObjects of up to 100K in size. When you try to save a larger set of data, Flash Player displays the Local Storage dialog box, which lets the user allow or deny local storage for the domain that is requesting access.”


Dynamically adding to a Model

One limitation of the Model tag is that if you supply one instance of a child tag in an <mx:Model> tag, there is no way for Flex to know if you intend it to be an array or a single property instance. You can work around this limitation by using an <mx:Object> tag instead of an <mx:Model> tag and declaring an <mx:Array> tag inside the <mx:Object> tag. As an added benefit, you can then dynamically add to the object creating an array of objects.

Here”s the sample code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">

public var count:Number = 0;

public function addToModel():Void
var newRecord:Object = new Object();
newRecord.name = "Toby";
newRecord.sign = "Leo";
newRecord.birthYear = "1984";
test[ count++ ] = newRecord;

<mx:Object id="test"/>

<mx:Button label="Add" click="addToModel()"/>



Using Eclipse for Flex 1.5 Development

So you want to use Eclipse to do Flex 1.5 development? No fluff, I”ll get right to it.

What you are going to do is use the Flex 2 alpha and point it to the Flex 1.5 compiler. This will compile your application into a SWF, which will be put in your web site.

  • Start with getting the Flex 2 alpha plug-in (either stand alone or plug-in). Follow the installation instructions, if necessary, to get Flex Builder 2 running. Once it is working, create a new Flex Project using the menu bar: File > New > Flex Project
  • Now for the changes. Right-click the project that will use the Flex 1.5 compiler and select Properties. This will open the Properties dialog. In the list on of properties on the left hand side, select Builders. You are going to add a new builder and disable the existing one. When you deselect the existing ”Flex Builder” builder you will get a prompt. Just click OK.
  • Click the New button to create a new builder. The configuration chooser dialog will open. Select Program and click OK.
  • Now you are ready to set the new builder up. Give it a name like ”Flex 1.5”.
  • Set the Location to point to the mxmlc.exe file, most likely something like this: C:\Program Files\Macromedia\Flex\bin\mxmlc.exe
  • Set the Working Directory to point to the directory holding the compiler. Something like this: C:\Program Files\Macromedia\Flex\bin\
  • And now the hard part… the arguments. Click the variables button and select the project_loc variable. This is an eclispe variable which has the absolute file system path for the project. Double-click project_loc to select that variable and close the dialog. Now append to the end of the variable the path to the main application mxml for the project. Something like this: ${project_loc}\Main.mxml
  • You need to add two more arguments; one that points to the flex-config.xml, and an output file. To do so, you will add the -configuration switch and the -o output file switch. They will look something like this: -configuration ${project_loc}\WEB-INF\flex\flex-config.xml -o C:\inetpub\wwwroot\mysite\Main.swf

In the end the arguments will look something like this: ${project_loc}\Main.mxml  -configuration ${project_loc}\WEB-INF\flex\flex-config.xml -o C:\inetpub\wwwroot\mysite\Main.swf

  • One last thing I would do is run your application the old way and copy the source HTML from a dynamically created Flex site (i.e. view source from the browser). Then create a new HTML page with the HTML source you copied. Finally, change the references to the [filename].mxml.swf to your new SWF ([filename].swf)

That”s it!

Thanks again to Marcin, Sean and Tony for sharing with me.


Creating your own Flex component

Adobe Flex is composed of two distinct pieces; a set of pre-built components known as the client-side framework, and a set of runtime services that allow Flex applications to integrate with back-end systems. The client-side framework is a series of ActionScript class that you utilize in MXML or ActionScript. Did you know that you can create your own ActionScript classes and reference them the same way? Remember, MXML is just short-hand notation for ActionScript.

Start by creating an ActionScript class that extends the Flex Panel component.

// Import the client-side framework components needed
// The .* is a wildcard that will only import classes that are needed.
import mx.containers.*;
class compClassXPanel extends Panel
public function compClassXPanel() {}
public function init():void {}

Next, create a component that uses this class as it’s root node:

<?xml version="1.0" encoding="utf-8"?>
<compClassXPanel xmlns="*" width="400" height="400">

Finally, create your main application that invokes your custom component:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
<myComponent />

Now, this is a very simple example of how you can do this. You would normally continue to build upon your extended class. The point is that your classes are really not that different from the client-side framework.


Feelin’ the Love From Your Logs

I recently had some datasource issues that I was able to figure out with a bit more feedback from the JRun logs.

First, for those of you who are not system admins, make sure you make a copy of the files before you modify them.

Now, there are a couple of XML files that you can modify that will provide a lot more detail of what is going on.

The CF datasources are stored in the jrun-resources.xml file located in {CFMX install}runtimeserversdefaultSERVER-INF. Locate the datasource in question and change the debugging node (<debugging>false</debugging>) of that element from false to true. This will tell JRun to log more information about this resource. Note: there a lot of other options available several of which you can equate to datasource options in the CF Admin.

Next, we want to modify the the actual logging service. You can do this with the jrun.xml file located in the same directory as jrun-resources.xml above.
Find the LoggerService in the jrun.xml file. Set the following two entries to “true”:
<attribute name=”debugEnabled”>false</attribute>
<attribute name=”metricsEnabled”>false</attribute>

A few lines down from these entries, you can separate the logs into separate files by making the following change:

<attribute name="filename">{jrun.rootdir}/logs/{jrun.server.name}-event.log</attribute>


<attribute name="filename">{jrun.rootdir}/logs/{jrun.server.name}-{log.level}</attribute>

By changing “event.log” to “{log.level}” it will create separate log files for each type of event. This allows you to narrow in on suspected problems a bit easier.

Finally, the logs produced can be found in {CFMX install}runtimelogs. Note: You will want to reverse these changes because they do cause a bit of overhead on the server.


CFFunction Tip

Extra white space can be a problem for some in ColdFusion. If you are creating ColdFusion Components (CFC) or User Defined Functions (UDF) then there is an attribute to the CFFUNCTION tag that can help.

The OUTPUT Attribute: You should add the attribute output=”no” to the CFFUNCTION tags in your CFC/UDF when it is not rendering display text. This will make it work like CFSILENT, when set to “yes” its like CFOUTPUT.

Note: CFSILENT suppresses all output that is produced by the CFML within the tag’s scope.