0 Replies Latest reply on Sep 4, 2008 4:53 AM by kleber.kiefer

    accessing data from component

    kleber.kiefer Level 1
      Hello guys,

      Based in one example of internet, I create one test aplication in Flex to test the relationship of more than one component, where:

      ==========================================================
      mainComp.mxml
      ==========================================================
      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      width="400" height="400" initialize="newItem('teste1');">

      <mx:Script>
      <![CDATA[

      import mx.controls.Alert;

      private var __designItem:DesignItem;

      public function newItem(newitem:String):void {

      __designItem = DesignItemFactory.getItem(newitem)

      for each (var item in __designItem.__items) {
      Alert.show(item);
      }

      }

      ]]>
      </mx:Script>

      <mx:Button label="Button" click="newItem('teste2');"/>

      </mx:Application>
      ==========================================================

      ==========================================================
      DesignItemFactory.as
      ==========================================================
      package {

      public class DesignItemFactory {

      import DesignItem;

      static public function getItem(i_item_name:String):DesignItem {
      var newDesignItem:DesignItem = new DesignItem();
      DesignItemFactory.addItems(i_item_name,newDesignItem);
      return newDesignItem;
      }

      static private function addItems(i_item_name:String,i_design_item:DesignItem):void {
      i_design_item.addNewItem(i_item_name);
      }
      }
      }
      ==========================================================

      ==========================================================
      DesignItem.mxml
      ==========================================================
      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[

      [Bindable]
      public var __items:Array = new Array();

      public function addNewItem(i_displayObject:String):void {
      __items.push(i_displayObject);
      }

      ]]>
      </mx:Script>

      </mx:Application>
      ==========================================================

      The idea is starting from first file ("mainComp.mxml"), insert data in array from third file ("DesignItem.mxml"), and store in array (push)


      public function addNewItem(i_displayObject:String):void {
      __items.push(i_displayObject);
      }

      But, in array "for each", return only ONE element.

      Please, someone can help me?

      The principal idea is have one component (mxml) that store data (like array, for example) and can be accessed from other components.

      Thanks a lot!

      Kleber

      PS.: Sorry my bad english...