rwhitlatch
asked on
flex dynamic mxml component adding
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:ArrayCollectio n=new ArrayCollection();
//loop through all questions in result
for each (var question:XML in xmlResult.Table)
{
//create question object
var tempQuestionAdt:InterviewQ uestionsAd t=new InterviewQuestionsAdt;
//load question object values from XML input
tempQuestionAdt.LoadFromXM L(question );
//add questions object to array collection for later use
questionsAC.addItem(tempQu estionAdt) ;
}
//create array collection to hold mxml components
var displayQuestionsAC:ArrayCo llection = 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:Intervi ewQuestion Widget=new interviewQuestionWidget();
//remap array collection object to custom object class
//var tempQ:InterviewQuestionsAd t=question sAC[x] as InterviewQuestionsAdt;
//define a unique 'id' value for each created mxml component
thisQuestionWidget.id="wgt Question" + x.toString();
//set current question object to mxml component value
thisQuestionWidget.Questio nAdt=tempQ ;
//Alert.show(tempQ.questio n);
//thisQuestion.Activate();
//thisQuestion.invalidateD isplayList ();
//add mxml component to display list array collection
displayQuestionsAC.addItem (thisQuest ion);
}
//reset display list data provider
listQuestions.dataProvider =displayQu estionsAC;
listQuestions.invalidateDi splayList( );
}
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:InterviewQuestionOute rWidget >
</ns2:InterviewQuestionOut erWidget>
</mx:Component>
</mx:itemRenderer>
</mx:List>
Here is the mxml component in question:
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:ArrayCollectio
//loop through all questions in result
for each (var question:XML in xmlResult.Table)
{
//create question object
var tempQuestionAdt:InterviewQ
//load question object values from XML input
tempQuestionAdt.LoadFromXM
//add questions object to array collection for later use
questionsAC.addItem(tempQu
}
//create array collection to hold mxml components
var displayQuestionsAC:ArrayCo
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:Intervi
//remap array collection object to custom object class
//var tempQ:InterviewQuestionsAd
//define a unique 'id' value for each created mxml component
thisQuestionWidget.id="wgt
//set current question object to mxml component value
thisQuestionWidget.Questio
//Alert.show(tempQ.questio
//thisQuestion.Activate();
//thisQuestion.invalidateD
//add mxml component to display list array collection
displayQuestionsAC.addItem
}
//reset display list data provider
listQuestions.dataProvider
listQuestions.invalidateDi
}
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:InterviewQuestionOute
</ns2:InterviewQuestionOut
</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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.