Showing posts with label Flex. Show all posts
Showing posts with label Flex. Show all posts

Flex Object

setter:
var obj:Object = new Object();
obj.name="test";

getter:
var name:String = obj[name];

Why can't we just call obj.name to get the value? You could only if you could directly use the property name onto the object. You could not do like the following:

var key:String = "name";
var nameValue=obj.key; //this will not work
var nameValue2=obj.name; //this will work

The only way you could do is through []

var nameValue3=obj[key]; //this will work, and recommended

We could actually take property_name == ["property_name"].

Conversion between Java object and Flex object:

Objects are serialized using Java bean introspection rules and also include public fields. Fields that are static, transient, or nonpublic, as well as bean properties that are nonpublic or static, are excluded.

So only public-non-static fields will be transferred to Flex object.

Using DropBox to Host Your Code

I wrote some Flex applications, and would like to post them into my Blog. First, I tried to use Google Docs, there is no problem to upload the folder, but Google Docs seems not let you have the link to the file. Then I tried DropBox's Public folder, wow, it's unbelievably easy, just drag and drop the release version of the Flex application to Public folder, then select the main html file, and right click, DropBox->Copy Public Link, now you have the web link to that file.

Next, just copy the following to my blog, and I am all set.

Get current user name in Flex

package
{
    import flash.filesystem.File;

    public class UserUtil
    {
        public static function get currentOSUser():String
        {
            var userDir:String = File.userDirectory.nativePath;
            var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1);
            return userName;
        }
    }
}

Init with Array or ArrayCollection

I am trying to use repeater to create a set of checkbox, at first, I am trying to use Array as repeater's data provider. If the array is hard coded, it works, but if I initialized the data for the array in init() method, it will not work. I changed the array to array collection, and it magically works!!!

That's quite strange...

Flex Style Explorer

http://examples.adobe.com/flex3/consulting/styleexplorer/Flex3StyleExplorer.html#

Get key/value from Flex Object

Ok, so we got a Flex object, let's suppose it's a map object, how could we retrieve the key/value from it?
//retrieve keys
for (var key:String in obj) 
{
   trace(key);
}

//retrieve values
for each(var value:String in obj) 
{
   trace(value);
}

The for..in loop iterates through the properties of an object, or the elements of an array. For example, you can use a for..in loop to iterate through the properties of a generic object (object properties are not kept in any particular order, so properties may appear in a seemingly random order):

The for each..in loop iterates through the items of a collection, which can be tags in an XML or XMLList object, the values held by object properties, or the elements of an array. For example, as the following excerpt shows, you can use a for each..in loop to iterate through the properties of a generic object, but unlike the for..in loop, the iterator variable in a for each..in loop contains the value held by the property instead of the name of the property:

Print out object in Flex

In Flex, object could be a lot of things, check here, you can see a flex object could be a Java map or dictionary. To check out its content could be really desirable, here is a useful function:
import mx.utils.ObjectUtil;

trace(ObjectUtil.toString(obj));
This will print out the content of the object very neatly.

Debugger Version of Flash Player + trace()

Recently I am working on a Flex project, and found that trace() is not working. Trace() method is equivalent of System.out.println() at Java, without making it work, it's a huge blow to debug on Flex. After some search, here are my foundings:

1. You need make sure your web browser has a debugger version of Flash Player.
Go to here, if you see "Debugger version of Flash Player", congratulations, otherwise, you need go to here to download a debugger version, be aware that Chrome has a build-in flash player, but it's not a debugger version, I have not figured out how to install a debugger version in Chrome yet, but here is a link which might help.
2. You need run your web server in debug mode.
3. You need invoke the web application from Eclipse's debug mode.

After that, trace() will print out whatever you want to see beautifully in your console.

---Update:
Sometimes, you need uninstall your current non-debugger version first before installing debugger version:

http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-windows.html

Create war file for Flex/Java project

SpringSource Tool Suite
File->Export->Web (War File)


Spring Roo and Spring Flex Addon

According to link, there are 2 combinations that are working so far.

a. Spring-flex-1.5.0.M1 release (org.springframework.flex.roo.addon-1.0.0.M1.jar) is only compatible with spring-roo-1.1.0.M1 and STS 2.3.3.M1.
b. There is a patch (org.springframework.flex.roo.addon-1.0.0.BUILD-20110219.075648-225.jar), which will work with Spring-roo-1.1.1.Release.

Spring-flex-1.5.0.M1 release is the only release so far which contains Spring Flex Addon.
The good thing is the latest STS (Version: 2.6.0.RELEASE) is compatible with Spring-roo-1.1.1.Release, this will give us all the three featrues:
a. the most updated STS
b. Spring Roo
c. Flex Addon for Spring Roo

Be noted, if you want to option b, which probably most of us will do, you need manually add the following lines to pom.xml
Introducint Flex Addon for Spring Roo
Flex Spring Forum
STS with Flash Builder Plugin
Getting Started With Spring Roo

Flex XML

Here is what I have

xml  
      Date   
    2010-10-15 
 /Date  
Number
       1000 
 /Number
 xml

The question is how can I get the vale of Date and Number?

if myXML is used to refer to the above XML

var strDate:String = myXML.Date[0].toString();
var strNumber:String = myXML.Number[0].toString();

Flex eventhandler mode

This weekend, I have a problem with Flex, to say specifically, with Flex's Event Handle mode.

Here is my situation, I need loop through SP500 symbols, and send the url to Yahoo web site to get some data.

When I sent a query, it will take some time to get the data back, the way Flex handles this is using Event Handler. It will add a listener to URLStream object, which will listen to complete event. When the stream is done loading, URLStream will be notified, and will proceed to do something else, like put the stream into database.

Now I got problems at the hand. You see, sending query and loading stream is separated, they are not in liner relationship. What will happen is you will send 500 queries to Yahoo server, then you wait for the data coming back to you one by one, not necessarily in the sending order.

First problem is, because I send the 500 queries together, Yahoo decides not like it, and I will get some timeout error.

Second problem is, when the data comes back, I need know the data is for which symbol, so I need pass the symbol to the complete event handler, fortunately, I found some solution:

urlStream.addEventListener(Event.COMPLETE, function(e:Event):void{loadedEventHandler(e, symbol);});

You see, that let me pass symbol to complete event handler.

addEventLister's signiture is (Event.COMPLETE, eventHandlerFunctionName:String)

But the eventHandlerFunction has to be like functionName(e:Event), so my own's event handler doesn't qualify the signature.

what this does, add a more standard event handler above my own event handler, then call my own event handler.

This resolve the problem, but the first problem is hard to resolve, eventually, I have to use Java to do what I want to do.

Flex 4, Air 2, and others

From last night, I started writing a Flex program. Here is what it does:
1. open a .xls file and show it in datagrid.
2. search by column, type as change.
3. Open the changed datagrid in new .xls file.

It's pretty neat, would be very useful to process a large .xsl file.

But then I found it's not that useful because Excel could do basically everything it does. Kind of frustrated a little bit, but then I realize that it's not that bad, after I jsut re-picked up what I left about a year ago. After all, I start using Flash Builder 4, Flex 4 API, AIR 2 API, refresh some of my knowledge on Flex, like layout, HGroup(HBox), VGroup (VBox), ArrayCollection, Column list, ComboBox, Filter function....and also how to release a project.

So, it's good.