2 Replies Latest reply on Sep 2, 2009 6:08 AM by San Question

    Dynamic Object Creation in MXML Class

    San Question

      Hi ,

       

      1)         In the below code i have created a static error box in MXML file . can u please help me to create the dynamic errorbox instead of the below static object.

       

       

      Static Object Creation :

       

          <mx:Fade id="ViewStack_EffectStart" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
          <mx:Fade id="ViewStack_EffectEnd" duration="500" alphaFrom="1.0" alphaTo="0.0"/>

       

      <comp:ErrorBox id="errorBox" active="{active}" showEffect="{ViewStack_EffectStart}" hideEffect="{ViewStack_EffectEnd}"/> .

       

       

       

      2).  The above static objects is working fine, but the problem is that we have lot of similiar static object which creates a memory issue.If we create dynamic objects, will it avoid the issue.Is dynamic objects advisible?.


      Thanks in advance.Please reply ASAP.

       

       

      Thanks ,

      San.

        • 1. Re: Dynamic Object Creation in MXML Class
          Andrew Rosewarn Level 3

          You need to create your errorbox as a component with some public properties for things like the error message as below

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="318" height="158"  backgroundColor="#EDDDDD">
              <mx:Script>
                  <![CDATA[
                      [Bindable]
                      private var _errorMessage:String;
                     
                      [Bindable]
                      public function set errorMessage(value:String):void {
                          _errorMessage = value;
                      }
                     
                      public function get errorMessage():String {
                          return _errorMessage;
                      }
                  ]]>
              </mx:Script>
             
              <mx:Text x="20" y="24" text="{_errorMessage}" width="279" height="114"/>
          </mx:Canvas>

           

          Then you can set the errror Message for diffferent errors as shown below in the main app

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  >
              <mx:Script>
                  <![CDATA[
                      import mx.managers.PopUpManager;
                      private var errorBox:ErrorBox;
                     
                      private function showError():void {
                          errorBox = new ErrorBox();
                          errorBox.errorMessage = 'This is an error';
                          PopUpManager.addPopUp(errorBox,this);
                          PopUpManager.centerPopUp(errorBox);
                      }
                     
                      private function removeError():void {
                          PopUpManager.removePopUp(errorBox);
                      }
                  ]]>
              </mx:Script>
              <mx:Button x="42" y="41" label="Show Error" width="106" click="showError()"/>
              <mx:Button x="42" y="71" label="Remove Error" width="106" click="removeError()"/>
          </mx:Application>

           

          To take if further and to fit your needs you'll probably want to add more public properties to set things like error icons or buttons to select and return a response, warning messages etx.

           

          Hope that helps

           

          Andrew

          • 2. Re: Dynamic Object Creation in MXML Class
            San Question Level 1

            Hi ,

             

                 The below dynamic object creation is not working . can u please guide me to create dynamic object.

                  with curly brace initilization ( active = "{active}" ).

             

            Static Object Creation :

             

            Eg:

             

                <mx:Fade id="ViewStack_EffectStart" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
                <mx:Fade id="ViewStack_EffectEnd" duration="500" alphaFrom="1.0" alphaTo="0.0"/>

                <comp:ErrorBox id="errorBox" active="{active}" showEffect="{ViewStack_EffectStart}" hideEffect="{ViewStack_EffectEnd}"/>

             

             

            Dynamic Object Creation:

             

            Eg:

             

                <mx:Fade id="ViewStack_EffectStart" duration="500" alphaFrom="0.0" alphaTo="1.0"/>
                <mx:Fade id="ViewStack_EffectEnd" duration="500" alphaFrom="1.0" alphaTo="0.0"/>

             

                       var   errorBox:ErrorBox  = new ErrorBox ();

                      errorBox.active="{active}";

                      errorBox.showEffect="{ViewStack_EffectStart}";
                      errorBox.hideEffect="{ViewStack_EffectEnd}";

             

            Thanks,

            Santhosh.