天天看点

Creating unique identifiers for objects using the getUID()

The following example shows how you can use the static <code>UIDUtil.getUID()</code> method to generate and retreive a unique identifier for an Object. The first time you click the Display UID button, an Alert control displays the generated UID and a string representation of the Object (yay <code>ObjectUtil.toString()</code>!). The second time you click the Display UID button, you’ll notice that a new parameter is added to the Object, mx_internal_uid

&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;!-- http://blog.flexexamples.com/2007/11/01/creating-unique-identifiers-for-objects-using-the-getuid-method/ --&gt;

&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

        layout="vertical"

        verticalAlign="middle"

        backgroundColor="white"&gt;

    &lt;mx:Script&gt;

        &lt;![CDATA[

            import mx.controls.Alert;

            import mx.utils.ObjectUtil;

            import mx.utils.UIDUtil;

            private function displayUID():void {

                var text:String = ObjectUtil.toString(myObj);

                var title:String = UIDUtil.getUID(myObj);

                Alert.show(text, title);

            }

        ]]&gt;

    &lt;/mx:Script&gt;

    &lt;mx:Object id="myObj" name="peter" site="flexexamples.com" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;

        &lt;mx:Button label="Display UID"

                click="displayUID();" /&gt;

    &lt;/mx:ApplicationControlBar&gt;

&lt;/mx:Application&gt;

    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/13/1037067.html,如需转载请自行联系原作者

继续阅读