title: Flash Builder. Create dynamic mxml package instance
body: <p>so, I just beginning flash builder. to the point</p>
  
  <p>my app package structure:</p>
  
  <pre><code>index.mxml (default) &lt;s:application/&gt;
    [main]
      signin.mxml &lt;s:form/&gt;
      dashboard.mxml &lt;s:group/&gt;
        [content]
          home.mxml
          data_a.mxml
          data_b.mxml
          post.mxml
          and-many-more-mxml-file.mxml
          etc.mxml
  </code></pre>
  
  <p><code>index.mxml</code> work as (something like) front controller. that will only load <code>main</code> package component (<code>signin</code>,<code>dashboard</code>).</p>
  
  <p>index.mxml <code>fx:script</code>:</p>
  
  <pre><code>import main.signin;
  import main.dashboard;
  
  public var m_signin:main.signin = new signin();
  public var m_dashboard:main.dashboard = new dashboard();
  
  private function app_ready():void { //creationComplete
      //...service to check session...
      if(is_signed) {
          addElement(m_dashboard);
      } else {
          addElement(m_signin);
      }
  }
  </code></pre>
  
  <p>success.</p>
  
  <p>we assume that user is signed. then from <code>main/dashboard.mxml</code> I want to load package from <code>main.content.*</code> that defined in array.</p>
  
  <p>main/dashboard.mxml <code>fx:script</code>:</p>
  
  <pre><code>protected var dashboard_content:Object = {};
  protected var dashboard_content_list:Array = [
      ['home','Home Admin'],
      ['user_a','User Data A'],
      ['user_b','User Data B']
      //many more.
  ];
  for (var i:int = 0; i &lt; dashboard_content_list.length; i++) {
      var content_class:Class = Class(getDefinitionByName('main.content.'+dashboard_content_list[i][0]));
      var content_obj:Object = new content_class();
      dashboard_content[dashboard_content_list[i][0]] = content_obj; //for refference each component
  }
  </code></pre>
  
  <p>each array from <code>dashboard_content_list</code> explain:</p>
  
  <pre><code>0: package suffix that i want to load (ex: `main.content.home`).
  1: button label (for each content).
  </code></pre>
  
  <p>but the loop is still not working, always <code>ReferenceError: Error #1065</code>.</p>
  
  <p>so what I want todo is:
  load <code>main.content.*</code> package class and save it on <code>Object</code> in <code>main/dashboard.mxml</code>.</p>
  
  <p>some of my refference (<code>but still not working.</code>):
  <a href="http://www.untoldentertainment.com/blog/2008/11/12/as3-tutorials-instantiate-a-class-dynamically/" rel="nofollow noreferrer">http://www.untoldentertainment.com/blog/2008/11/12/as3-tutorials-instantiate-a-class-dynamically/</a>
  <a href="http://blogs.adobe.com/cantrell/archives/2010/09/loading-classes-dynamically-in-actionscript-3.html" rel="nofollow noreferrer">http://blogs.adobe.com/cantrell/archives/2010/09/loading-classes-dynamically-in-actionscript-3.html</a>
  <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getQualifiedSuperclassName()" rel="nofollow noreferrer">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getQualifiedSuperclassName()</a>
  <a href="https://stackoverflow.com/questions/6934141/instantiate-a-class-from-a-string-in-actionscript-3">Instantiate a class from a string in ActionScript 3</a>
  <a href="https://stackoverflow.com/questions/3001951/dynamically-creating-flex-components-in-actionscript">Dynamically Creating Flex Components In ActionScript</a>
  <a href="https://stackoverflow.com/questions/4065970/as3-cast-variable-as-dynamic-type">AS3: Cast Variable as Dynamic Type</a>
  <a href="https://delfeld.wordpress.com/2009/04/21/object_from_class_name/" rel="nofollow noreferrer">https://delfeld.wordpress.com/2009/04/21/object_from_class_name/</a>
  <a href="http://www.mikechambers.com/blog/2006/06/22/actionscript-3-get-a-class-reference-by-class-name/" rel="nofollow noreferrer">http://www.mikechambers.com/blog/2006/06/22/actionscript-3-get-a-class-reference-by-class-name/</a>
  <a href="http://www.rozengain.com/blog/2009/08/21/getdefinitionbyname-referenceerror-and-the-frame-metadata-tag/" rel="nofollow noreferrer">http://www.rozengain.com/blog/2009/08/21/getdefinitionbyname-referenceerror-and-the-frame-metadata-tag/</a></p>
  
  <h1>respons to @SameerJain</h1>
  
  <p>I have try:</p>
  
  <pre><code>import main.content.*;
  
  //inside creationComplete
  var c:Class = getDefinitionByName('main.content.home') as Class; // throw: ReferenceError: Error #1065
  var o:Object = new c();
  trace(o);
  </code></pre>
  
  <p>then, I try:</p>
  
  <pre><code>var c:Class = getDefinitionByName(getQualifiedClassName('main.content.home')) as Class;
  var o:Object = new c();
  trace(c); // return [class String]
  trace(o); // return '' (empty)
  trace(main.content.home); // return [class home] &lt;&lt;&lt; this what I want.
  </code></pre>
  
  <p><br/></p>
  
  <h1>SOLVED</h1>
  
  <p><strong>so, @SameerJain's answer guided me to solving my problem</strong>.</p>
  
  <pre><code>protected var dashboard_content_list:Array = [
      /*
      index-0: the class inself &lt;&lt;&lt; this solved my problem!
      index-1: the label button
      */
      [main.content.home,'Home Admin'],
      [main.content.user_a,'User Data A'],
      [main.content.user_b,'User Data B']
      //many more.
  ];
  </code></pre>
  
  <p><br/>sorry for my bad english :)<br/>thanks.</p>