This component is based on the revised codebase of AutoComplete 4 component originally created by Tenger Ivan from FlashCommander.org
Two different search modes are supported : prefix and infix
to see the difference please play with the interactive sample file below.
The auto-completion operation can be achieved in two ways:
via keyboard
First, select the list item by moving selected index via UP and DOWN keys and confirm the choice by hitting ENTER key
via mouse
Just mouse click upon the currently selected list item.
Disclaimer: the source code of this component is of beta quality and can be obtained for free here: ZIP file, 23 kb. If any bug is found, please let me know.
UPD: Updated sample file with a real world list of 978 US universities.
Also a few bugs were fixed related to case insensitive search and not working text highlight of the last string character.
February 4, 2010 @ 6:56 pm
· Filed under Adobe Flex
Flex 4 documentation article named "Selecting and modifying text" lists an finite final list of components that supports the selection:
RichEditableText
Label (Spark only)
TextInput (both MX and Spark)
TextArea (both MX and Spark)
RichTextEditor and all controls that have a TextArea as a subcomponent
This list does not include RichText component, but luckily with a new Text Layout Framework (TLF) available starting from Flash player 10, it is quite easy to "simulate" dynamic selection of the text with some ActionScript 3 code.
In the following example, try to drag the slider to the left and to the right to control the dynamic selection of the text of RichText component:
Code listing:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
width="200"
height="75">
<s:layout>
<s:HorizontalLayout paddingLeft="25"
paddingTop="25"
paddingRight="25"/>
</s:layout>
<fx:Script>
<![CDATA[
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.edit.SelectionState;
import flashx.textLayout.formats.TextLayoutFormat;
protected function highlightItem(endSelectionCharIndex : int):void
{
var containerFormat:TextLayoutFormat = new TextLayoutFormat();
var paragraphFormat:TextLayoutFormat = new TextLayoutFormat();
var characterFormat:TextLayoutFormat = new TextLayoutFormat();
characterFormat = _selectedTextFormat;
var selectionState : SelectionState = new SelectionState(rt.textFlow, 0, endSelectionCharIndex, _selectedTextFormat);
// apply format to the selection
_textEditManager.applyFormat(
characterFormat,
paragraphFormat,
containerFormat,
selectionState);
characterFormat = _notSelectedTextFormat;
// apply format to the rest of the text
var notSelectionState : SelectionState = new SelectionState(rt.textFlow, endSelectionCharIndex, rt.text.length, _notSelectedTextFormat);
_textEditManager.applyFormat(
characterFormat, paragraphFormat, containerFormat, notSelectionState);
}
protected function onRichTextCreationComplete():void
{
_textEditManager = new EditManager();
rt.textFlow.interactionManager = _textEditManager;
_selectedTextFormat = new TextLayoutFormat();
_selectedTextFormat.backgroundColor = 0xFF99CC;
_selectedTextFormat.color = 0x000000;
_notSelectedTextFormat = new TextLayoutFormat();
_notSelectedTextFormat.backgroundColor = 0xFFFFFF;
_notSelectedTextFormat.color = 0x000000;
}
private var _textEditManager : EditManager;
private var _selectedTextFormat : TextLayoutFormat;
private var _notSelectedTextFormat : TextLayoutFormat;
]]>
</fx:Script>
<s:RichText id="rt" text="Sample text"
creationComplete="onRichTextCreationComplete()"/>
<s:HSlider id="slider"
minimum="0"
maximum="10"
change="highlightItem(slider.value)">
</s:HSlider>
</s:Application>
December 24, 2009 @ 8:02 pm
· Filed under Adobe Flex
Invalidation in Flex is a mechanism by which changes made to a component's property values are queued and processed.This property value invalidation in Flex is controlled by setting and resetting boolean variables called dirty flags.
One of such a dirty flags used internally in Flex invalidation mechanism is invalidatePropertiesFlag flag.
This particular flag is reset in validateProperties() method from mx.core.UIComponent class from Flex 3 SDK:
public function validateProperties():void
{
if (invalidatePropertiesFlag)
{
commitProperties();
invalidatePropertiesFlag = false;
}
}
Inside commitProperties() function the actual changes occur to the invalidated property's value, for example, it can be "width" property.
My question is:
Why dirty flag invalidatePropertiesFlag is reset aftercommitProperties() call, but not before this call?
I speculate this happens because:
It is just a matter of life == code convention to put the dirty flag at the end of IF block;
If code within commitProperties() raises RTE, we will still have a chance to execute the code in commitProperties() during playing next frame in Flash Player and this time maybe the code will not throw RTE.
At this point, you may start to wonder why the exact location (at the very beginning or at the very end of IF sequence) of the dirty flag can be important?
It is very likely that the authors of Adobe Flex SDK have never devised the following simple use-case for both List and DataGrid components from Flex SDK:
"selectable" property is set to false
"editable" property is set to true
To prove this fact, try to play with the following samples:
mx:List
Click the first row, in a List, then the itemEditor appears on the first row.
Click the second row in a List , but the itemEditor doesn't appear on the second row
Now, try to click on the DataGrid header, oops, you've just hit SDK-19436 bug (itemEditor instance is created unwillingly at first column, first row of DataGrid).
Then try to scroll the DataGrid with scroller buttons, and again you've hit another, albeit similar, SDK-21726 bug (itemEditor instance is created unwillingly at first column, first row of DataGrid).
Now scroll the contents of Datagrid a little bit down with a scroller thumb and start to edit cell in the first topmost visible row, first column, now move the current focus by pressing keyboard combination Shift+Tab, and once again, you've hit a SDK-16262 bug.
To conclude this post: do not set selectable on mx:List or mx:DataGrid components to false if you are going to edit their values using itemEditors, until all above mentioned bugs will be fixed.
November 4, 2008 @ 6:43 pm
· Filed under Adobe Flex
I was going to enter a new issue into Adobe JIRA Flex SDK bugbase that I could confirm to be present in the most recent milestone Adobe Flex SDK release 3.1.0.2710, shipped together with an August 2008 Flex Builder 3.0.1 update.
Just before submitting the bug issue, I've tested the functionality under the question under the latest Adobe Flex SDK stable build (3.2.0.3794 at the time of writing) - and I was surprised to find out that the bug is already fixed. Joy! Joy!
I rushed to find the reasoning for this change for UITextFormat class by reading change notes at Flex SDK download section at Adobe open source web-site, but could not find any remarks regarding this change - would be handy to have a better insight behind this change for the community.
ps If you wonder, the issue was incorrect implementation of an internal function copyFrom from UITextFormat class. UITextField's public getUITextFormat() method relies on this copyFrom function to return UITextFormat object for the UITextField class instance. In a nutshell UITextFormat object is just a wrapper around textFormat class that should contain all the properties from wrapped textFormat class instance + add some additional functionality.
As it turned out, In Adobe Flex SDK 3.1 and below, 7(!) different properties were not copied into UITextFormat object from existing textFormat format object because of wrong implementation of UITextFormat.copyFrom function.
April 20, 2008 @ 12:02 am
· Filed under Adobe Flex
When you want to update already existing data item in your ArrayCollection in ActionScript 3 with a new values for object's properties you have 2 options to select from:
//Update an existing person in the ArrayCollection via setItemAt
public function updatePersonViaSetItemAt():void {
var currentlySelectedItem : Object = dg.selectedItem;
currentlySelectedItem.first = firstInput.text;
currentlySelectedItem.last = lastInput.text;
ac.setItemAt(currentlySelectedItem, dg.selectedIndex);
}
// Update an existing person in the ArrayCollection via itemUpdated
public function updatePersonViaItemUpdated():void {
var currentlySelectedItem : Object = dg.selectedItem;
currentlySelectedItem.first = firstInput.text;
currentlySelectedItem.last = lastInput.text;
ac.itemUpdated(currentlySelectedItem);
}
Which one to choose?
I would strongly advice to always use 'itemUpdated' because of the following reasons:
Calling setItemAt(x) on your existing data item in ArrayCollection is an equivalent to calling the removeItemAt(x) method and then calling the addItemAt(..., x) method on your data item.
Thus after making the call to setItemAt(x, index) you will loose the current selection in your ArrayCollection dependant UI component (mx:DataGrid, mx:Tree, mx:Combobox.. etc..)
If the Sort rule is already applied to your ArrayCollection then you can receive some funky results like unwanted inserting of a new row when partly changing several properties of the existing data item in ArrayCollection.
Speakers list had included 3 (THREE!) talented local Flash profesionals who had presented to the audience of 45 attendees mostly from all major cities in Eastern Ukraine and Kyiv included + 1 international visitor from Russia.
The speech topics were as follows:
Event flow model in ActionScript 3.0 (presented by Pirrest)
Introducing Flash media server 3.0 feature (presented by Dinosaur)
Applying PureMVC framework to the creation of vector map of Moscow city (like Mos2.ru does) (presented by _rost)
.
Rostyslav Syrik _rost discusses the ins and outs of PureMVC framework.
The UAFPUG-1 meeting audience was very into the subject of the seminars .
Thank you to all of you, who had helped to make this meeting to become a reality, especially _rost, Reijji, __i, Pirrest and Global Logic team crew.
February 13, 2008 @ 4:28 am
· Filed under Adobe Flex
The issue:
I was stumbled upon once ago when I loaded my external SWF file authored by the Flash IDE by the help of component and suddenly (?) every content object that was originally placed outside of the Stage inside the Flash IDE became visible in my Flex 2 based web application outside of the boundaries after loading sequence for my external SWF file was over (the file is Flash8 based, AVM1 if this matters).
I currently fight this issue by applying the mask over the content that is loaded by the component, see the code below, may be you can find it helpful too:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
resize="applyMask()" >
<mx:Script>
<![CDATA[
private function applyMask() : void {
if (swf != null &&
swf.content != null &&
swf.content.loaderInfo.width > 0 &&
swf.content.loaderInfo.height > 0) {
var scaleRatioX : Number = swf.content.loaderInfo.width /
this.width;
var scaleRatioY : Number = swf.content.loaderInfo.height /
(this.height - this.controlBar.height);
var scaleRatio : Number = Math.max(scaleRatioX, scaleRatioY);
swf.width = swf.content.loaderInfo.width > 0 ?
Math.round(swf.content.loaderInfo.width / scaleRatio) : 100;
swf.height = swf.content.loaderInfo.height > 0 ?
Math.round(swf.content.loaderInfo.height / scaleRatio) : 100;
var s : Shape = new Shape();
s.graphics.beginFill(0xFFFFFF);
s.graphics.drawRect(0, 0, swf.width, swf.height);
s.graphics.endFill();
swf.addChild(s);
s.visible = false;
swf.mask = s;
}
}
]]>
</mx:Script>
<mx:SWFLoader id="swf"
complete="applyMask()"
source="navigation.swf"/>
</mx:VBox>
October 17, 2007 @ 10:12 am
· Filed under Adobe Flex
The steps I underwent:
I had installed Flex Builder 3 beta 2 (FB 3 beta 2) as a plugin on my Eclipse 3.2
Opened my Flex SWF Library projects inside of Flex Builder 3 beta 2
Selected Flex 3 M3 (Beta 2) SDK at the dialog (default value)
Flex Buidler 2 had given me the following error in my log file: (full error info skipped for the sake of text clarity)
java.lang.IllegalArgumentException: Attempted to beginRule: P/FlexLibrary, does not match outer scope rule: P/as3corelib
at com.adobe.flexbuilder.project.actionscript.internal.FlexProjectPreferences.setUpgradeFlexSDK
(FlexProjectPreferences.java:147)
at com.adobe.flexbuilder.project.actionscript.internal.ActionScriptProjectSettings$2.runInUIThread
(ActionScriptProjectSettings.java:285)
Nevertheless of the received error, I was able to compile ALL my Flex 2 based projects that relies on my Flex SWC Library projects in FB 3 Beta 2
Then I had reopened my plain Flex projects inside Flex Builder 2 again, because at the company we are using currently Flex Builder 2 for the production.
But Flex Builder 2 constantly had failed to recompile all Flex SWC Library projects that were previously opened at least once at FB 3 beta2.
My resolution to this issue was to delete manually a config file created by FB 3 beta 2 and located at each Flex SWC library project folder at the following path: