You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Irnbru <ir...@live.com> on 2014/08/01 17:48:40 UTC

How do I to access data from objects created with addElement ?

So I have a very simple cutome component with two textInputs

I create these as needed dynamically using

siFormItem         = new FormItem(); // Add formItem
siFormAttrbt        = new lpSiComp(); // Custom Component
siFormItem.addElement(siFormAttrbt); // Add Custom component to formItem
siForm.addElement(siFormItem); // Add FormItem To form

Greate this works but now how do I get to the textinput data within the
CustomComponents

I get as far as 

for (var i:int = 0; i < siForm.numElements; i++)
{
   var stringName:String = siForm.getElementAt(i) + "";
   var currentElement:IVisualElement = siForm.getElementAt(i);
					
   trace(currentElement);
					
   if (currentElement as FormItem)
   {
	trace ('Is a formItem');
   }
}
					



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: How do I to access data from objects created with addElement ?

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
Assign it an ID and reference it through that?

-Mark

-----Original Message-----
From: Irnbru [mailto:irnbruusa@live.com]
Sent: Friday, August 01, 2014 11:49 AM
To: users@flex.apache.org
Subject: How do I to access data from objects created with addElement ?

So I have a very simple cutome component with two textInputs

I create these as needed dynamically using

siFormItem         = new FormItem(); // Add formItem
siFormAttrbt        = new lpSiComp(); // Custom Component
siFormItem.addElement(siFormAttrbt); // Add Custom component to formItem
siForm.addElement(siFormItem); // Add FormItem To form

Greate this works but now how do I get to the textinput data within the
CustomComponents

I get as far as

for (var i:int = 0; i < siForm.numElements; i++)
{
   var stringName:String = siForm.getElementAt(i) + "";
   var currentElement:IVisualElement = siForm.getElementAt(i);

   trace(currentElement);

   if (currentElement as FormItem)
   {
        trace ('Is a formItem');
   }
}




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How do I to access data from objects created with addElement ?

Posted by Irnbru <ir...@live.com>.
This is an excelent approach. Especially given that I have to reference the
same structure for different events.





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446p7460.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How do I to access data from objects created with addElement ?

Posted by Chris Martin <wi...@gmail.com>.
Just to spit ball an idea.  Maybe build up an Array/Vector with the refs to
the items you built out? If you want to reference them by name directly
than maybe build out an object with properties that match the generated ids.

Example of array with items that you built

var arrItems:Array = [];
var siFormAttrbt:lpSiComp // Custom Component

for (var i:int = 0; i < numElementsToCreate; i++){
    //form item creation code

    siFormAttrbt = new lpSiComp();
    arrItems.push(siFormAttrbt);

    //code to add siFormAttrbt to form item
}

reference by:

var referenceIndex:int = 5  //to grab the 5th item in the form
var refAttr:lpSiComp = arrItems[referenceIndex] as lpSiComp;
var textInputData:String = refAttr.txtInput.text;

Here's the example with using IDs and an object

var objItems:Object = {};
var siFormAttrbt:lpSiComp // Custom Component

for (var i:int = 0; i < numElementsToCreate; i++){
    //form item creation code

    siFormAttrbt = new lpSiComp();
    siFormAttrbt.id = "formItem" + i;
    objItems[siFormAttrbt.id] = siFormAttrbt.id;

    //code to add siFormAttrbt to form item
}

reference by:

var referenceIndex:int = 5  //to grab the 5th item in the form
var refAttr:lpSiComp = objItems["formItem" + referenceIndex] as lpSiComp;
var textInputData:String = refAttr.txtInput.text;

I think the array option may be more straight forward when you look back at
the code later on.  Hope that helps,

Chris




On Fri, Aug 1, 2014 at 11:09 AM, Irnbru <ir...@live.com> wrote:

>
> //*******************************************************************/
>                                 //* We must traverse the Dynamic Form
> object. This code is not good */
>                                 //* but it works, untill I can find
> something better                */
>
> //*******************************************************************/
>                                 //* Start at the Form Level and open a
> loop to all its elements */
>
> //***************************************************************/
>                                 for (var i1:int = 0 ;i1 <=
> siForm.numElements-1;i1++)
>                                 {
>                                         //*******************/
>                                         //* Inside The form */
>                                         //*******************/
>                                         var item:IVisualElementContainer =
> siForm.getElementAt(i1) as
> IVisualElementContainer;
>
>
> //***************************************************/
>                                         //* Each Form has a Form Item
>                   */
>
> //***************************************************/
>                                         for (var i2:int = 0;
> i2<=item.numElements-1;i2++)
>                                         {
>                                                 //************************/
>                                                 //* Inside The form item */
>                                                 //************************/
>
> trace(item.getElementAt(i2));
>
>
> //*****************************************/
>                                                 //* The Form Item has a
> Custom Component  */
>
> //*****************************************/
>                                                 var
> comp:IVisualElementContainer = item.getElementAt(i2) as
> IVisualElementContainer;
>
>                                                 for (var i3:int = 0;
> i3<=comp.numElements-1;i3++)
>                                                 {
>
> //************************/
>                                                         //* Inside the
> Component */
>
> //************************/
>
> trace(comp.getElementAt(i3));
>
>
> //****************************************/
>                                                         //* The Component
> has a Vgroup Container */
>
> //****************************************/
>                                                         var
> vgrp1:IVisualElementContainer = comp.getElementAt(i3) as
> IVisualElementContainer;
>
>                                                         for (var i4:int =
> 0; i4<=vgrp1.numElements-1;i4++)
>                                                         {
>
> //*********************/
>                                                                 //* Inside
> the Vgroup */
>
> //*********************/
>
> trace(vgrp1.getElementAt(i4));
>
>
> //**************************************/
>                                                                 //* The
> Vgroup has an Hgroup container */
>
> //**************************************/
>                                                                 var
> hgrp1:IVisualElementContainer = vgrp1.getElementAt(i4) as
> IVisualElementContainer;
>
>                                                                 for (var
> i5:int = 0; i5<=hgrp1.numElements-1;i5++)
>                                                                 {
>
> //*************************************/
>
> //* Inside the final container Hgroup */
>
> //*************************************/
>
> trace(hgrp1.getElementAt(i5));
>
>
> //************************************************/
>
> //* I can finall get to the form inputs YEAH :-) */
>
> //************************************************/
>
> var input:UIComponent = hgrp1.getElementAt(i5) as UIComponent;
>
> trace(input.id);
>                                                                 }// END
> for (var i5:int = 0; i5<=hgrp1.numElements-1;i5++)
>                                                         }// END for (var
> i4:int = 0; i4<=vgrp1.numElements-1;i4++)
>                                                 }// END for (var i3:int =
> 0; i3<=comp.numElements-1;i3++)
>                                         }// END for (var i2:int = 0;
> i2<=item.numElements-1;i2++)
>                                 }// END for (var i1:int = 0 ;i1 <=
> siForm.numElements-1;i1++)
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446p7450.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: How do I to access data from objects created with addElement ?

Posted by Irnbru <ir...@live.com>.
				//*******************************************************************/
				//* We must traverse the Dynamic Form object. This code is not good */
				//* but it works, untill I can find something better                */
				//*******************************************************************/
				//* Start at the Form Level and open a loop to all its elements */
				//***************************************************************/
				for (var i1:int = 0 ;i1 <= siForm.numElements-1;i1++)
				{
					//*******************/
					//* Inside The form */
					//*******************/
					var item:IVisualElementContainer = siForm.getElementAt(i1) as
IVisualElementContainer;

					//***************************************************/
					//* Each Form has a Form Item                       */
					//***************************************************/
					for (var i2:int = 0; i2<=item.numElements-1;i2++)
					{
						//************************/
						//* Inside The form item */
						//************************/
						trace(item.getElementAt(i2));
						
						//*****************************************/
						//* The Form Item has a Custom Component  */
						//*****************************************/
						var comp:IVisualElementContainer = item.getElementAt(i2) as
IVisualElementContainer;
						
						for (var i3:int = 0; i3<=comp.numElements-1;i3++)
						{
							//************************/
							//* Inside the Component */
							//************************/
							trace(comp.getElementAt(i3));
							
							//****************************************/
							//* The Component has a Vgroup Container */
							//****************************************/
							var vgrp1:IVisualElementContainer = comp.getElementAt(i3) as
IVisualElementContainer;
							
							for (var i4:int = 0; i4<=vgrp1.numElements-1;i4++)
							{
								//*********************/
								//* Inside the Vgroup */
								//*********************/
								trace(vgrp1.getElementAt(i4));
								
								//**************************************/
								//* The Vgroup has an Hgroup container */
								//**************************************/
								var hgrp1:IVisualElementContainer = vgrp1.getElementAt(i4) as
IVisualElementContainer;

								for (var i5:int = 0; i5<=hgrp1.numElements-1;i5++)
								{
									//*************************************/
									//* Inside the final container Hgroup */
									//*************************************/
									trace(hgrp1.getElementAt(i5));
									
									//************************************************/
									//* I can finall get to the form inputs YEAH :-) */
									//************************************************/
									var input:UIComponent = hgrp1.getElementAt(i5) as UIComponent;
									trace(input.id);
								}// END for (var i5:int = 0; i5<=hgrp1.numElements-1;i5++)		
							}// END for (var i4:int = 0; i4<=vgrp1.numElements-1;i4++)							
						}// END for (var i3:int = 0; i3<=comp.numElements-1;i3++)
					}// END for (var i2:int = 0; i2<=item.numElements-1;i2++)
				}// END for (var i1:int = 0 ;i1 <= siForm.numElements-1;i1++)



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446p7450.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How do I to access data from objects created with addElement ?

Posted by Irnbru <ir...@live.com>.
I have a soultion, but it stinks. Has to be a bettwr way. Anyway I thought I
would share...
dynamicFormItem_how_to_get_to_the_data.dynamicFormItem_how_to_get_to_the_data
<http://apache-flex-users.2333346.n4.nabble.com/file/n7449/dynamicFormItem_how_to_get_to_the_data.dynamicFormItem_how_to_get_to_the_data>  



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446p7449.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: How do I to access data from objects created with addElement ?

Posted by Subscriptions <su...@leeburrows.com>.
try:

if (currentElement*is*  FormItem)



On 01/08/2014 16:48, Irnbru wrote:
> So I have a very simple cutome component with two textInputs
>
> I create these as needed dynamically using
>
> siFormItem         = new FormItem(); // Add formItem
> siFormAttrbt        = new lpSiComp(); // Custom Component
> siFormItem.addElement(siFormAttrbt); // Add Custom component to formItem
> siForm.addElement(siFormItem); // Add FormItem To form
>
> Greate this works but now how do I get to the textinput data within the
> CustomComponents
>
> I get as far as
>
> for (var i:int = 0; i < siForm.numElements; i++)
> {
>     var stringName:String = siForm.getElementAt(i) + "";
>     var currentElement:IVisualElement = siForm.getElementAt(i);
> 					
>     trace(currentElement);
> 					
>     if (currentElement as FormItem)
>     {
> 	trace ('Is a formItem');
>     }
> }
> 					
>
>
>
> --
> View this message in context: http://apache-flex-users.2333346.n4.nabble.com/How-do-I-to-access-data-from-objects-created-with-addElement-tp7446.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.

-- 
Lee Burrows
ActionScripter