Creating Your First Custom SkinnableComponent in Flex 4

July 19th, 2008

It took me a couple of days to get to my next Flex 4 example, but here we finally are. I wanted to try making a component which had optional SkinParts, so I came up with the following example (get the source). For those who don’t know, Flex 4 targets Flash Player 10 so you’ll need that in order to run the SWF.

In this example we will build a component called QuestionAndAnswer which will include a text field containing a question, a check box, and a text field containing an answer to the question. The check box and answer are both optional, so if the Skin file doesn’t include those SkinParts, they won’t be a part of the view. If they are included, then clicking the check box will show the text field containing the answer. Let’s see what the code looks like.

Read the rest of this entry »

Creating a Custom Layout Class in Flex 4

July 16th, 2008

So apparently I’m giving a week long series on getting started with Flex 4. I would have titled my content as such, but I guess I wasn’t sure if I would have learned enough to provide a week’s worth of content. Let’s give it a shot anyway.

As I briefly touched upon in yesterday’s post, layout is handled in new layout classes in Flex 4. Let’s dive in to making a simple, custom layout manager.

Read the rest of this entry »

Skinning A Button in Flex 4 Using FXG

July 16th, 2008

In yesterday’s post I walked through how I got the Flex 4 SDK setup, compiled, and ran the first Hello World application in Flex 4. I said I would follow up today with skinning a Button using the new declarative graphics tags known as FXG (previously referred to as MXML-G), so here we are.

Today I want to explore using the new layout property as well as using a Skin file to describe how the button should look. Let’s get started…

Read the rest of this entry »

Compiling Your First Flex 4 Application

July 15th, 2008

Big news today in the world of Flex! The first push of the Flex 4 source was made this afternoon (and another push was made this evening). Additionally, a lot of documentation was added to the Adobe Open Source site regarding Flex 4 (code-named “Gumbo”). Reading through the Architecture Whitepaper will leave you with a great handle around where things stand and the current direction Flex is headed.

To reward myself for reading through all of those docs this evening, I decided it would be appropriate to try to test out the new code and make my first Flex 4 application…

Read the rest of this entry »

Problems with restful_authentication Plugin and Internet Explorer Cookies

July 11th, 2008

I just ran into a fairly obscure bug. Bit me pretty good and stole an hour from me on an otherwise quiet Friday afternoon.

How the Problem Manifested Itself: Using restful_authentication, I could log in fine using Firefox and Opera, but not Internet Explorer or Safari. I figured, it’s just an HTML POST, nothing special, so what could be going wrong? I started to tail my logfile, and the session#create action was working properly. It was redirecting to a protected page, signifying that the login was successful. However, there was a second redirect occurring immediately after, sending me back to the login page. Here’s a tail of the logfile:

Read the rest of this entry »

Losing Data When Drag and Dropping Custom Classes in Flex?

July 11th, 2008

One of our developers recently encountered some strange behavior when he was dragging a piece of data (which was a custom class) from a TileList and dropping it into a List, but losing some pieces of the dragged data when it was dropped into the List. I discovered the root of the issue by delving into the source for the dragDropHandler function within ListBase

Read the rest of this entry »

Merging a :has_many relationship into one instance

July 10th, 2008

So the problem is that I have an ActiveRecord model that has a :has_many relationship to another model (we’ll call this one object), but when I am in the view context I didn’t want to have to loop through the object each time to determine which data was being displayed. Object has many attributes (approximately 30) and many are often null for a given instance. So I decided to add a method to my model to loop through all of objects and determine which data should be included. Pretty much the rule was that if there was no data for a particular attribute temporarily save it to a copy of the object and then return that. This is what I came up with.

  def object
    tmp = objects.first
    objects.each {|o| tmp.attributes.each {|key, value| tmp[key] = o[key] if value.blank? && key != 'id'}}
    tmp.freeze
  end

However there was a flaw here. Every time I would view the page all of the data in the objects was getting overwritten with one copy of it. After banging my head on the desk it was realized that tmp[key] = o[key] was actually writing the changes to the database permanently rewriting all of the objects (which still seems counter intuitive to me, because it seems like only the first record should have been the one changing). But the solution was pretty simple. The working method is as follows.

  def object
    tmp = Object.new
    objects.each {|o| tmp.attributes.each {|key, value| tmp[key] = o[key] if value.blank? && key != 'id'}}
    tmp.freeze
  end

Reading and replacing text in Word DocX and Excel XlsX documents using Ruby

July 9th, 2008

So as you may know. The new Word and Excel formats are similar to open office document formats in that they are just zips of multiple xml documents (well mostly xml documents). So what we wanted to do for our project (the WebDav one mentioned in my last post) is to set up a simple templating system that would do variable replacement in Word/Excel documents. And it turned out to be a piece of cake. I am just going to go through the DocX version of template model, but the only difference between them is the folder structure so there is not too much to change to get this working for both.

Read the rest of this entry »

I can’t upgrade RubyGems from 1.1.1 to 1.2.0 on Ubuntu

July 7th, 2008

Just a quick little snippet here. RubyGems 1.2.0 dropped roughly two weeks ago….however, I’d been having trouble getting my 1.1.1 installs on Ubuntu to update properly.

john@john-ubuntu:~/passenger-recipes$ gem -v
1.1.1
john@john-ubuntu:~/passenger-recipes$ sudo gem update --system
Updating RubyGems
Nothing to update
john@john-ubuntu:~/passenger-recipes$ gem -v
1.1.1
john@john-ubuntu:~/passenger-recipes$ sudo gem update --system
Updating RubyGems
Nothing to update

The first few times I ran into this, I was too busy to figure out what was wrong and ignored it. However, there is one HUGE TIME SAVER in 1.2.0 that I just couldn’t wait for any longer. Up through 1.1.1, gem update and gem install calls both updated all locally cached gemspec’s from your gem sources. This not only led to large memory consumption (anyone on a VPS got a horror story?), but was also just a plain waste of time. If I know which gem I want to update, it should just update that gem. The onus should be on me specify that I want to fully update my cache.

That said, I finally came across Eric Hodel’s notice addressing this very problem. The solution:

john@john-ubuntu:~/passenger-recipes$ sudo gem install rubygems-update -v 1.1.1
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed rubygems-update-1.1.1
1 gem installed
john@john-ubuntu:~/passenger-recipes$ sudo gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.2.0
Updating version of RubyGems to 1.2.0
Installing RubyGems 1.2.0
...
... (success)
...
john@john-ubuntu:~/passenger-recipes$ gem -v
1.2.0

Happy upgrading.

Microsoft WebDav opens document as Read-Only when using RailsDav

July 1st, 2008

I had been working on a project in which we wanted to utilize WebDAV (namely for editing Word & Excel Documents that were saved in our application). In order to do this we decided to use a plugin from liverail.net that can be found here. It was pretty easy to hook up after a little direction from a guy over at Benryan Inc [apologies I cannot find a link for them], but there was a major issue. When opening a document through the ActiveX controller for editing it was opening in Read-Only mode.

After a few starts and stops, many hours of reading through the webdav documentation, and browsing through the http traffic using Fiddler - it was determined that locking was the issue.

Read the rest of this entry »