2 Replies Latest reply on Jul 7, 2009 12:08 PM by garigantua

    differentiating Library Definitions and Declarations, and for something in between

    garigantua Level 1

      Is there MXML syntax that can define components like template that later be configured during runtime?

       

      Using Flex4 Docs says that Library and definition tags are only for graphics and symbols, meaning that do not invoke methods, right?  The great thing about them is for reusability, but they are only limited to FXGs.

       

      Declarations require giving an id to the mxml instance, which there can only be one instace of. 

       

      To instatiate runtime objects, I usually model them as a class then instantiate at runtime using AS.  Is there an MXML way to describe a "prototype" object, sort of like a blueprint of the object, then have them filled at runtime?  It could present a much cleaner and more readable variation to AS.

       

      Thanks,

       

      g

        • 1. Re: differentiating Library Definitions and Declarations, and for something in between
          CoreyRLucier Adobe Employee

          Were you going for something like this (a new component type is declared locally within the declarations section and can be instantiated within the context of the same document):

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application
              width="500" height="500"
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:mx="library://ns.adobe.com/flex/halo"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:local="*">
             
              <fx:Script>
                  <![CDATA[
                      private function createInstance():void
                      {
                          var a:MyButtonGroup = new MyButtonGroup();
                          outerGroup.addElement(a);
                      }
                  ]]>
              </fx:Script>
              <s:layout>
                  <s:VerticalLayout/>
              </s:layout>
             
              <s:Group id="outerGroup"/>
              <s:Button label="createInstance" click="createInstance()"/>
             
              <fx:Declarations>
                  <fx:Component className="MyButtonGroup">
                      <s:Group>
                          <s:Button label="SomeButton"/>
                      </s:Group>
                  </fx:Component>
              </fx:Declarations>
          </s:Application>