May 14th, 2007 by Kyle
Tags: , , , , ,
Posted in: ActionScript, Flex

I have used mx_internal a few times, but in between my instances of use, forget exactly what I have to do to use it. Here is a link to a good blog article that describes what to do.


No Comments »

April 17th, 2007 by Kyle
Tags: , , , , ,
Posted in: ActionScript, Flex

E4X is a very powerful and easy way to manipulate xml data in Flex.
Of course something so p[powerful can sometimes be confusing when it produces unexpected results.

     <mx:XML format="e4x" id="myXML">
           <order>
              <item id=‘1′>
                  <menuName>burger</menuName>
                  <price>3.95</price>
              </item>
              <item id=‘2′>
                  <menuName>fries</menuName>
                  <price>1.45</price>
             </item>
          </order>
      </mx:XML>
 

If you wanted to retrieve the price of the burger menuitem above, it is easily done with the e4x expression:

     <mx:XML format="e4x" id="myXML">
          <order>
              <item id=’1′>
                  <menuName>burger</menuName>
                  <menuName>burger</menuName>
                  <price>3.95</price>
              </item>
              <item id=’2′>
                  <menuName>fries</menuName>
                  <price>1.45</price>
             </item>
          </order>
      </mx:XML>
 

Then if you used the same expression, you actually would not get a value returned.
It is not obvious as to why this happens, but of course there is more than one way to skin a cat…
Here is an expression that will work:

    myXML.item.menuName.(text()=="burger").parent().price;
 

Here is a link to a Flex Builder 2.0.1 project (compiled with SDK hotfix1) containing a sample demonstrating the solution described above.


No Comments »

April 17th, 2007 by Kyle
Tags: , , , , , , , ,
Posted in: ActionScript, Flex

If in the dataGrid control you set showHeader = false and if the dataProvider has no items in it, then the vertical column lines don’t show up.
The vertical column separator lines only appear when the dataProvider has items populating the grid (or if there is no data and showHeader=true).
In the Datagrid code, drawing the vertical column separator lines is keyed off of the listData, which would have a “row 0” containing the header row if the headers where to be visible.
The solution to this is to extend the datagrid and override the drawLinesAndColumnBackgrounds method in which you can iterate over the column array rather than the listItems to draw the vertical lines.

Read the rest of this post»


No Comments »

This is installment 3 in the series.
The previous 2 related posts are:

Changing embedded True Type fonts at Runtime in Flex Applications

Using Modules to Change embedded True Type fonts at Runtime in Flex Applications

This approach is a little different.
The application is very similar, but instead of using a loader or module loading, I use the StyleManager to load a runtime CSS swf (which was compiled from a CSS file).

Here is one of the style sheets that is tuned into a CSS swf:

/* CSS file */
@font-face {
    src:url("assets/arial.ttf");
    fontFamily: myFont;
}

@font-face {
    /* Note the different filename for boldface. */
    src:url("assets/arialbd.ttf");
    fontFamily: myFont; /* Notice that this is the same alias. */
    fontWeight: bold;
}

@font-face {
    /* Note the different filename for italic face. */
    src:url("assets/ariali.ttf");
    fontFamily: myFont; /* Notice that this is the same alias. */
    fontStyle: italic;
}
 
@font-face {
    /* Note the different filename for bold-italic face. */
    src:url("assets/arialbi.ttf");
    fontFamily: myFont; /* Notice that this is the same alias. */
    fontWeight: bold;
    fontStyle: italic;
}

.myPlainStyle {
    fontSize: 11;
    fontFamily: myFont;
 }
 
.myBoldStyle {
    fontSize: 11;
    fontFamily: myFont;
    fontWeight: bold;
}

.myItalicStyle {
    fontSize: 11;
    fontFamily: myFont;
    fontStyle: italic;
}

.myBoldItalicStyle {
    fontSize: 11;
    fontFamily: myFont;
    fontWeight: bold;    
    fontStyle: italic;
}
 

Read the rest of this post»


1 Comment »

This is really part 2 in the series. Part 1 was Changing embedded True Type fonts at Runtime in Flex Applications

The interface that I have each font swf implementing is the same, so I have not posted the code.

The application has undergone some slight refactoring and I have added a few things.
I chose to use the ModuleManager.getModule(url) rather than using the mx:ModuleLoader tag.
The module Manager was more flexible and really should be used for loading non-visual modules.

Note the way that you get access to the loaded module after it has loaded:

 var ml:IModuleInfo = e.target as IModuleInfo;
 loadedFont = ml.factory.create()as IFontModule;
 

Read the rest of this post»


No Comments »

I’ve had a few customers ask me how they can switch out embedded fonts at runtime. This really isn’t too difficult and basically involves loading swfs at runtime that have the appropriate fonts embedded within.
You register the font after the “font swf” is loaded and apply the newly loaded font to whatever components you like. Check out the code and comments below.

First I define an interface that I want all my font swf classes to implement so I know how to determine what font(s) are loaded.

IFontModule.as:

package
{
    public interface IFontModule
    {
        function get fontName_Normal():String;
        function get fontName_Bold():String;
        function get fontName_Italic():String;
        function get fontName_BoldItalic():String;
    }
}

Read the rest of this post»


3 Comments »

February 5th, 2007 by Kyle
Tags: , , , , , , , ,
Posted in: ActionScript, Flash Player, Flex

I’ve been asked this by at least 4 customers and provided them with simple samples that set the stage.quality = StageQuality.BEST. This provides smoother image scaling, but at potentially some performance cost. You also have to use the loaded image’s content property, casting it to a bitmap in order to scale it. I don’t recall exactly where I found the info on this, but I Googled and didn’t find a good reference for doing this, so I thought I’d post my own solution.

Check out the code snippet:

<mx:application xmlns:mx="http://www.adobe.com/2006/mxml">
    applicationComplete="stage.quality = StageQuality.BEST">

    <mx:script>
        <!–[CDATA[
            private function handleImageComplete(event: Event): void {
                var bitmap: Bitmap = ((event.target as Image).content as Bitmap);
                if (bitmap != null) {
                    bitmap.smoothing = true;
                }
            }
        ]]–>
    </mx:script>

    <mx:hslider id="zoomSlider">
        height="150"
        buttonMode="true" useHandCursor="true"
        minimum="1" maximum="10"
        snapInterval="1" tickInterval="1" value="1"/>

    <mx:image height="600" width="800">
        scaleX="{zoomSlider.value}" scaleY="{zoomSlider.value}"
        source="me.jpg" complete="handleImageComplete(event)" />
</mx:image></mx:hslider></mx:application>


No Comments »

I had a customer request some help in modifying the default Flex ComboBox behavior such that when the dropdown list was open and a user was scrolling the mousewheel with the mouse outside the dropdown list, the dropdown list would scroll. The default behavior is to close the dropdown list as soon as the user scrolls the mousewheel outside the dropdown list.

Read the rest of this post»


No Comments »