Tag Archives: flex

Use unique IDs to identify objects in Flex

In our application, sometimes we need to keep the same object in several different places. Of course, we can create our own logic to produce a unique id for each objects. But Flex has contained a convinient way for us to complete this type of task.

First of all, we need to implement the mx.core.IUID interface, and then, we can use mx.core.UIDUtil.createUID function to generate the unique id for our object in our class’s constructor. This method will create a 32 bit hex string like:

E4509FFA-3E61-A17B-E08A-705DA2C25D1C

Here is the example:

package {
import mx.core.IUID;
import mx.utils.UIDUtil;
[Bindable]
public class Message implements IUID {
public var messageStr:String;
public var fromID:String;
private var _uid:String;
public function Message() {
_uid = UIDUtil.createUID();
}
public function get uid():String {
return _uid;
}
public function set uid(value:String):void {
// Since we'vealreadycreatedtheid,there's
//nothing to be done here, but the method is
//required by the IUID interface
}
}
}

An email from a stranger

Today I got an email from a stranger. The email’s content was not long. It was a question, or to put it better, it’s a request. It was about my new project I created a few days ago. Yeah, bluewolf-flex, which I introduced in my former post.

The question was ask me to give him some example code on how to use the library. Absolutely, it’s my negligence. Because the project is still in it’s process of the first stable version, and also this is my first open source project. I haven’t any experience on it. My thought was to upload the sample application after finishing the first stable version. But it seems to late. The project is available for everyone everywhere. So all useful information should be given with the source code at the same time. I’ll improve my work in the future development procedure.

At the end, I want to say thanks to the sender of this email. His mail not only let me know the things I mentioned above, but also encourage me at all. For the reason he is the first user of my library. From now on, I’m not only develop this project for myself. I should make it useful to as many people as I can.

Bluewolf-Flex library

Bluewolf-flex is a library based on Adobe Flex 4 framework. I created it because I want to abstract some common functions into a library which contains a set of tools to solve some problems I met in my work.

I created the project on google code, you can get more information on

http://bluewolf-flex.googlecode.com

The first goal of this project is to build some components for drawing topological diagrams. The library has finished the following functions at the moment:

  1. Add nodes and links in diagrams
  2. Drag and drop nodes
  3. Layout objects in different layers, show several layers in one diagram
  4. Group objects, show grouped objects in different colors’ borders

I will update the development process in this blog regularly. And I appretiate for any kinds of contribution to this project. If you are interested in this project and willing to contribute, please leave a message for me.

Flex 4: Drag components in a nested Group container

I met a problem in my development of a Flex library recently. The library is a set of components for drawing topological diagram. My problem was that I can’t drag and drop a component in a Group container which was nested in anthor one. This made me feel headache for two days on this odd behaviour, even it worked fine if a use BorderContainer instead of Group. I searched in google about it, but no good news.

I have to start a discussion on a Chinese forum to discus with that, and no good luck, too. At last, I asked that question on Adobe Flex forum. After one day waiting, someone replied my post, he let me try to listen the dragEnter and dragDrop events in the parent Group container, not to listen them in the nested one. I followed his advice and modified my code. It worked. I could drag and drop components in a nested Group container, that was just what I want. I want to appreciate that guy again here. He really did me a great favour.

CSS in Flex 4

I’m using Flex 4 to upgrade a project in my work these days. Cause I have used Flex 3 for a long time in developing, Flex 4 really set a huge gap for me to adapt it immediately. I will write some articles about it in my learning progress.

First, I’ll record something about CSS in Flex 4 that I met in work. In Flex 4, We must declare namespaces if you want to customize the look of the Spark and Halo components like

@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/halo";

Now I can set a style of the component by prefix “s” or “mx”, The following style set the font color of  TextInput:

s|TextInput {
	color: #000000;
}

After then, I’ll talk about the validators’ error tip style, We can set the errorTip style like

.errorTip {
	fontSize: 12;
}

This set the error tips’ font size to 12.

OK, I’ll post some new articles about my experience on learning Flex 4 in the near future. If I make some mistakes or you have something to discus with me, please let me know.