0 Replies Latest reply on Feb 28, 2008 7:59 AM by ericbelair

    ActionScript: Making MXML Component properties accessible across components

    ericbelair Level 1
      I have a dynamic mashup application which allows users to build a custom page using available sub-applications. I currently have each of these sub-applications as their own MXML components. So, I am dynamically adding these to the main application according to the user's settings. Several of these components use the properties that are set and stored in their parent component. But, in order to use them in the child components, I have to create the properties in the child components, and set them each time. I would like to have these properties only in the parent component, but accessible, as needed, by each of the child components.

      Example:

      This is a skimmed down, non-dynamic version of my application.

      I have three files in my application: application.mxml, parentComp.mxml, childComp1.mxml, and childComp2.mxml.

      application.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">
      <mx:Script>
      <![CDATA[

      private function init():void
      {
      var _parentComp:parentComp = new parentComp();

      hBox.addChild(_parentComp);
      }

      ]]>
      </mx:Script>

      <mx:HBox id="hBox" width="100%" height="100%">
      </mx:Application>

      parentComp.mxml:

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">
      <mx:Script>
      <![CDATA[
      public var users:Array = new Array("joe","bob","ted","bill");

      private function init():void
      {
      var _childComp1:childComp1 = new childComp1();

      _childComp1.users = users;

      var _childComp2:childComp2 = new childComp2();

      _childComp2.users = users;

      viewStack.addChild(_childComp1);
      }

      ]]>
      </mx:Script>

      <mx:ViewStack id="viewStack" width="100%" height="100%">
      </mx:Canvas>

      childComp1.mxml:

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">
      <mx:Script>
      <![CDATA[
      public var users:Array;

      private function init():void
      {
      dataGrid.dataProvider = users;
      }

      ]]>
      </mx:Script>

      <mx:DataGrid id="dataGrid" width="100%" height="100%">
      </mx:Canvas>

      childComp1.mxml:

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">
      <mx:Script>
      <![CDATA[
      public var users:Array;

      private function init():void
      {
      comboBox.dataProvider = users;
      }

      ]]>
      </mx:Script>

      <mx:ComboBox id="comboBox" width="100%" height="100%">
      </mx:Canvas>

      So, instead of having to create a public variable named "users" in both childComp1.mxml and childComp2.mxml, I want to be able to access the variable "users" in parentComp.mxml.

      Can anyone help?

      Thank you.