[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

flex dynamic mxml component adding

Posted on 2010-08-20
1
Medium Priority
?
1,470 Views
Last Modified: 2012-05-10
Hello,

I'm attempting to add mxml components dynamically to a display list within a form and am having issues.  

The form is intended to allow users to conduct customer interviews.  After selecting the interview type from a combo box, questions are retrieved via web service (working) and then added to a question object (custom AS3 class ).
These objects are then added to an array collection.  Then I create another array collection and add my mxml question 'widget' and map it to one of the existing question objects. When I run the application and refresh the data provider of the display list (using custom item renderer), the components will display but not the mapped question object values (i.e. the question text).

How do I get the mapped question object values to display within the component?



Here is how I am building the list data provider:

                                //save web service result (XML) for local use
                        var xmlResult:XML=new XML(event.result);

                        //create array collection to hold question object values
                        var questionsAC:ArrayCollection=new ArrayCollection();

                        //loop through all questions in result
                        for each (var question:XML in xmlResult.Table)
                        {
                              //create question object
                              var tempQuestionAdt:InterviewQuestionsAdt=new InterviewQuestionsAdt;
                              
                              //load question object values from XML input
                              tempQuestionAdt.LoadFromXML(question);
                              
                              //add questions object to array collection for later use
                              questionsAC.addItem(tempQuestionAdt);
                        }
                        
                        //create array collection to hold mxml components
                        var displayQuestionsAC:ArrayCollection = new ArrayCollection();
                        
                        try
                        {
                  // loop through all questions in questions array and assign objects to mxml components
                              for (var x:int=0; x < questionsAC.length; x++)
                              {
                                    //create new mxml component
                                    var thisQuestionWidget:InterviewQuestionWidget=new interviewQuestionWidget();
      
                                    //remap array collection object to custom object class
                                               
                                               
                                    //var tempQ:InterviewQuestionsAdt=questionsAC[x] as InterviewQuestionsAdt;

                                    //define a unique 'id' value for each created mxml component
                                    thisQuestionWidget.id="wgtQuestion" + x.toString();
                                    
                                    //set current question object to mxml component value
                                    thisQuestionWidget.QuestionAdt=tempQ;
                                    
                                    //Alert.show(tempQ.question);
                                    //thisQuestion.Activate();
                                    //thisQuestion.invalidateDisplayList();
                                    
                                    //add mxml component to display list array collection
                                    displayQuestionsAC.addItem(thisQuestion);
                              }
                              
                              //reset display list data provider
                              listQuestions.dataProvider=displayQuestionsAC;
                              listQuestions.invalidateDisplayList();
                        }
                        catch (err:Error)
                        {
                              //display error
                              Alert.show(err.message);
                        }



Here is the mxml List:

<mx:List x="10" y="184" width="698" height="414" id="listQuestions"  >
                  <mx:itemRenderer>
                                                
                                          <mx:Component>
                                                <ns2:InterviewQuestionOuterWidget  >
                                                
                                                </ns2:InterviewQuestionOuterWidget>
                                          </mx:Component>

                                    </mx:itemRenderer>
                  
                  </mx:List>



Here is the mxml component in question:


<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
		   width="524"
		   height="170"
		   cornerRadius="8"
		   borderThickness="1"
		   borderColor="#000000"
		   color="#000000"
		   borderStyle="solid"
		   backgroundColor="#B2B2B2"
		   fontFamily="futura md bt"
		   fontSize="10"
		   maxHeight="170"
		   maxWidth="524"
		   creationComplete="Activate();"	  
		   >
			   

	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import com.adobe.linguistics.spelling.SpellUI;
			import com.lag.adt.cosulting.interview.InterviewQuestionsAdt;
			import mx.controls.Alert;

			[Bindable]
			public var QuestionAdt:InterviewQuestionsAdt;
			
			public var cbAnswerScores:ArrayCollection = new ArrayCollection([{label:"Very Positive",score:5},{label:"Positive",score:4},{label:"Neutral",score:3},{label:"Negative",score:2},{label:"Very Negative",score:1}]);
			
			public var InitDone:Boolean = false;
			
			public function Init():void
			{
				InitDone = true;
			}
			
			public function Activate():void
			{
				Alert.show(QuestionAdt.question);
				trace("Question is:"+QuestionAdt.question);
				trace("Tip is: "+QuestionAdt.questiontips);
				txtQuestionText.text = QuestionAdt.question;
				txtQuestionText.toolTip = QuestionAdt.questiontips;
			}
			public function setQuestionText():void
			{
				 if(txtQuestionText != null)
				{ 
					Alert.show(QuestionAdt.question);
					txtQuestionText.text = this.QuestionAdt.question.toString();
					txtQuestionText.toolTip = this.QuestionAdt.questiontips.toString();
				}
			}
		]]>
	</mx:Script>


	<mx:TextInput x="10"
				  y="72"
				  width="458"
				  height="86"
				  fontFamily="futura md bt"
				  fontSize="10"
				  text="Answer Text Goes Here."
				  id="txtAnswerText"
				  creationComplete="SpellUI.enableSpelling(txtAnswerText, 'en_US');"/>
	<mx:TextInput x="10"
				  y="22"
				  width="376"
				  height="42"
				  editable="true"
				  backgroundColor="#E2DEDE" 
				  fontFamily="futura md bt"
				  fontSize="12"
				  id="txtQuestionText"
				  enabled="true" visible="true"
				  />
				  
	<mx:Button x="476"
			   y="72"
			   width="35"
			   height="86"
			   id="btnExpandAnswerText">
		<mx:downIcon>@Embed(source='../../Assets/img/up_arrow_16_x_16.gif')</mx:downIcon>
		<mx:icon>@Embed(source='../../Assets/img/down_arrow_16_x_16.gif')</mx:icon>
	</mx:Button>
	<mx:ComboBox x="394" y="24" width="118" id="cbAnswerScore" dataProvider="{cbAnswerScores}" labelField="label" selectedIndex="2" ></mx:ComboBox>
	<mx:Label x="394" y="54" id="lbQnum"/>

</mx:Canvas>

Open in new window

0
Comment
Question by:rwhitlatch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
jth_92 earned 2000 total points
ID: 33487384
Depending on the way your service is returning the xml there could be different methods.
What I would do is create a variable that is bindable in your mxml component for each property of the question that you need:

[Bindable] public var QuestionTextVar:String;
....
In the txtQuestionText TextInput Component add the property:
   text="{QuestionTextVar}" to show

<mx:TextInput x="10"
                          y="22"
                          width="376"
                          height="42"
                          editable="true"
                          backgroundColor="#E2DEDE"
                          fontFamily="futura md bt"
                          fontSize="12"
                          id="txtQuestionText"
                          enabled="true" visible="true"
                          text="{QuestionTextVar}" />                            


When you create the object from you main application:

                              //create question object
                              var tempQuestionAdt:InterviewQuestionsAdt=new InterviewQuestionsAdt;

                              /* replace this with ******************************
                              //load question object values from XML input
                              tempQuestionAdt.LoadFromXML(question);
                              ****************************************************/
                             /* with the following ***********************/
                            tempQuestionAdt.QuestionTextVar = question.lastResult.xmlQuestionTag //replace xmlQuestion Tag with the correct xml tag that returns the question

                              //add questions object to array collection for later use
                              questionsAC.addItem(tempQuestionAdt);

Thus, the mxml component should correctly load from the parent application.
For more info check out: http://livedocs.adobe.com/flex/3/html/help.html?content=layouts_12.html
where it discusses how to pass data to and from a pop-up window.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question