Give us a call 203-379-0773

Flextras Friday Lunch - Episode 48 - 2/5/2009 - mx_internal

In this episode I talk about the mx_internal namespace. We talk about e4x, Book publishing, context menus, and FlexPMD.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

Flextras Friday Lunch - Episode 45 - 1/15/2009 - updateDisplayList()

In this episode I talk about the updateDisplayList() method. Participants ask about component resizing, and we go into details on the Flex component lifecycle.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

How do you tell if a component is in a transition?

I'm working on Fleshing out the Flextras CalendarDisplay component. I think I'm finally happy with our approach to implementing a day view. One of the things we want to support is the ability to transition between a month view, a week view, and a day view.

Transitioning from a day display to a month display was working fine. Transitioning from the month to the day was not. After stepping through the code I discovered that the updateDisplayList() method would resize the day before the effect ran, thus negating the effect.

I needed a way to figure out if a transition was playing and tell the component not to run the updateDisplayList() method.

I've seen some situations where you set a Boolean value "transitionRunning" to true before running the play method, then set it back to false in a listener to the effectEnd method.

But, that wouldn't work in this situation. If the transition is a transition between two states, then all the code for starting / stopping the effects is locked up in private methods of UIComponent.

I ended up writing this method to loop over the transitions array and figure out if one of the effects was playing.

protected function isTransitionPlaying():Boolean{
if(this.transitions){
for each(var transition : Transition in this.transitions){
if(transition.effect.isPlaying){
return true;
}
}
}
return false;
}

My intuition tells me there should be an easier way, but I'm not sure what that is.

Update:

A friend on twitter recommended I take a look at the activeEffects property. The function would be modified like this:

protected function isTransitionPlaying():Boolean{
if(this.activeEffects.length >
0){
return true;
}
return false;
}

Unfortunately, that didn't work. Even though a transition was running, it was not on the activeEffects array. I'm unsure why.

Flextras Friday Lunch - Episode 43 - 12/18/2009 - The measure() method

In this episode I talk about the Flex Component LifeCycle's measure() method. We talk about 360|Flex San Jose in 2010, build tools such as ANT and Maven, and constraints based layouts.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

What do you do with a SWC?

When you download a Flextras component--or many of the other Flex components out on the interwebs--they often come as a SWC file. What do you do with that SWC file? How do you use it in your Flex projects? I'm writing this to explain what to do.

Where does a SWCs come from?

SWCs are created in one of two ways. In Flex Builder you create a library project. Library projects are a lot like a normal Flex Project, except there is no main application file and the binary output is a swc file, not a swf. The alternate is to use the command line compiler compc.

You create classes in a library project just as if you were going to create classes in a Flex project. The compiler does magic and packages up your code into a SWC which is easily reusable across multiple projects. In this article I'm not going to go into details of creating a SWC, I'm going to focus on what you do after you have the SWC.

Using the SWC

There are three different ways that you can use the classes that reside in a SWC file:

  1. Library Path in Project Properties: This is how I use SWCs most commonly.
  2. Libs folder: The libs folder was introduced in Flex Builder 3. If you put a SWC into a libs folder it is automatically added to your library path, and all the classes in the SWC are available from your project
  3. Library Path command line argument: You can use the library path argument to the mxmlc command line compiler.

These are all different routes to the same endpoint. Most developers I'm aware of use Flex Builder, but I'll go over all three options.

Adding a SWC to the Library Path

First you want to right click on the project and bring up properties:

The project properties window is below. Select, Flex Build Path and then Library Path

Press the buttons to Add a SWC Folder or to add a SWC

Browse to the folder, or directly to a swc, then click okay and the new SWC should be added to your library path. Click okay and you can now use the classes in the SWC inside your application, just as if the code was in the project's source folder.

If you have a library project in the current workspace, you can also add it using the add Project dialog. From the screenshot you can tell that is the way I work when developing Flextras Components.

Using the Libs Folder and Command Line

Using the libs folder is almost trivially easy. Just add your SWC file to the libs folder of your Flex Builder Project. Flex Bulder will automatically add the file library path when compiling the project.

The final method is to use the command line. There isn't much to elaborate on. You just need to know the path to your file and then use the library-path command line argument, like this:

-library-path+=c:/mylibraries/MyButtonSwc.swc

Summary

SWC files allow you to create functionality and easily reuse it throughout many projects. They are a great example of hiding the implementation that is so important to encapsulation. So, those are the ways that you can use a SWC in your Flex Builder Projects.

Flex 4 Library Project -Type not found or not a compile-time constant: Matrix3D

I spent some time tonight upgrading the Flextras watermarking code to the Flex 4 SDK. I've done this before without problems, but the latest beta is giving me a bunch of errors, similar to these:

"Type not Found or not a compile-time constant: Matrix3D" "Type not Found or not a compile-time constant: Number" "Type not Found or not a compile-time constant: Vector"

After some Googling around I discovered that the fix is easy if you're using a simple Flex Project. My good friend Simeon had my back, this time without even knowing it. His blog post directed me to shortfusion blog which lets me know this is a type mismatch with player versions. I must specify that the player version for my project is Flash Player 10 or higher for this error to go away.

The shortfusion blog has a great screenshot showing you how to update the player version for your Flex Project. Unfortunately, that is where I hit a snag. That screen is not available for Flex Library Projects. What is the solution? You can use a command line compiler option on the specify the targeted player in a Library project. Just add this line to the compiler settings:

-target-player=10

You can see the setting page here:

Understanding the Flex Component LifeCycle Methods

Lately we''ve been getting a lot of questions about the proper way to use the methods in the Flex 3 Component LifeCycle. I wrote about this in the December Flextras newsletter and thought I'd turn it into a post here too.

The Flex Component Lifecycle is a set of methods and events that Flex uses to setup, size, and position the components that make up your Flex Application. There four lifecycle methods that you'll use when creating Flex Components: createChildren(), commitProperties(), measure(), and updateDisplayList(). I'll discuss each one individually.

createChildren()

The createChildren() method is aptly named. It is intended to create the children of the component. This is run as part of the initial component setup and is never run again. In our Calendar component's MonthDisplay class we use createChildren() to create the day name headers to display the day of the week and the month header which displays forward / next buttons, the month name and the year.

commitProperties()

I consider the commitProperties() method is a wild card method. You'll use commitProperties() to coordinate component changes all at once. However, the exact use of this is a bit of a gray area. It depends what properties have changed and how they affect the component.

In many of the custom components I've built I find that I'm using commitProperties() as an alternative for createChildren(). In our Calendar component, I use it to create the month's days from a dayRenderer. This can't be done in createChildren() because we may not know the displayedMonth or displayedYear yet, and therefore can't determine the number of days in the week.

measure()

The measure() method will determine the ideal size of this component. Its' purpose is the most concretely defined of all the component lifecycle methods. This will set the measuredWidth, measuredHeight, measuredMinWidth, and measuredMinHeight properties on your component. A component is always sized by its' parent; but if these properties are suggestions to that parent.

How you calculate the meauredWidth and measuredHeight is open to interpretation and depends on your component. In most cases, you'll examine each of the component's children and keeping some type of running tally. For our Calendar component's 'month display, we set measuredWidth to the width of the longest week. MeasuredHeight is calculated using sum of the heights of the largest day in each week. The calculations take into account localization features, such as the first day of week.

I've experienced a few gotchas with the measure() method. First, if you specify an explicit height and width, the measure method will not be run. This is done for performance reasons. If you already know the height and width, why does the parent need suggestions from the child? It doesn't!

Second, the documentation states that measuredMinWidth and measuredMinHeight are optional, but I have found this not to be the case. If these values are not set I've experienced situations where the width or height ended up being set to NaN, which interferes with sizing calculations up the component chain.

updateDisplayList()

The updateDisplayList() method is intended for changing the visual pieces of the component. It is great for setting the height and width of your children and positioning those children with the x and y coordinates. In the Calendar's MonthDisplay this will size and position all the days. Even though the measure() method assumes that individual days can contain have different height or widths, updateDisplayList() forces all days to the same size. You may also use updateDisplayList for changing styles.

Final Words

So, in summary:

  • createChildre(): Creates the component's children
  • commitProperties(): Coordinates property changes
  • measure(): Determines the ideal size of a component's children
  • updateDisplayList(): Positions and sizes the children

Most of the work I do when building components for Flextras relates to use of one of these component lifecycle methods. The Flex 4 framework does bring quite a few changes along with a new component architecture. Perhaps I'll write about that another time.

Flextras Friday Lunch - Episode 39 - 11/06/2009 - My Customized Flex Debugging Perspective

I show you my customized Flex Builder Debugging Perspective. The conversation touches on the best way to display a PDF in Flex, ColdFusion alternatives, and how to customize the Flex Preloader.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

Flextras Friday Lunch - Episode 37 - 10/23/2009 - commitProperties()

In this episode I talk about the Flex Component LifeCycle's commitProperties method. In the chat, we talk about the proper use of component lifecycle methods, and touch on AlivePDF.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

Flextras Friday Lunch - Episode 33 - 09/25/2009 - Custom Event Data

In this episode, I demonstrate how to add data to your custom eventt class. The conversation turns to the differences between normal and education versions of Flex Builder, performance optimization, and video in Flex and Flash.

Flextras Friday Lunch is a short demo followed by open Q&A that occur every Friday at 1pm EST. The presentations take place over Connect. You can find out what time this occurs in your own time zone at TimeAndDate.com.

I hope I can help answer some of your questions at the next one.

Notes

Subscribe

Contact

More Entries