DataGrid ItemEditor with Two Input Fields

October 10, 2008 by flexdream

Several folks have been asking about how to have a DataGrid ItemEditor with two input fields (say you want to separately edit first name and last name or something like that).

It’s a bit tricky because of some missing pieces in the underlying Flash focus APIs and because of how Focus events work. Here is my take on how to do it. Usual caveats apply (i.e, code is not supported and may have bugs etc).

Download Source
Run Example

Data Grid With CheckBox and ComboBox

October 10, 2008 by flexdream

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.utils.ObjectProxy;
[Bindable] private var comboArr:ArrayCollection = new ArrayCollection([new ObjectProxy({"checked":true}),new ObjectProxy({"checked":true}),new ObjectProxy({"checked":false}),new ObjectProxy({"checked":true}),new ObjectProxy({"checked":false})]);
]]>
</mx:Script>

<mx:DataGrid dataProvider=”{comboArr}”>
<mx:columns>
<mx:DataGridColumn headerText=”Check Box” dataField=”checked”>
<mx:itemRenderer>
<mx:Component>
<mx:Canvas>
<mx:CheckBox id=”checks” selected=”{data.checked}” change=”{data.checked = this.checks.selected}”/>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText=”Combo Box” dataField=”checked”>
<mx:itemRenderer>
<mx:Component>
<mx:Canvas>
<mx:ComboBox visible=”{data.checked}”>
<mx:dataProvider>
<mx:ArrayCollection>
<mx:source>
<mx:String>Data1</mx:String>
<mx:String>Data2</mx:String>
<mx:String>Data3</mx:String>
<mx:String>Data4</mx:String>
<mx:String>Data5</mx:String>
</mx:source>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:ComboBox>
</mx:Canvas>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>

Replicating click Event on a MouseOver event in Flex Accordion

October 10, 2008 by flexdream

The following code is solution to a problem where you need to make the accordion component’s MouseOver event to behave like a click event. The code will work only in the case if you have not given the names to the AccordionHeader explicitly. Check the solution out here

<?xml version=”1.0″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Script>
<![CDATA[
public function onMouseOver(evt:MouseEvent):void{
var strName:String = evt.target.name;
var strLen:int = String("_header").length;
if(strName.indexOf("_header") > -1){
accordion.selectedIndex = int(strName.substr(strLen,strName.length));
}
}
]]>
</mx:Script>
<mx:Panel title=”Accordion Container Example” height=”90%” width=”90%”
paddingTop=”10″ paddingLeft=”10″ paddingRight=”10″ paddingBottom=”10″>
<mx:Label width=”100%” color=”blue”
text=”Select an Accordion navigator button to change the panel.”/>
<mx:Accordion id=”accordion” width=”100%” height=”100%” mouseOver=”onMouseOver(event)” >
<!– Define each panel using a VBox container. –>
<mx:VBox label=”Accordion Button for Panel 1″>
<mx:Label text=”Accordion container panel 1″/>
</mx:VBox>
<mx:VBox label=”Accordion Button for Panel 2″>
<mx:Label text=”Accordion container panel 2″/>
</mx:VBox>
<mx:VBox label=”Accordion Button for Panel 3″>
<mx:Label text=”Accordion container panel 3″/>
</mx:VBox>
</mx:Accordion>
<mx:Label width=”100%” color=”blue”
text=”Programmatically select the panel using a Button control.”/>
<mx:HBox>
<mx:Button label=”Select Panel 1″ click=”accordion.selectedIndex=0;”/>
<mx:Button label=”Select Panel 2″ click=”accordion.selectedIndex=1;”/>
<mx:Button label=”Select Panel 3″ click=”accordion.selectedIndex=2;”/>
</mx:HBox>
</mx:Panel>
</mx:Application>

Enabling Handcursor on a MovieClip having dynamic TextField in AS3

October 10, 2008 by flexdream

You can enable the hand cursor on a MovieClip by defining the following statement

MovieClip.buttonMode = true;

However the solution does not work in-case you have a dynamic textField in that movieclip. To enable hand in this case you have to additionally write the following statement

MovieClip.mouseChildren = false;

The reason is that the mouseChildren property determines whether or not the children of the object are mouse enabled. If an object is mouse enabled, a user can interact with it by using a mouse. The default is true which makes the dynamic textfield interactable and due to the textfield behaviour the flash player does not show the hand-cursor.

Attaching MovieClip from library by passing classname as a string in function in AS3

October 10, 2008 by flexdream

The post contains a solution for a case where you need to attach a Library symbol and you have to pass that class name as a string to the function.

The approach followed here is by using the getDefinitionByName utility which interprets the string and convert it into a Class. Then you can use a new syntax with that particular class. Following is a code for the same solution and you can download the source files from here. The “testMC” here is a movieClip in library with the className as testMC and BaseClass as flash.display.MovieClip

import flash.utils.getDefinitionByName;


function addMovieFromLibrary(mcIName:String){
var tMC:Class = getDefinitionByName(mcIName) as Class;
var newMc:MovieClip = new tMC() as MovieClip;
addChild(newMc);
}


Get Data Grid Value on Button Click

October 10, 2008 by flexdream

<?xml version=”1.0″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” width=”800″>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
[Bindable] private var employees:ArrayCollection = new ArrayCollection([{"name":"Christina Coenraets","phone":"555-219-2270","email":"ccoenraets@fictitious.com","active":"true"},{"name":"Joanne Wall","phone":"555-219-2012","email":"jwall@fictitious.com","active":"true"},{"name":"Maurice Smith","phone":"555-219-2012","email":"maurice@fictitious.com","active":"false"},{"name":"Mary Jones","phone":"555-219-2000","email":"mjones@fictitious.com","active":"true"}]);

private function dgItemClick(event:ListEvent):void{
if (event.columnIndex != 3) //to check if the button has not been clicked
loadItem(event.itemRenderer.data);
}

public function loadItem(dataObj:Object):void{
var str:String = “”;
for (var items:String in dataObj)
{
if (items != “mx_internal_uid”)//this is an extra unique id that Flex assigns by itself
str += items + “:” + dataObj[items] + “\n”;
}
Alert.show(str);
}
]]>
</mx:Script>

<mx:DataGrid id=”dg” width=”500″ height=”200″ rowCount=”5″ dataProvider=”{employees}” itemClick=”dgItemClick(event)”>
<mx:columns>
<mx:DataGridColumn dataField=”name” headerText=”Name”/>
<mx:DataGridColumn dataField=”phone” headerText=”Phone”/>
<mx:DataGridColumn dataField=”email” headerText=”Email”/>
<mx:DataGridColumn headerText=”">
<mx:itemRenderer>
<mx:Component>
<mx:Button label=”Select” click=”{outerDocument.loadItem(data)}”/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>

</mx:Application>

Trace from the browser, using standard trace()Trace from the browser, using standard trace()

August 22, 2008 by flexdream
Some great 3rd party debug tools have been released in the past few months that expand upon the standard trace() in Flash. I recently wrote about one of them. Unfortunately, I’ve noticed myself not using these tools as often as I would like because its usually easier and quicker to just use trace(). The biggest drawback about trace, however, is that there’s no way to output from the browser … or is there?
The other day I stumbled upon an article by Josh Buhler at actionscript.org that shows you how to install the Flash Debug Player that’s buried in the application folders of Flash. The Debug Player, along with a text file, allows you to view standard traces from a swf in the browser. Now, if you’ve already read his article skip on down to the bottom of this page because I’ve added a step that will make you even happier. If you haven’t read his article yet, go on what are you waiting for? If, on the other hand, you like step-by-step instructions that get you up and running the fastest, I’ve recapped his process below. I’ve done this on both the mac and pc and can’t live without it now.
1) Uninstall your Flash Player
Find the uninstaller here: Adobe Flash Player Uninstallers.

Even though this is the first step, this is the one that you’re going to question the most, should I really uninstall my Flash Player and install the Debug Player? The answer is an emphatic “yes”. The Flash Debug Player is the exact same player with a very nice extra feature.

2) Install the Flash Debug Player

Find the installer here: Adobe Flash Debug Players

3) Verify installation of the Flash Debug Player

Restart your browser and right-click (ctrl-click) on a swf. You should have the “Debugger” option in the context menu, like the example below. Flash Debug Player

4a) Create a text file named “mm.cfg”

Save the file here:

OSX -
MacHD:Library:Application Support:Macromedia:mm.cfg
Windows XP -
C:\Documents and Settings\username\mm.cfg
Windows 2000 -
C:\mm.cfg
Linux -
home/username/mm.cfg
4b) Add properties to mm.cfg
ErrorReportingEnable=0
TraceOutputFileEnable=1
MaxWarnings=0
FLASH DEBUG PLAYERS 9,0,28,0 AND NEWER
4c) The property TraceOutputFileName is no longer needed in mm.cfg. The default location of flashlog.txt has changed and cannot be modified from the following locations:
OSX -
MacHD:Users:username:Library:Preferences:Macromedia:Flash Player:Logs:flashlog.txt
Windows -
C:\Documents and Settings\username\Application Data\Macromedia\Flash Player\Logs\flashlog.txt
Linux -
home/username/Macromedia/Flash_Player/Logs/flashlog.txt
FLASH DEBUG PLAYERS 9,0,16,0 AND OLDER
4c) Add the property TraceOutputFileName to mm.cfg
OSX -
TraceOutputFileName=MacHD:Users:username :D esktop:flashlog.txt
Windows -
TraceOutputFileName=C:\Documents and Settings\username\Desktop\flashlog.txt
ALL FLASH DEBUG PLAYERS
5) Test the Flash Debug Player

Either publish a swf that uses trace() and view it in the browser, or surf around and find out what other people have been tracing in their movies (that’s one of my favorite options). The traces have been output from the browser to the text file. Open up flashlog.txt and see for yourself, you know you want to.

And there you go. I’m sure many of you are extremely happy right now, and you should be, this is a great tip. But after a few uses, you’re going to get really annoyed opening and closing the text file to view the new traces … if only there was a way to view the text file being updated in real time like the Output window in Flash. Here’s the new step that will make you rejoice.
NEW STEP …
6) View the text file updating in real time
OSX -
Open Terminal
At the prompt type:
>> cd <path to flashlog’s directory>
>> tail -f flashlog.txt
Windows -
Go to Windows Server 2003 Tools, and download Windows Server 2003 Resource Kit Tools near the bottom of the page. Although it says Windows Server 2003 all over the page, its also made for Windows XP.
Install
Open Command Prompt
At the prompt type:
> cd <path to flashlog’s directory>
> tail -f flashlog.txt
Browse to a swf online that uses trace() and watch the magic. Terminal and Command Prompt display the contents of flashlog.txt as it changes … its just like having Flash’s Output window, except this one works in the browser!!
Isn’t this great? Like I said earlier, I’ve gotten this to work on both the mac and the pc and can’t live without it now. If you have any questions about these steps, feel free to email me or comment below and I’ll be glad to help.
OPTIONAL WINDOWS STEPS …
7) Create a batch file to quickly load up the flashlog in tail
Create a text file and rename it flashlog.bat
Right-click on the batch file and select “Edit”
Add the following content to flashlog.bat:
cd <path to flashlog’s directory>
tail -f flashlog.txt
Double-click on the batch file to see it working.
8) Create a shortcut to the batch file to set the Command Prompt colors and options
Right-click on the batch file and select “Create Shortcut”
Right-click on the shortcut and select “Properties”
To view the Command Prompt maximized change the pulldown under “Run:”
To change the colors of the Command Prompt select the “Colors” tab
Unfortunately the “Font” tab options are very limited
Under the “Options” tab, select “QuickEdit mode” to be able to easily select and copy and paste
Tip for copying and pasting in the Command Prompt:
Select the text you want to copy and then right-click it, this puts the selected text into the clipboard … now just hit ctrl-v or paste in any other program.

Close out of the properties and double-click on the shortcut to see the flashlog with your colors and options.

General Known Issues in Flash Player 9.0

August 21, 2008 by flexdream

General Known Issues in Flash Player 9.0

· Flash Player cannot progressively load files that are greater than 2Gb

· UILoader ignores scaleContent when content is loaded through loadBytes

· Memory utilization could substantially increase when large numbers of bitmaps that are subject to mipmapping are loaded

· Flash Player supports up to 30 frames per second playback for video.

· Opera and Netscape do not allow recursive calls using the ExternalInterface API into the Flash Player. This issue has been reported to Opera and Netscape.

· In certain browsers, full-screen does not render correctly when the window is split between two monitors where one monitor has a higher resolution than the other.

· Socket connecting to port under 1024 throws ioError, not securityError

· When using the Flex profiler, if FlashPlayerTrust is incorrectly created as a file, the Flex profiler will crash. Please ensure FlashPlayerTrust is properly configured as a directory.

· On the Windows standalone Flash Player, empty POST actions are changed to GET.

· Subsequent loads of ActionScript 2.0 SWFs containing components into a parent ActionScript 3.0 SWF may cause some components to break. The components will work on the first load, but loading new, or unloading ActionScript 2.0 components of the same class may exhibit this behavior.

· Developers should not rely on garbage collection if immediate clean up of active objects, such as display objects, streams and media, is expected. Use the appropriate ActionScript 3.0 APIs (close, removeEvent Listener, etc.) to get immediate behavior when cleaning up active objects.

· The delete operator is intended to remove properties of an object, and cannot be used to remove members of a class. For more details on the delete operator, see the ActionScript 3.0 Language Reference.

· Flash Player sound input does not work for OSX Audio MIDI sample rate settings higher than 48Khz. The microphone will either record noise or nothing. Some third party applications and MIDI breakout boxes will change the systemwide Audio settings on launch, and fail to return settings to default on close. To workaround this issue, go to Applications-> Utilities-> Audio MIDI Setup. Select Sound Input and change the properties for the ‘Built-in Input’ and/or ‘Built-in Microphone’ to a setting less than or equal to 48Khz.

· The standalone player cannot self-register SWF and FLV file associations under Vista without administrator privileges. Workaround: Users should launch SAFlashPlayer.exe once with administrator privileges by right-clicking on the EXE and selecting “Run as administrator” so it can correctly set the registry properties.

· Bitmap effects and filters cannot be printed.

· Button label text may not redraw correctly upon exiting full screen mode. User must mouse over the text to force the redraw.

· Transform Matrix transformations are not reflected in respective MovieClip/DisplayObject properties. Properties like scaleX, scaleY, and rotation are not changed as the result of changes to a DisplayObject’s transformation matrix (flash.geom.Transform, flash.geom.Matrix). However, changes to those properties are reflected in the matrix. If you change a property after changing the matrix, the matrix also resets to its original value. Affects ActionScript 2.0 and ActionScript 3.0. Workaround: If using matrix transformations, avoid using scaleX, scaleY, and rotation in favor of their respective matrix transformations.

· Triggering stage.invalidate() during a “render” event listener fails.

· Empty strings passed through External Interface API via JavaScript are converted to null.

· Some users are experiencing sound problems under Windows due to lack of support for WaveOut with drivers for some video cards, such as Realtek and SoundMax.

· Launching the context menu when in full-screen mode may temporarily reduce FLV video playback performance on Macintosh systems.

· Although full-screen mode does not support text input, the text input cursor will display over input text fields. Workaround: dynamically convert input fields to dynamic text fields or disable TextInput components when in full-screen mode.

MXML ActionScript Classes

August 10, 2008 by flexdream

As you know, all MXML files are converted to ActionScript Classes which are later compiled in SWF file. If you want to view / study these automatically generated classes, you can use Compiler Argument -keep-generated-actionscript in Flex Builder Project.

In Flex Builder navigate to Project > Properties > Flex Compiler > Additional compiler arguments and add following configuration: -keep-generated-actionscript

This will create a folder named generated in project source folder which will have all ActionScript classes which Flex Builder automatically generates from MXML ({MXML file name}-generated).

Moock on ActionScript 4

July 29, 2008 by flexdream

Thease feature  will probably be present in ActionScript 4 .

  • Generic Functions: This functionality will add Java-style method overloading to ActionScript. A function must be defined with the keyword generic, but then mutliple methods (with different method signatures) can be used.
  • Iterators and Generators: Increased support for iterating over a series of values using a class defined iterator. Both of these items are very Python-like.
  • Proper Tail Calls: A function can properly call another function as its last operation – this adds increased support for recursion patterns.
  • New Number Types: byte, double, decimal (and the current generic ‘Number’ type would be removed)
  • Numeric Suffixes: As in Java, numeric literals will have suffixes to denote their specific numeric type.
  • Vector Type: As in Java, there will be a mono-typed array called Vector. Length can optionally be pre-defined at creation.
  • Record Type: Describes the details of an object – easier to create than a class. I believe it is dynamic – in that it has required values, but additional properties can be defined per instance.
  • Array Type: A type that describes what will be contained within an array. For example – you could say that you will have a 7-element array made up of Strings.
  • Union Types: A property (or argument) could be one of a list of types (as opposed to now where a property has to be of one type – or no type). This would give you the ability to have an argument that could be a String or XML – but nothing else.