Docs for Global Error Handling in Flash Player 10.1 and AIR 2

One of the most anticipated features of Flash Player 10.1/AIR 2 was global error handling. Global error handling lets you use one class to handle any uncaught errors in your code:

flash.events.UncaughtErrorEvent

Very, very handy. Description and code examples in the ActionScript 3.0 Reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/UncaughtErrorEvent.html

Flash Player 10.1 and AIR 2 are live!

Flash Player 10.1 and AIR 2 are now available for download on adobe.com.

For more information about AIR, read the announcement on the AIR blog and check out the release notes for a list of new features.

For more information about Flash Player, read the announcement on the Flash Player blog.

The ActionScript 3.0 Reference for Flash Platform includes all the Flash Player 10.1 and AIR 2 APIs.

You can filter the ActionScript Reference to display APIs for specific runtimes:
runtime_filter.jpg

Download the Flash Player 10.1 and AIR 2 mobile runtimes from Adobe Labs.

Contest for improving US government websites

Use your programming skills and web design know-how to help the US government improve its websites!

Adobe is a platinum sponsor for a contest called Design for America. The goal of the contest is to show government agencies better ways to present information to the public. Winners get cash awards and will have their entries showcased at the Gov 2.0 Expo in May in Washington, DC.

For details, visit this site:

http://blogs.adobe.com/adobeingovernment/2010/03/design_for_america.html

Sorting an array without sorting it

Have you ever wanted to access an array in a different sequence without
changing its current sequence? The ActionScript 3.0 constant, Array.RETURNINDEXEDARRAY, allows you to do that. When you call Array.sort() with RETURNINDEXEDARRAY as a parameter, sort() returns an array of indexes in sorted order. You can then use the indexed array to access the primary array in that sequence. The following example contains an array of students’ names: John, Rachel, Melissa, Calvin. Let’s say this sequence represents their order for the seating chart. Now, however, we would
like to get them in alphabetical order for the grade book. We can do this by calling students.sort(Array.RETURNINDEXEDARRAY) and using the indexed array that it returns. Note that by default, sort() sorts in ascending order. Here’s the code:

var students:Array = ["John", "Rachel", "Melissa", "Calvin"];
var index:Array = students.sort(Array.RETURNINDEXEDARRAY);
for(var i:int = 0; i < students.length; i++) {
trace(students[index[i]] + ": student index: "
+ index[i] + " sorted: " + i);
}

The example uses a for() loop to step through the returned index array in order, using the variable i, initialized to 0. The trace() statement displays the following information: the student’s name (students[index[i]]); the position of that student in the original array (the value of index[i]); the sorted position of the student, which is the sequence of index, or the value of i. The output looks like this:

Calvin: student index: 3 sorted: 0
John: student index: 0 sorted: 1
Melissa: student index: 2 sorted: 2
Rachel: student index: 1 sorted: 3

And the order of the students array remains unchanged: John, Rachel, Melissa, Calvin.

You can obtain additional sequences by using the OR operator| to combine
RETURNINDEXEDARRAY with other sort() constants. For example, the call to students.sort() in the following code combines RETURNINDEXEDARRAY with the constant DESCENDING, to access students in descending order:

var students:Array = ["John", "Rachel", "Melissa", "Calvin"];
var index:Array = students.sort(Array.RETURNINDEXEDARRAY | Array.DESCENDING);
for(var i:int = 0; i < students.length; i++) {
trace(students[index[i]] + ": student index: "
+ index[i] + " sorted: " + i);
}

The output for this version looks like this:

Rachel: student index: 1 sorted: 0
Melissa: student index: 2 sorted: 1
John: student index: 0 sorted: 2
Calvin: student index: 3 sorted: 3

For more information on the Array class, see:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Array.html

Learn ActionScript 3.0 using Flash Professional CS4

In the summer it’s usually a little quieter at work so why not use this quiet time to learn something new? ActionScript 3.0 for instance. Doug Winnie, Adobe’s group manager for designer/developer workflows, just started a new series on Adobe TV titled: “ActionScript 1:1″.

ActionScript 1:1 is a free training resource that combines video tutorials, documentation [...]

Adjusting audio pitch in Flash Player 10

Update: Andre Michelle wrote some much better code to adjust the pitch of an external sound. I was secretly hoping he would. Check it out at http://blog.andre-michelle.com/2009/pitch-mp3. Thanks Andre!

Here is another sound example that shows how to adjust the pitch of an external sound. This is an extension of the example that can be found in the documentation for the Sound.extract method. Now this example does adjust the pitch but it also speeds the song up as well. This is because you need to skip some samples in order to increase the pitch. Now there are ways to increase the pitch of sounds without speeding them up but I have no idea how to do it. Do you?

Click on the image below to see the example. It uses my throw slider which you can toss back and forth. It may take a minute for the song to load so please be patient. You can download the FLA file if you want to see how it was done.

Lee

Update on the Adobe TextLayout Framework

The TextLayout Framework API has had quite a few changes since it was released on Adobe Labs last November. And the documentation is being updated, as well, to reflect these changes. While these changes are still in progress, the TextLayout Framework overview has been updated and incorporated into the “Working with Text” chapter of Programming ActionScript 3.0. You can find instructions on how to access and review a PDF of that chapter on Francis Cheng’s blog.

The API reference is availabe as part of the Flex Gumbo API Documentation, which accepts comments. Look for the flashx.textLayout.* packages

We’d love to get any feedback you might have.

If you’d like to see what people are doing with the TextLayout Framework, check out the New York Times Reader 2.0 application, which is built with Adobe AIR.

DataProvider.getItemIndex()

A user recently asked why the call to DataProvider.getItemIndex() in the following example returns -1:

import fl.controls.List;
import fl.data.DataProvider;
var dp:DataProvider = new DataProvider();
dp.addItem({label:"AL", data:"Montgomery"});
dp.addItem({label:"AK", data:"Juneau"});
dp.addItem({label:"AR", data:"Little Rock"});
// assign the data provider to the list
var myList:List = new List();
myList.dataProvider = dp;
myList.rowHeight = 35;
myList.rowCount = dp.length;
myList.move(10, 10);
addChild(myList);	// display the list
// this attempt to locate an item in the list returns -1
trace("Index is: " + myList.dataProvider.getItemIndex({label:"AK", data:"Juneau"}));

Paul Robertson explains:

The problem is that the getItemIndex() method matches exact object references, not objects with matching properties. The first object, {label:”AK”, data”Juneau”}, may
have identical property values with the one that’s being passed to the getItemIndex() method, but they’re not exactly the same object – they’re just two different objects that happen to have the same property values.

To get a match with getItemIndex(), you need to pass a reference to the actual object that’s in the data provider. To do that, of course, you need a reference to the
same object, for example in a variable. Here’s a variation of your code that works:

import fl.controls.List;
import fl.data.DataProvider;
var dp:DataProvider = new DataProvider();
var item1:Object = {label:"AL", data:"Montgomery"};
var item2:Object = {label:"AK", data:"Juneau"};
var item3:Object = {label:"AR", data:"Little Rock"};
dp.addItem(item1);
dp.addItem(item2);
dp.addItem(item3);
var myList:List = new List();
myList.dataProvider = dp;
myList.rowHeight = 35;
myList.rowCount = dp.length;
myList.move(10, 10);
addChild(myList);
trace("Index is: " + myList.dataProvider.getItemIndex(item2));

Of course, you are probably really trying to do some sort of search to find the index of an item that matches a user entered string. The only way I can see to do that is to loop over the data provider one item at a time and compare the property values. You can either loop over the data provider directly using dp.length and
dp.getItemAt(index), or else keep the objects in a separate array. This code demonstrates the first approach:

import fl.controls.List;
import fl.controls.Button;
import fl.controls.TextInput;
import fl.data.DataProvider;
var dp:DataProvider = new DataProvider();
dp.addItem({label:"AL", data:"Montgomery"});
dp.addItem({label:"AK", data:"Juneau"});
dp.addItem({label:"AR", data:"Little Rock"});
var myList:List = new List();
myList.dataProvider = dp;
myList.rowHeight = 35;
myList.rowCount = dp.length;
myList.move(10, 35);
addChild(myList);
var ti:TextInput = new TextInput();
ti.width = 100;
ti.move(10, 10);
addChild(ti);
var btn:Button = new Button();
btn.width = 50;
btn.label = "Search";
btn.move(120, 10);
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, btn_click);
function btn_click(event:Event):void
{
for (var i:int = 0, len:int = dp.length; i < len; i++)
{
if (dp.getItemAt(i).data == ti.text)
{
trace("Index is: " + i.toString());
return;
}
}
trace("Item not found");
}