 <p>To programmatically instantiate the component instead of a declarative implementation, use <code>addElement()</code> to add components to the display list.</p> <p>For example, to add a visual element to a Spark Group named <code>container</code>.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="creationCompleteHandler(event)"&gt; &lt;fx:Script&gt; &lt;![CDATA[ import mx.core.UIComponent; import mx.events.FlexEvent; protected function creationCompleteHandler(event:FlexEvent):void { var component:UIComponent = new UIComponent(); component.x = 5; component.y = 5; container.addElement(component); } ]]&gt; &lt;/fx:Script&gt; &lt;s:Group id="container" /&gt; &lt;/s:Application&gt; </code></pre> <p>Within script blocks, use package namespaces instead of MXML namespaces.</p> <pre><code>import com.msns.Component; var component:Component = new Component(); component.x = 5 </code></pre>