spark.globalization

# MatchingCollator - AS3 Flex

Package | spark.globalization
Class | public class MatchingCollator
Inheritance | MatchingCollator CollatorBase GlobalizationBase AdvancedStyleClient EventDispatcher Object

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10.1, AIR 2.5

The `MatchingCollator` class provides locale-sensitve string comparison capabilities with inital settings suitable for general string matching such as finding a matching word in a block of text.

This class is a wrapper class around the `flash.globalization.Collator`. Therefore the locale-specific string comparison is provided by the `flash.globalization.Collator`. However, this MatchingCollator class can be used in MXML declartions, uses the locale style for the requested Locale ID name, and has methods and properties that are bindable. Additionally, `LastOperationStatus` is set, if there is an error or warning generated by the flash.globalization class.

The flash.globalization.Collator class uses the underlying operating system for the formatting functionality and to supply the locale specific data. On some operating systems, the flash.globalization classes are unsupported, this wrapper class provides a fallback functionality.

View the examples

More examples

Sorting and matching

Learn more

Localization

Related API Elements

flash.globalization.Collator

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | actualLocaleIDName : String [override] [read-only] The name of the actual locale ID used by this class object. | CollatorBase
|  | className : String [read-only] The name of the component class. | AdvancedStyleClient
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | id : String The identity of the component. | AdvancedStyleClient
|  | ignoreCase : Boolean When this property is set to true, identical strings and strings that differ only in the case of the letters are evaluated as equal. | CollatorBase
|  | ignoreCharacterWidth : Boolean When this property is true, full-width and half-width forms of some Chinese and Japanese characters are evaluated as equal. | CollatorBase
|  | ignoreDiacritics : Boolean When this property is set to true, strings that use the same base characters but different accents or other diacritic marks are evaluated as equal. | CollatorBase
|  | ignoreKanaType : Boolean When this property is set to true, strings that differ only by the type of kana character being used are treated as equal. | CollatorBase
|  | ignoreSymbols : Boolean When this property is set to is true, symbol characters such as spaces, currency symbols, math symbols, and other types of symbols are ignored when sorting or matching. | CollatorBase
|  | inheritingStyles : Object An object containing the inheritable styles for this non-visual style client instance. | AdvancedStyleClient
|  | lastOperationStatus : String [override] [read-only] The status of the most recent operation that this class object performed. | CollatorBase
|  | moduleFactory : IFlexModuleFactory A module factory is used as context for finding the style manager that controls the styles for this non-visual style client instance. | AdvancedStyleClient
|  | nonInheritingStyles : Object The beginning of this component's chain of non-inheriting styles. | AdvancedStyleClient
|  | numericComparison : Boolean Controls how numeric values embedded in strings are handled during string comparison. | CollatorBase
|  | styleDeclaration : CSSStyleDeclaration The style declaration that holds the inline styles declared by this object. | AdvancedStyleClient
|  | styleManager : IStyleManager2 [read-only] Returns the StyleManager instance used by this component. | AdvancedStyleClient
|  | styleName : Object The source of this object's style values. | AdvancedStyleClient
|  | styleParent : IAdvancedStyleClient A component's parent is used to evaluate descendant selectors. | AdvancedStyleClient

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | MatchingCollator() Constructs a new MatchingCollator object to provide string comparisons according to the conventions of a specified locale. | MatchingCollator
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | clearStyle(styleProp:String):void Deletes a style property from this component instance. | AdvancedStyleClient
|  | compare(string1:String, string2:String):int Compares two strings and returns an integer value indicating whether the first string is less than, equal to, or greater than the second string. | CollatorBase
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | equals(string1:String, string2:String):Boolean Compares two strings and returns a Boolean value indicating whether the strings are equal. | CollatorBase
|  | getAvailableLocaleIDNames():Vector.<String> [static] Lists all of the locale ID names supported by this class. | CollatorBase
|  | getClassStyleDeclarations():Array Returns an Array of CSSStyleDeclaration objects for the type selector that applies to this component, or null if none exist. | AdvancedStyleClient
|  | getStyle(styleProp:String):* [override] Gets a style property that has been set anywhere in this component's style lookup chain. | GlobalizationBase
|  | hasCSSState():Boolean Returns true if currentCSSState is not null. | AdvancedStyleClient
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | initialized(document:Object, id:String):void The initialized method is called when this class or a class that extends this class is used in an MXML declaration. | AdvancedStyleClient
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | matchesCSSState(cssState:String):Boolean Returns true if cssState matches currentCSSState. | AdvancedStyleClient
|  | matchesCSSType(cssType:String):Boolean Determines whether this instance is the same as, or is a subclass of, the given type. | AdvancedStyleClient
|  | notifyStyleChangeInChildren(styleProp:String, recursive:Boolean):void Propagates style changes to the children of this style client instance. | AdvancedStyleClient
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | regenerateStyleCache(recursive:Boolean):void Sets up the internal style cache values so that the getStyle() method functions. | AdvancedStyleClient
|  | registerEffects(effects:Array):void Registers the EffectManager as one of the event listeners for each effect event. | AdvancedStyleClient
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | setStyle(styleProp:String, newValue:*):void Sets a style property on this component instance. | AdvancedStyleClient
|  | styleChanged(styleProp:String):void Detects changes to style properties. | AdvancedStyleClient
|  | stylesInitialized():void Flex calls the stylesInitialized() method when the styles for a component are first initialized. | AdvancedStyleClient
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | change | The change event is generated whenever the locale style is changed or another property is set that would cause the format of a number to change or cause updates to the other values available through this class. | GlobalizationBase
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher

Styles

Styles are either common or associated with a specific theme. If the style is common, it can be used with any theme. If a style is associated with a specific theme, it can only be used if your application uses that theme.

Common Styles
Click for more information on styles
Hide Inherited Styles
Show Inherited Styles

| Style | Description | Defined By
--- | --- | --- | ---
|  | locale | Type: String CSS Inheritance: Yes Language Version: ActionScript 3.0 Product Version: Flex 4.5 Runtime Versions: Flash10.1, AIR 2.5 The locale identifier that specifies the language, region, script and optionally other related tags and keys. | GlobalizationBase

Constructor Detail

### MatchingCollator

()
Constructor

`public function MatchingCollator()`

Language Version: | ActionScript 3.0

Product Version: | Flex 4.5

Runtime Versions: | Flash Player 10.1, AIR 2.5

Constructs a new MatchingCollator object to provide string comparisons according to the conventions of a specified locale.

This class sets the initial values of the various collation for general string matching uses such as determining if two strings are equivalent or finding a matching word in a block of text. In this mode, differences in uppercase and lower case letters, accented characters, and so on are ignored when doing string comparisons.

The comparison provided by an instance of this class is equivalent to constructing an instance of the `flash.globalization.Collator` with the `initialMode` paramater set to `CollatorMode.MATCHING`. For more details and examples of this mode, please see the documentation for the `flash.globalization.Collator` class

The locale for this class is supplied by the locale style. The locale style can be set in several ways:

- Inheriting the style from a `UIComponent` by calling the UIComponent's addStyleClient method.
- By using the class in an MXML declaration and inheriting the locale from the document that contains the declaration.

            Example:
            <fx:Declarations>
                   <s:MatchingCollator id="mc" />
            </fx:Declarations>

- By using an MXML declaration and specifying the locale value in the list of assignments.

            Example:
            <fx:Declarations>
                <s:MatchingCollator id="mc_France" locale="fr-FR" />
            </fx:Declarations>

- Calling the setStyle method, e.g. `mc.setStyle("locale", "fr-FR")`

If the `locale` style is not set by one of the above techniques, the instance of this class will be added as a `StyleClient` to the `topLevelApplication` and will therefore inherit the `locale` style from the `topLevelApplication` object when the `locale` dependent property getter or `locale` dependent method is called.

Related API Elements

flash.globalization.Collator
Examples How to use this example
MatchingCollatorExample.mxml
Copy

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Sample program for spark.globalization.MatchingCollator -->
    <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/mx">

        <fx:Declarations>
            <s:MatchingCollator id="collator"/>
        </fx:Declarations>

        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.ListEvent;

                private static const localeList:ArrayCollection
                    = new ArrayCollection([
                        { label:"English (en)", data:"en" },
                        { label:"Turkish (tr)", data:"tr" } ]);

                private static const wordList:ArrayCollection
                    = new ArrayCollection([
                        "Windows", "windows", "WINDOWS",
                        "WÄ±ndows", "wÄ±ndows", "WÄ°NDOWS" ]);

                private function inputWord_changeHandler(event:Event):void
                {
                    const word:String = inputWord.selectedItem as String;
                    resultWordList.text = "";
                    for (var i:int = 0; i < wordList.length; ++i)
                    {
                        if (collator.equals(word, wordList[i]))
                            resultWordList.text += wordList[i] + " ";
                    }
                }
            ]]>
        </fx:Script>

        <mx:Form>
            <mx:FormItem label="Select Language">
                <mx:ComboBox id="localeSelector"
                    change="setStyle('locale', localeSelector.selectedItem.data);"
                    dataProvider="{localeList}"/>
            </mx:FormItem>
            <mx:FormItem label="Ignore case">
                <s:CheckBox id="ignoreCase" selected="{collator.ignoreCase}"
                    change="collator.ignoreCase = ignoreCase.selected"/>
            </mx:FormItem>
            <mx:FormItem label="Input word">
                <mx:ComboBox id="inputWord" dataProvider="{wordList}"/>
                <s:Button click="inputWord_changeHandler(event)" label="Find"/>
            </mx:FormItem>
            <mx:FormItem label="Result Matching Words">
                <mx:Text id="resultWordList"/>
            </mx:FormItem>
        </mx:Form>
    </s:Application>

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00