1 Reply Latest reply on Feb 1, 2011 4:06 AM by Gurdeep Singh

    how to access component attribute inside dynamiclly created component?

    bobgalka Level 1

      Help me out here ;O)

       

      I finally figured out how to dynamically create custom components into a bordercontainer. Something like this...

       

       

       

      for each(var i:Object in galleryList)

      {

      gContainer =

      new galleryImage2;

      gContainer.addEventListener(galleryClick.GALLERY_EVENT,buildGallery);

       

      gContainer.imageFile = i.aGalleryImage;

      gContainer.galleryName = i.gName;

      gContainer.galleryDesc = i.gDesc;

      gContainer.gscale = .5;

       

      gallerysContainer.addElement(gContainer);

      }

       

      now inside my custom component (gContainer) there is a spark label where the i.gName goes. This all works fine but now I have been playing around with a new custom component to change the background color of the container (gallerysContainer) that houses the gContainer objects. And so now it is possible to choose a background that requires the text of the the gContainer text to be changed... I used the same color change component but of course it only affects the last generated gContainer object.

       

      How so I create a custom component as above and have access to the internals of each of them?

       

      what I want to access is the GLabel color attribute in this component?  I know it's messy.. I am still learning this stuff ;O)

       

      thanks for any insight... I'm not looking for any actual code... just a push in the right directtion..

      Bob

       

       

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

      <s:Group

       

      xmlns:s="library://ns.adobe.com/flex/spark"

      xmlns:fx=

      http://ns.adobe.com/mxml/2009

      xmlns:mx="

      library://ns.adobe.com/flex/mx"

      creationComplete="group1_creationCompleteHandler(event)"

      click="group1_clickHandler(event)"

      >

       

      <s:layout>

       

      <s:BasicLayout/>

       

      </s:layout>

       

      <fx:Metadata>

      [

      Event(name="galleryClick", type="events.galleryClick")]

       

      </fx:Metadata>

       

       

      <fx:Script>

      <![CDATA[

       

      import events.galleryClick;

       

       

      import mx.controls.Image;

       

      import mx.controls.Label;

       

      import mx.events.FlexEvent;

       

      [

      Bindable]

       

      public var imageFile:String;

      [

      Bindable]

       

      public var galleryName:String;

      [

      Bindable]

       

      public var galleryDesc:String;

      [

      Bindable]

       

      public var gscale:Number;

      [

      Bindable]

       

      public var imageID:String;

      [

      Bindable]

       

      public var contID:String;

      [

      Bindable]

       

      private var _Fcolor:uint;

       

       

       

      public function get Fcolor():uint

      {

       

      return _Fcolor;

      }

       

       

      public function set Fcolor(value:uint):void

      {

      _Fcolor = value;

      }

       

       

      protected function group1_clickHandler(event:MouseEvent):void

      {

      dispatchEvent(

      new galleryClick (galleryClick.GALLERY_EVENT));

      }

       

        

       

      protected function group1_creationCompleteHandler(event:FlexEvent):void

      {

       

      }

       

      ]]>

       

      </fx:Script>

       

       

      <s:Rect horizontalCenter="0" verticalCenter="0">

       

      <s:stroke>

       

      <s:SolidColorStroke caps="none" color="#5C5C5C" joints="miter" miterLimit="4"

      weight="

      1"/>

       

      </s:stroke>

       

      <s:fill>

       

      <s:SolidColor color="#FFFFFF"/>

       

      </s:fill>

       

      </s:Rect>

       

      <mx:Image source="{imageFile}" top="0" horizontalCenter="0" scaleX="{gscale}" scaleY="{gscale}" bottom="20" toolTip="{galleryDesc}"/>

       

      <s:Label id="GLabel" color="{_Fcolor}" fontFamily="Arial" fontSize="18"

      text="

      {galleryName}" bottom="0" horizontalCenter="0"/>

       

      </s:Group>