Jeffry Houser is Editor In Chief of Flex Authority + 30onAIR

I'm pleased to announce that I am now on board as editor in chief of Flex Authority. Flex Authority will be a quarterly print journal aimed at teaching programmers about Flex. The first issue is being planned, and we are looking for authors. Contact me for more information. I'm sure that there will be an official press release soon from the House of Fusion folks.

Since I hear that milk shake analogies are all the rage, here is my attempt at a 30OnAIR video.

It came out really dark, but I'm not sure why. It looked fantastic on the video camera screen. I was thinking of doing another attempt, which would be an interview the smallest Cabbage Patch Kids that lives in my living room. Red in the top left has her own Mii.

Will Adobe Open Screen Project bring Flash to Game Consoles?

Will the Adobe Open Screen Project bring the Flash player to game consoles? Will I be able to create a Flash game and deploy it via Wiiware?

The open screen project removes some licensing restrictions on delivering the Flash Player and also documents a porting layer for the API, making it easier to get the Flash Player working on your device. I do not see Nintendo or Sony or Microsoft on the list of supporters, but I do think this move would make it easier to implement a version of the Flash Player for game consoles. I wonder if a game developer would take the time to do that, or if it has to be done by the console maker?

The implications for a game developer to be able to develop something once and deploy it across consoles and computers consistently is huge. Maybe my next company will be a gaming company. I'm still digesting what this will mean for the community as Flash and Flex Developers.

Ryan's post on the topic also mentioned also mentioned Adobe AIR for devices, which is a new concept for me. Kevin Lynch's video also mentions AIR for Devices.

Dragging and Dropping Between Lists Part 3: Showing The Code

This is the third part of a series about dragging and dropping between lists. You can read part 1, where I spoke about properties related to dragging and dropping. In part 2, I covered events. In this one, I'm going to ditch with the theory and show you some code.

There are 3 properties that need to be set to enable dragging and dropping. dragEnabled specifies whether an item can be copied from one list to another. DragMoveEnabled specifies whether the item can be moved in addition to copying. DropEnabled says that the current list can allow for items to be dropped on it. EAch property accepts a value of either true or false, leaving a total of eight possible configurations for drag and drop. I'm going to implement all 8 possible options.

First, I'm going to create 8 data providers:

<mx:Script><![CDATA[
import mx.collections.ArrayCollection;
   
[Bindable] public var AC1 : ArrayCollection = new ArrayCollection([
{id: 2, text: "One"} ,
{id: 3, text: "Two"},
{id: 4, text: "Three"}
]);

[Bindable] public var AC2 : ArrayCollection = new ArrayCollection([
{id: 4, text: "Four"} ,
{id: 5, text: "Five"},
{id: 6, text: "Six"}
]);

[Bindable] public var AC3 : ArrayCollection = new ArrayCollection([
{id: 7, text: "Seven"} ,
{id: 8, text: "Eight"},
{id: 9, text: "Nine"}
]);


[Bindable] public var AC4 : ArrayCollection = new ArrayCollection([
{id: 10, text: "Ten"} ,
{id: 11, text: "Eleven"},
{id: 12, text: "Twelve"}
]);


[Bindable] public var AC5 : ArrayCollection = new ArrayCollection([
{id: 13, text: "Thirteen"} ,
{id: 14, text: "Fourteen"},
{id: 15, text: "Fifteen"}
]);

[Bindable] public var AC6 : ArrayCollection = new ArrayCollection([
{id: 16, text: "Sixteen"} ,
{id: 17, text: "Seventeen"},
{id: 18, text: "Eighteen"}
]);

[Bindable] public var AC7 : ArrayCollection = new ArrayCollection([
{id: 19, text: "Nineteen"} ,
{id: 20, text: "Twenty"},
{id: 21, text: "Twenty-one"}
]);


[Bindable] public var AC8 : ArrayCollection = new ArrayCollection([
{id: 22, text: "Twenty-two"} ,
{id: 23, text: "Twenty-three"},
{id: 24, text: "Twenty-four"}
]);

]]></mx:Script>

Eight options, so that creates 8 different data provider. Now we need 8 different lists. Here is the first:

<mx:List dataProvider="{this.AC1}" id="List0" height="100%"
dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"    >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

The first one has dragEnabled set to true, dropenabled to true, and dragMoveEnabled to true. This means that you can copy or move items from this list, and also bring new items into the list.

<mx:List dataProvider="{this.AC2}" id="List1" height="100%"
dragEnabled="true" dropEnabled="true" dragMoveEnabled="false"    >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

The second one changes dragMoveEnabled to false. This means you can copy items from this list, but cannot move them. Anything can be brought into the list.

<mx:List dataProvider="{this.AC3}" id="List2" height="100%"
dragEnabled="true" dropEnabled="false" dragMoveEnabled="true"    >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

The third list sets drop enabled to false. That means you can't drop items onto the list. However, you can copy or move items to any other list that has dropEnabled to true.

<mx:List dataProvider="{this.AC4}" id="List3" height="100%"
dragEnabled="true" dropEnabled="false" dragMoveEnabled="false" >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

This fourth list modifies the previous one by changing dragMoveEnabled to false. That means items can be copied from this but cannot be moved from the list. Next we go through the first four options, with "dragEnabled" set to false. I'm not going to show the code for each of the 4 options, because the end results are pretty much the same. If you can't drag items away from the list, then dragMoveEnabled has no affect, thus only leaving dropEnabled the only property that matters. Here is code for each variation with dragEnabled=false:

<mx:List dataProvider="{this.AC5}" id="List4" height="100%"
dragEnabled="false" dropEnabled="true" dragMoveEnabled="true" >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

<mx:List dataProvider="{this.A7}" id="List6" height="100%"
dragEnabled="false" dropEnabled="false" dragMoveEnabled="true" >

<mx:itemRenderer><mx:Component>
<mx:Label text="{data.text}" />
</mx:Component></mx:itemRenderer>
</mx:List>

In List4 you can drop items onto it. In list6 you can't. It seems odd that there is no way to "move" an item without also having "copy" enabled. Perhaps we need to have Adobe add a "dragCopyEnabled' property or some other solution.

You can view the full source code here, or the compiled swf here

A question for my readers. Do my readers like these "more expansive" series split into multiple posts, or would you rather shorter self contained posts?

Using AIR to launch other applications

Lets say you want to open an MS Word file from your web page. You can just link to it using a normal HREF. Browser settings and the operating system will take care of the rest. If it's a PDF, Reader will open. Word will launch for a .doc file. Excel for an excel sheet. ( Or perhaps your browser independent equivalents ).

How do you give the same functionality to an AIR Application? This exact question came up on the Flex Coders list recently and the general concensus was that it could not be done. That surprised me, because I figured you could do something very similiar to what you would do in a web page and let the operating system handle it. This would (I assume) not violate ay security protocols inside AIR. Am I right?

I played around with it and found one solution to the problem. It's far from perfect, though. I accomplished this using the NavigateToURL functionality. The code is really simple, just a button to open the file:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script><![CDATA[
import flash.net.URLRequest;
      
public function clickButton():void{
var request : URLRequest = new URLRequest('C:\\projects\\test.doc');
navigateToURL(request )   
}
]]></mx:Script>
   
<mx:Button click="clickButton()" />
</mx:WindowedApplication>

Click the button, it creates a URL Request and then uses navigateToURL to launch it. In my tests, this will launch a browser instance outside of AIR; and that browser instance will deal with the file, launching word, or a text editor, or whatever depending upon the file.

I can understand how, in some situations this would not be ideal. Perhaps in AIR next we need a navigateToApplication?

Personality Test MeMe


My Personality

Neuroticism
63
Extraversion
16
Openness to Experience
15
Agreeableness
31
Conscientiousness
39
You rarely get angry and it takes a lot to make you angry, however you experience panic, confusion, and helplessness when under pressure or stress. You tend not to talk much and prefer to let others control the activities of groups. You tend not to express your emotions openly and are sometimes not even aware of your own feelings. There are times when you believe that a certain amount of deception in social relationships is necessary, however you are mostly candid, frank and sincere. People find it moderately easy to relate to you, however you do not particularly like helping other people. Requests for help feel like an imposition on your time. You take your time when making decisions and will deliberate on all the possible consequences and alternatives.

Take a Personality Test now or view the full Personality Report.

The best Buying Pet Gifts.

How much of this is me? Answer before reading my thoughts.

[More]

How can I find the user's screen size in AIR?

Yesterday, someone posted to Apollo Coders to ask if they can find out the user's screen resolution in an AIR application. The answer is yes, you can.

You can find this information out using the flash.system.Capabilities class. You need to look at the screenResolutionX and screenResolutionY properties. These are static properties on the Capabilities class, so you do not need to create an instance.

The poster also asked if he could find the height and width of the current window. This on was even easier to answer, because windows (and most UI controls ) have a height and width in the Flex framework.

I can demonstrate both of these answers with a single code sample. This code sample will size the application window to 60% of the screen width:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    preinitialize="preInitializeHandler()"/>

<mx:Script><![CDATA[

import flash.system.Capabilities;
import mx.controls.Alert

private function preInitializeHandler():void{
// set the width to 60% of the full screen this.height = Capabilities.screenResolutionY * .6;
this.width = Capabilities.screenResolutionX * .6;
this.visible = true;
}

]]></mx:Script>

</mx:WindowedApplication>

This code is very similar to something I used in a Flex application for a client. It runs code in the preinitialize event. That code sets the height and width of the WindowedApplication to 60% of the screenResolution. Then it makes the window visible. ( I set the window to be invisible in the app.xml file )

As a note, this should work in a Flex app too, but I haven't tried it.

I got a busy week this week. Thursday I'm at a a Microsoft even in Hartford. I understand they are giving out free software. Friday I'm down in NYC to do some podcast interviews at Flex Camp Wall Street.

What is the difference between Children and dataProvider Elements in a Flex DataGrid?

Sean was having some trouble with the number of children in the dataProvider of a DataGrid. Here was his question:

I'm using a DataGrid component for a list of data. I have a timer that is set to auto-rotate through the elements in the DataGrid, one at a time every 5 seconds. However, the problem I am running into is that the numChildren property of the DataGrid does not appear to return the actual number of children in the list. It only appears to return the number of visible children in the list. Once it hits the visible bottom of the list, it goes back to the top... my question is:

Is there a property other than numChildren that will return the actual number of children in the DataGrid instead of only the visible number of children?

The numChildren property returns the number of children (AKA itemRenderer objects) in the DataGrid. Was was getting exactly what he was asking for. Unfortuantely, he was asking for the wrong thing. What he wanted was the number of elements in the dataProvider; which is a completely different number.

The DataGrid (and List, and probably other similar type components) only creates children (rows) based on what is shown on the screen. As you scroll through a DataGrid, the children (rows) are recycled. Instead of creating a new row for each element, it changes the content in an already existing one. This is done for performance reasons. If you have a list of 100 images, for example, but are only displaying 6 images you wouldn't want the Flash Player to render all 100 images.

To get the number of elements in the dataProvider, you need to go back to the dataProvider. If it's an ArrayCollection, you can use the length. Something like this would work DataGrid.dataProvider.length.

The difference between children and dataProvider elements was not intuitive to Sean. I guess if he really wanted to use the numChildren to get the value he wanted, he could extend the DataGrid and override the property. However, that would be inconsistent with how numChildren is handled in the rest of the framework. It refers to visual elements, not data elements.

Cookie Crisp for breakfast, I can't wait.

All Content Copyright 2005, 2006, 2007 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.8.