<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; getDefinitionByName()</title>
	<atom:link href="http://blog.flexexamples.com/tag/getdefinitionbyname/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inspecting the properties in a class using the describeType() method and E4X/XML</title>
		<link>http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/</link>
		<comments>http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 05:37:18 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[E4X]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XMLList]]></category>
		<category><![CDATA[XMLListCollection]]></category>
		<category><![CDATA[describeType()]]></category>
		<category><![CDATA[getDefinitionByName()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/</guid>
		<description><![CDATA[<p>The following example shows how you can use the describeType() method to inspect a class&#8217;s accessor methods.</p> <p>Full code after the jump.</p> <p></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" initialize="init();"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import flash.utils.getDefinitionByName; import mx.collections.Sort; import mx.collections.SortField; import mx.collections.XMLListCollection; import mx.controls.*; import mx.utils.StringUtil; import mx.utils.ObjectUtil; [Embed("bullet_red.png")] private const WRITE_ONLY_ICON:Class; [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use the <code>describeType()</code> method to inspect a class&#8217;s accessor methods.</p>
<p>Full code after the jump.</p>
<p><span id="more-798"></span></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        initialize="init();"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import flash.utils.getDefinitionByName;

            import mx.collections.Sort;
            import mx.collections.SortField;
            import mx.collections.XMLListCollection;
            import mx.controls.*;
            import mx.utils.StringUtil;
            import mx.utils.ObjectUtil;

            [Embed("bullet_red.png")]
            private const WRITE_ONLY_ICON:Class;

            [Embed("bullet_yellow.png")]
            private const READ_ONLY_ICON:Class;

            [Embed("bullet_green.png")]
            private const READ_WRITE_ICON:Class;

            private var theXML:XML;
            private var theXMLList:XMLList;
            private var theXMLListColl:XMLListCollection;

            private function init():void {
                var theSortField:SortField = new SortField("@name", true);
                var theSort:Sort = new Sort();
                theSort.fields = [theSortField];

                // var theXML:XML = describeType(getDefinitionByName("mx.controls.Alert"));
                theXML = describeType(Label);
                theXMLList = theXML.factory.accessor.(@declaredBy == theXML.@name);
                theXMLListColl = new XMLListCollection(theXMLList);
                theXMLListColl.sort = theSort;
                theXMLListColl.refresh();
                list.dataProvider = theXMLListColl;
                panel.title = "Accessor methods for the " + theXML.@name + " class:"
            }

            private function list_labelFunc(item:XML):String {
                var itemName:String = item.@name;
                var itemType:String = item.@type.split("::").pop();
                return StringUtil.substitute("{0} : {1}",
                            itemName,
                            itemType);
            }

            private function list_iconFunc(item:XML):Class {
                var access:String = item.@access;
                switch (access) {
                    case "readwrite":
                        return READ_WRITE_ICON;
                        break;
                    case "readonly":
                        return READ_ONLY_ICON;
                        break;
                    case "writeonly":
                        return WRITE_ONLY_ICON;
                        break;
                    default:
                        break;
                }
                return null;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Panel id="panel" width="350"&gt;
        &lt;mx:List id="list"
                labelFunction="list_labelFunc"
                iconFunction="list_iconFunc"
                verticalScrollPolicy="on"
                width="100%"
                itemClick="Alert.show(list.selectedItem.toXMLString());" /&gt;

        &lt;mx:ControlBar&gt;
            &lt;mx:Button label="Read/Write" icon="{READ_WRITE_ICON}" skin="{null}" /&gt;
            &lt;mx:Button label="Read Only" icon="{READ_ONLY_ICON}" skin="{null}" /&gt;
            &lt;mx:Button label="Write Only" icon="{WRITE_ONLY_ICON}" skin="{null}" /&gt;
        &lt;/mx:ControlBar&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Inspecting the properties in a class using the describeType() method and E4X/XML on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/',contentID: 'post-798',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'describeType(),getDefinitionByName()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/09/19/inspecting-the-properties-in-a-class-using-the-describetype-method-and-e4xxml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a component instance by class name in ActionScript 3.0</title>
		<link>http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/</link>
		<comments>http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 05:49:44 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[className]]></category>
		<category><![CDATA[getDefinitionByName()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/</guid>
		<description><![CDATA[<p>The following example shows how you can create a new Flex component instance by using its class name by calling the getDefintionByName() method.</p> <p>Full code after the jump.</p> <p></p> <p class="construction">In the following example, note that we must include a reference to each of the components we may need to create at runtime in a [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can create a new Flex component instance by using its class name by calling the <code>getDefintionByName()</code> method.</p>
<p>Full code after the jump.</p>
<p><span id="more-777"></span></p>
<p class="construction">In the following example, note that we must include a reference to each of the components we may need to create at runtime in a variable, <code>dummyArr</code>. This way, the components we need are compiled in to the SWF so they can be created at runtime.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/getDefinitionByName_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/ --&gt;
&lt;mx:Application name="getDefinitionByName_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.core.UIComponent;
            import flash.utils.getDefinitionByName;
            import mx.controls.*;

            /**
             * Create references to component classes so the classes get
             * included in the SWF document.
             */
            private var dummyArr:Array = [Button, CheckBox, ComboBox,
                                            List, TextInput, TextArea];

            private function createBtn_click(evt:MouseEvent):void {
                var className:String = comboBox.selectedItem.toString();
                // Convert class name to Class object.
                var cls:Class = getDefinitionByName(className) as Class;

                // Create a new instance of the class.
                var instance:UIComponent = new cls();
                if (instance) {
                    switch (instance.className) {
                        case "Button":
                            Button(instance).label = "I am a Button";
                            break;
                        case "CheckBox":
                            CheckBox(instance).label = "I am a CheckBox";
                            break;
                        case "ComboBox":
                            ComboBox(instance).dataProvider = ["I am a ComboBox"];
                            break;
                        case "List":
                            List(instance).dataProvider = ["I am a List"];
                            instance.width = 100;
                            break;
                        case "TextInput":
                            TextInput(instance).text = "I am a TextInput";
                            break;
                        case "TextArea":
                            TextArea(instance).text = "I am a TextArea";
                            break;
                    }

                    // Remove all children and add new child.
                    canvas.removeAllChildren();
                    canvas.addChild(instance);
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Form styleName="plain"
                defaultButton="{createBtn}"&gt;
            &lt;mx:FormItem label="Class:"
                    direction="horizontal"&gt;
                &lt;mx:ComboBox id="comboBox"&gt;
                    &lt;mx:dataProvider&gt;
                        &lt;mx:Array&gt;
                            &lt;mx:String&gt;mx.controls.Button&lt;/mx:String&gt;
                            &lt;mx:String&gt;mx.controls.CheckBox&lt;/mx:String&gt;
                            &lt;mx:String&gt;mx.controls.ComboBox&lt;/mx:String&gt;
                            &lt;mx:String&gt;mx.controls.List&lt;/mx:String&gt;
                            &lt;mx:String&gt;mx.controls.TextInput&lt;/mx:String&gt;
                            &lt;mx:String&gt;mx.controls.TextArea&lt;/mx:String&gt;
                        &lt;/mx:Array&gt;
                    &lt;/mx:dataProvider&gt;
                &lt;/mx:ComboBox&gt;
                &lt;mx:Button id="createBtn"
                        label="Create"
                        click="createBtn_click(event);" /&gt;
            &lt;/mx:FormItem&gt;
        &lt;/mx:Form&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:Canvas id="canvas"
            horizontalCenter="0"
            verticalCenter="0" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/getDefinitionByName_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/getDefinitionByName_test/bin/main.html" width="100%" height="250"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Creating a component instance by class name in ActionScript 3.0 on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/',contentID: 'post-777',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'className,getDefinitionByName()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

