Adobe Flex 3 Nested Radio Buttons

28. May 2009

NestedRadioButtons I’ve been working on a Flex radio button component that will allow users to select nested options.  The control accepts an XMLList as the data source for the button options, and expands to show nested buttons beneath selected options according the data passed in to it. The nest level of radio buttons is essentially infinite.

The best way to understand it is to take a look.

Live Example     View Source

For the moment, this is only a proof-of-concept version of the control. The control has 2 values to indicate selected values. One is bottomValue which holds only the value of the bottom-most selected radio button. The other is fullValue which holds a comma separated list of values beginning with the top-most value and ending with the bottom-most value.

With this version of the component, you can also pass in an initial bottomValue and the control will select all of the parent radio buttons recursively and accurately fill in the fullValue field.

Flex developers: Check out the control and let me know what you think! If there is significant interest, I’ll work on revising the component to feel more like a native Flex Framework control and add some additional features to it. It’s usable as is, but needs work to polish it up before it can used efficiently and reliably in a live Flex application.

Adobe Flex

 Popping up HTML with Flex

29. January 2009

I made a new example showing 3 ways to pop-up HTML content with Flex 3.2. You can view the example here:

Demo: http://www.brentlamborn.com/examples/popup/

Source: http://www.brentlamborn.com/examples/popup/srcview/index.html

I also posted an article over at the Flex Cookbook.

 

Adobe Flex

 Embed YouTube Videos Inside A Flex Application

23. December 2008

I recently ran across a question in a Flex forum from a visitor asking how to embed YouTube videos inside Flex . The solution is very simple. Since the YouTube player is a Flash object itself,  we can simply use the SWFLoader object to load the Youtube video into our Flex app. You just need to copy the embed code on the YouTube page for the video you want to embed in your application. It will look like this:

 

<object width="425" height="344"><param name="movie" 
value="http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1">
</param><param name="allowFullScreen" value="true">
</param><param name="allowscriptaccess" value="always">
</param><embed src=http://www.youtube.com/v/zlfKdbWwruY&hl=en&fs=1
 type="application/x-shockwave-flash" 
allowscriptaccess="always" allowfullscreen="true" 
width="425" height="344"></embed></object> 
 
 

Then just grab the URL to the video from the embed code and use it as the source property for your SWFLoader.  I created a working sample here with view source enabled.

Adobe Flex

 The Flex Component Lifecycle

16. December 2008

This is an excellent video detailing the lifecycle of Adobe Flex components. Unless you are an expert Flex dev, you are almost certain to hear a tip that will improve your applications efficiency by watching it. I really wish I would have known even just some of the information in this video before beginning work on my recent projects. I'm including it here on my blog for my own reference, as well as any Flex devs that happen upon my other Flex posts. It's about an hour long - but well worth the time!


Adobe Flex

 Kick Ass Flex Debugger

9. December 2008

I just found a new debugger for Adobe Flex applications. It pretty much works along the same lines as Firebug does for debugging web pages. The debugger is called Kap Inspect.  To use it in your Flex apps, all you have to do is include the SWC file in your project, add the namespace, and a single MXML tag and you are up and running. 

 With your Flex app running in the browser just hit Ctrl + Alt + F12 and a debugger window will pop-up that allows you to inspect events process, check the design and the styles, manipulate objects properties and more.

Here is a demo you can try out. One thing I really like is that I can use it even without running my app in Debug mode!  If you do any Flex development I suggest you check it out!

Adobe Flex

 Tour de Flex

25. November 2008

If you are a Flex developer or are interested in Flex, I suggest you check out Tour de Flex! Tour de Flex is a desktop application for exploring Flex capabilities and resources, including the core Flex components, Adobe AIR and data integration, as well as a variety of third-party components, effects, skins, and more.

 

 Tour de Flex has three primary purposes:

  • Provide non-Flex developers with a good overview of what is possible in Flex in a “look and see” environment
  • Provide Flex developers with an illustrated reference tool
  • Provide commercial and non-commercial Flex developers a place to showcase their work

It's about a 50 mb download so be patient!

Tour de Flex includes over 200 runnable samples, each with source code, links to documentation, and other details. Topics include the Flex Core Components, Flex Data Access, AIR Desktop Capabilities, Cloud APIs, Data Visualization, Mapping, and a growing collection of custom components, effects, skins, etc.

 Note: If you don't want to download the entire AIR app, but still want to look at some of the examples go here.

Adobe Flex

 Thanks Adobe!

27. August 2008

flex 3 book I posted a few how-to articles on Adobe's Flex Cookbook site recently and to say thanks they sent me this great Flex 3 book from O'Reilly!

I'm not sure if the book was to say thanks, or if my articles were so crappy that they felt sorry for me and thought I needed to learn more about Flex! Big Grin Just kidding,  my articles rock - check 'em out!

Thanks for the great book Adobe!

Adobe Flex

 Flex 3 Looping over itemRenderers in a List

20. August 2008

Adobe Flex Looping over the data used by a Flex List component is easy enough, but what if you need to loop over the actual itemRenderers in the List? Recently I needed to do just that.

I needed a reference to each of the itemRenderers so that I could pass TextInput controls in my custom renderer into a 3rd party spell check library.  Anytime you want to do something with the controls inside each of the custom itemRenderers in your list, looping over them will come in handy.

The key to doing it with Flex 3 is understanding the mx_internal namespace. A lot of variables in the Flex framework are mx_internal variables.  Variables in the mx_internal namespace are ones that Adobe thinks have a high probability of changing in future versions of Flex, so  they reside in a special namespace so developers know they may change. Since the Flex framework is open source, we can easily open the code and find which variables are mx_internal.

The List controls inherits from ListBase. ListBase has a mx_internal variable named rendererArray. rendererArray is just that, an array of renderer's used by your List.  If you try to access rendererArray using the standard List component you wont be able to. To gain access to this array we will need to create a new component that inherits from List. Below is the full source for my ExposedRendererList :

   1:  package Controls
   2:  {
   3:      import mx.controls.List;
   4:      import mx.core.mx_internal; //this import statement should appear be last
   5:   
   6:      public class ExposedRendererList extends List
   7:      {
   8:          use namespace mx_internal; //tells Actionscript that mx_internal is a namespace 
   9:          
  10:          public function ExposedRendererList()
  11:          {
  12:              super();
  13:          }
  14:          
  15:          //The array of renderer's being used in this list
  16:          public function get renderers():Array
  17:          {
  18:              //prefix the internal property name with its namespace
  19:              return mx_internal::rendererArray;
  20:          }
  21:          
  22:      }
  23:  }

 

There are 3 lines of code we need to take a look at. The first one is line 4. We need to import  mx.core.internal namespace  into our new class. On line 8 we tell Actionscript that mx_internal is a namespace we will be using in the class. And finally we create a new property on our class named renderers. The only thing it does is get the rendererArray from ListBase (which is the parent class for List). We have to prefix rendererArray with the mx_internal:: namespace in order to gain access to it. Now we've exposed the previously internal array for use anywhere in our Flex application.

Looping over the renderers or components in each of renderers becomes pretty trivial. The one thing to keep in mind is that rendererArray is an Array of Array so we'll need to write our ActionScript accordingly. Here is a sample method the does a for...each loop over the itemRenderers in a List:

   1:  private function LoopOverRenderers():void
   2:              {
   3:                  for each(var renderer:Array in coolstuff.renderers)
   4:                  {
   5:                      //renderers is an array of arrays
   6:                      //in a List component, our renders will be the first element of each array
   7:                      
   8:                      if(renderer[0] != null)
   9:                      {
  10:                          ProductRenderer(renderer[0]).img.rotation += 90;
  11:                      }
  12:                  }
  13:              }

 

I'm also including the obligatory live example with view source enabled so you can view the full source code and/or download the sample app.

In the sample application, I simply rotate the image in each of the renderers 90 degrees to show I have reference to each itemRenderer and its therefore its child components.

 

Adobe Flex