June 5, 2007

Interesting technique for modifying internal Flex code

You can do this in Ruby, and there is some argument whether it is a good thing to be able to do (in terms of readability, comprehensibility).  You can override an existing method w/your own   (I forget what the term is, right now, mainly because I never use it).  Ruby on Rails takes full advantage of this.

Apparently, you can do the same thing in Flex, for the internal functions/capabilities of the MX Controls.

Void where prohibited, your mileage may vary, etc.

May 2, 2007

Optimizations in ActionScript 3

Daniel Hai provides a bunch of techniques to improve the speed of certain common actions in ActionScript 3. None of them were screaming at me to implement forthwith, but they are worth reading and being familiar with in case you’ll need them in the future.

February 1, 2007

Flex vs Javascript

I’ve been looking at 9 things you may not know about javaScript, and I thought it would be interesting (where appropriate) to see if ActionScript 3.0 shows the same behavior (where appropriate)

  1. (Binary Trees) - nothing to add here
  2. (Concat Performance) - counterintuitively, ActionScript is almost twice as fast with concatenation as it is with Array.join
  3. (Binding Objects To Methods) - works exactly the same in AS3 as JavaScript
  4. (Custom Sort Functions) - works exactly the same way in AS3 as JavaScript
  5. (AssertException) - similar. I created a seperate class, for clarity, and when you throw the exception it pops a message up on top of the app, which can be disruptive if you’re in production. I suppose you could turn off that behavior in production.
  6. (Static Variables) - ActionScript 3 has native support for static variables
  7. (Undefined, Null and Delete) - slight behavior change here. delete seems to remove a property, and both Alert.show() and Text.text reveal it as blank, instead of undefined.
  8. (Deep Nesting) - this one was the most significant difference - because everything in ActionScript3 is strongly typed, you can’t link a String to a TextInput.text element, for example. However, you can link objects to each other. For example:

if I have a Form a, with a FormItem b, and a TextInput c

I can do this:var linkTextInput:TextInput = c; // linkTextInput.text will always == c.text

But I can’t do this:

var textString:String = c.text; // if the user enters new text into c, textString will still contain the old text.

9. (FireBug) - there’s a built-in debugger in Flex, so none of this really applies.
Update: 2/2/07 - added #5, 6 and 7.

Update: 2/5/07 - added #8 and #9

January 31, 2007

Flex is the new Java?

Bruce Eckel wrote an interesting article on the shortcomings in Java, and how much he likes Flex as a platform for future app development.

I think he’s exactly right - Flex apps will run in browsers on all of the major operating systems, and there’s no reason they can’t run on the desktop using a runtime of some sort.   Other than 3d games and CAD rendering there are few applications that need direct access to the video card and the CPU.

If Flex does succeed here, it will represent the triumph of JavaScript over Java, Flash over HTML and Adobe over Sun.   Microsoft may have a response with Atlas, but unless Atlas is fully cross-platform, I’m not sure it’s going to win.

January 8, 2007

Java and Flex

Yakov Fain asks Should Java Developers Care About Flex?

Basically, this question could be re-phrased like this “Should I invest my time in learning this technology, are there any real (billable) projects going on in Flex?”, or like this: “I am a Java developer, and do not have too much time in my hands - do you recommend me learning Flex”…

We are using Flex, for a commercial product to be delivered later this year.  It will be B2B, it will run inside a browser, and it will be awesome.

The comments on this article are very amusing - Flash? How gauche! - the kind of elitist distaste that used to permeate the C++ crowd in 1995 when someone mentioned “java”

If I have the opportunity to choose between writing a front-end in Flex or HTML/JSP/JavaScript, I’ll generally prefer Flex.  It looks very nice, all of the animation and rich interactions are built-in (not assembled from a frankensteinian mess of JavaScript libraries), the language is generally compatible with JavaScript, which makes learning it easier, and it doesn’t have any cross-browser issues as far as I’m aware.

January 4, 2007

Propogating Events in Flex 2.0

It’s time for another JB explains how to solve a frustrating problem so you can find the answer on Google

Problem:

I’m writing a Flex 2.0 app, and I need to propogate an event from a low level class back to the top level app.

  1. I create a new Event subclass, and add a listener for the appropriate type in my app
  2. I set up a button so it fires the event.
  3. I run the app and click the button.
  4. Nothing happens

I sigh, and look at the Flex examples.  Right there, in the help/tutorials, they show how you can fire a MouseEvent and catch it, exactly how I want to do it.

  1. In a fit of inspiration, I change my custom event into a MouseEvent, leaving everything else unchanged
  2. It works!

Well, let’s try again with a plain vanilla Event.  No Joy.

Finally, in a fit of inspiration, I set up the debugger and inspect the contents of a regular Event and a MouseEvent.   Sure enough, in MouseEvent, bubbles == true.

  1. Curious, I modify the plain Vanilla event, and make sure that bubbles == true.
  2. It works

Ah hah! I update my custom event, set bubbles = true in the constructor, and put it back into the code.  Everything works.  Boo Yah.

The moral of the story:  Your event needs to set bubbles == true if you want to catch it in a separate class from where you fire it.
Note: I have no idea what the negative side effects of setting bubbles == true are.   But it seems to work well for what I need.

October 30, 2006

Flexifier

If you want to experiment with Flex, but don’t want to pay for the full Flex Builder, the Flexifier is a great way to experiment, debug and get your hands dirty in a simple, online form.

How do I know? Because I learned a bunch of interesting things about Laszlo using the same technique.

October 11, 2006

ActionScript vs. JavaScript

This page had 9 tips for improving your Javascript.
One of them struck me:

2. String Concatenation vs. Array.join

(Array.join is faster in Javascript)

Curious, I wrote a simple program to exercise the same functionality in ActionScript 3.

It turns out that the opposite is true. For the test I did, concatenanting 100,000 strings together, String concatenation was 3x faster than Array.join

September 29, 2006

Flickr on Flex - A tutorial

I couldn’t get it to work right with the Wordpress editor, so I wrote it on a standalone web page.

A tutorial on using the Flickr API with Flex 2.0

September 28, 2006

Flex and Flickr

So I sat down last night, and tried to learn the Flex library for building Flickr apps. (You can find the libraries at labs.adobe.com)

Good News

I was eventually able to get it to work.

Bad News

It took a long time to debug the library enough to make it work. I don’t think it’s been updated recently. I thought I would post this, in a hope that someone somewhere will find it, and it will help them avoid some of the problems that I had.

The Adventure

The Flickr library is dependent on the corelib, and you need to download both. Make sure you download the source - you’re going to need it!

You will also need a Flickr API key, which you can get from Flickr by logging in (create an account if you need to) and going here: http://www.flickr.com/services/ - to apply for a key.
Here’s what I discovered:

  • You can’t use the flickr.swc - you must either include the flickr api source code in your app, or recompile the flickr.swc file for yourself. I did the former.
  • You have to include the flickr api source code at the right directory - src/trunk/src/actionscript3
  • As a starting point for understanding how the Flickr api works, there are no tutorials. However, there is a manual test - src/trunk/tests/ManualFlickrTest/ManualFlickrTest.mxml
    • Note that it doesn’t work as is - you have to edit the code in a couple of places (see below)
  • You need to make several changes to the existing Flickr code:
    • src\trunk\src\actionscript3\com\adobe\webapis\flickr\FlickrService.as - you must change the two END_POINT urls - they need to be api.flickr.com, not just ‘flickr.com’ (I’ll explain why at the end)
    • src\trunk\src\actionscript3\com\adobe\webapis\flickr\methodgroups\Auth.as - you must change the checkToken function - where it says ‘false’ on line three of the MethodGroupHelper call, it needs to be ‘true’.
    • src\trunk\tests\ManualFlickrTest\ManualFlickrTest.mxml - In a couple of places (getFrobResponse & getTokenResponse), listeners attempts to get data directly from event.data. But you can’t. You have to get data from event.data.frob and event.data.auth, respectively.
  • If you try to test out ManualFlickrTest, be aware that it has hardcoded values for all of the parameters - so if you’re trying to use the API, it will probably return the wrong results until you go into the code and fix it.
  • And, here’s the punchline - this whole app is a big security hole, because you have to include your secret Flickr API key. That key lets a clever hacker pretty much do anything to your flickr account except change your password. So you can’t really put apps out there for public consumption.
    • I have a theoretical fix in mind for this problem, but it will take some time to write it. In the meantime, just beware!

Here’s the updated source code for the Flickr API for Flex

August 13, 2006

Flex - Separating Content from Code

I’m likely to be doing more Flex programming in the relatively near future, so I’m gathering interesting posts.

http://www.zeuslabs.us/archives/87/separating-layout-from-style-and-functionality/

My only problem with this example (and it is primarily because it is just an example) is that it makes it much harder to see the direct consequence of an action - you have to go hunting for it - the button and its clickAction are loosely coupled, which is a good thing in many cases, but harder to understand when you’re trying to support or maintain.

I suspect that better naming strategies would help here.  And certainly I’m not blaming the author of the post - he was focused on demonstrating separation, not maintainability.

May 25, 2006

Base64 Encoding for ActionScript 3/Flex 2.0

I updated this Base64 Encoder to work with ActionScript 3 for Flex 2.0 Beta 3.

New version:  Base64.zip

Also, there’s this version, which is binary data oriented:

Note that I’ve only done rudimentary testing with these.   It may not work perfectly.

April 19, 2006

Flex and Ruby On Rails

Someone stole my idea to build an app combining the eye-candy of Flex with the web-dev coolness of Rails.

Actually, I’m happy someone else did this, since I don’t have the spare time to work on this with all my other projects.

The tutorial is very well written. I will enjoy looking at it with more leisure when I get a chance.

*Update* - changed the URL to point to the new location of the project.

March 29, 2006

Adventures in Flex 2

Over the last month I’ve had to put OpenLaszlo away, and adopt Flex 2 as my RIA platform.

I would have preferred to stay with Laszlo, but I’ve discovered that the way that Laszlo manages data sources seems fundamentally broken, forcing one to build applications instead of frameworks, and limit reuse. I may be wrong, it may turn out that you can “alias” datasources in a standard way, but I was not able to find it.

But enough about Laszlo. Now it is time to complain about Flex!

Bug: Selection Highlight bar on my DataGrid is stuck at the bottom of the list

Description:

  • Create an Array of custom objects - for example, Alerts (your definition) , and make that array the dataprovider for a DataGrid control
  • Show it on the screen. Verify that the blue highlight bar is stuck to the bottom element in the list

Resolution:

  • In order for the DataGrid or other list-style component to do highlighting properly, the objects in the Array need to implement the IUID interface. Using ObjectProxy, here’s an easy way to do that:
public function addAlert( alert:Alert,
array:ArrayCollection):void
{
array.addItem( new ObjectProxy( alert ));
}

Now, your list should highlight properly.