I will look at it tom


----- Original Message ----
From: Amy <[EMAIL PROTECTED]>
To: flexcoders@yahoogroups.com
Sent: Thursday, March 6, 2008 9:32:28 PM
Subject: [flexcoders] Re: E4x mystery

--- In [EMAIL PROTECTED] ups.com, Sherif Abdou <[EMAIL PROTECTED] ..> wrote:
>
> try wrapping your xml in an XMLListCollection and see if that 
works. I am not really following maybe upload the MXML file and i'll 
look at it, its kinda hard to follow the code on here.

It is already wrapped like that.

MyApplication. mxml:

<?xml version="1.0" encoding="utf- 8"?>
<mx:Application xmlns:mx="http://www.adobe. com/2006/ mxml" 
layout="absolute" 
xmlns:cmc="com. magnoliamultimed ia.components. *" 
creationComplete= "isStarted( )"
horizontalScrollPol icy="off" verticalScrollPolic y="off" >
<mx:Script>
<![CDATA[
import mx.collections. XMLListCollectio n;
import com.magnoliamultime dia.components. *
import mx.controls. Alert;
[Bindable]
private var qXMLList:XMLListCol lection;
private var qXML:XML;
[Bindable]
private var useHighlight: Boolean;
[Bindable]
private var editing:Boolean;
[Bindable]
private var bubbleRow:ClassFact ory;
private function getXML():void{
useHighlight = true;
//hard coded XML for testing
qXML = 
<questions>
<question id="1">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="2">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="3">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="4">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="5">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="6">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="7">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="8">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="9">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="10">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="11">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="12">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="13">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="14">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="15">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="16">
</question>
<question id="17">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="18">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="19">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="20">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="21">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="22">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="23">
<selected>3< /selected>
<selected>4< /selected>
</question>
<question id="24">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="25">
<selected>3< /selected>
<selected>5< /selected>
</question>
<question id="26">
<selected>1< /selected>
<selected>3< /selected>
</question>
<question id="27">
<selected>1< /selected>
<selected>5< /selected>
</question>
<question id="28">
<selected>1< /selected>
<selected>5< /selected>
</question>
</questions>
useHighlight = false;
editing = false;
bubbleRow = new ClassFactory
(AnswerRow);
bubbleRow.propertie s = 
{isEditing:editing} ;
showBubbles( qXML); 
setCurrentQuestion( 1);
}
//convert regular xml to xmlList
private function showBubbles( questionsXML: XML):void{
qXMLList= new XMLListCollection
(questionsXML. question) ;
scoreSheet.visible = true;
}
//pass back info about what happened
private function userAnswerHandler( e:Event): void {
if (!useHighlight) {
trace('index = ' + 
(e.target.parent. data.childIndex( ) + 1) + ', info = ' + 
qXMLList.getItemAt( e.target. parent.data. childIndex( )).toString( ));
ExternalInterface. call
('bubbleMarked' , e.target.parent. data.childIndex( )+1, 
e.target.parent. data.toString( ));
}
}
//set up to be ready to talk to container
public function isStarted(): void{
if (ExternalInterface. available) {
ExternalInterface. call("started" , 1);
ExternalInterface. addCallback
("setSource" , setXML);
ExternalInterface. addCallback
("setCurrentQuestio n", setCurrentQuestion) ;
} else {
getXML();
}
getXML(); 

setCurrentQuestion( 1);
}
public function setXML(theContent: String, 
highlightOn: Boolean=false, isContentEditor: Boolean=false) :void {
theContent=theConte nt.substring
(theContent. indexOf(" \n")+1, theContent.lastInde xOf("\n") );
qXML = XML(theContent) ;
showBubbles( qXML);
scoreSheet.visible = true;
//Alert.show( highlightOn. toString( ));
useHighlight = highlightOn;
editing = isContentEditor;
setCurrentQuestion( 1);
bubbleRow = new ClassFactory( AnswerRow) ;
bubbleRow.propertie s = {isEditing:editing} ;
}
public function setCurrentQuestion( qNum:Number) :void{
//Alert.show( qNum.toString( ));
if (useHighlight) {
scoreSheet.styleNam e 
= 'tileReviewMode' ;
scoreSheet.selected Index = qNum - 1;

} else {
scoreSheet.styleNam e = '';
}
}
]]>
</mx:Script>
<mx:Style>
Application{
backgroundColor: #FFFFFF;
}
Button{
cornerRadius : 40;
paddingLeft: 0;
paddingRight: 0;
paddingTop: 0;
paddingBottom: 0;
fontSize: 8;
}
.selectedBtn {
fillColors: #000000, #000000;
}
HBox {
paddingTop: 0;
paddingBottom: 0;
}
TileList {
paddingTop: 1;
paddingBottom: 1;
paddingRight: 10;
selectionColor: #FFFFFF;
selectionDuration: 0;
}
.tileReviewMode{
paddingTop: 0;
paddingBottom: 2;
paddingRight: 10;
selectionColor: #FFFF11;
selectionDuration: 10;
}
</mx:Style>
<mx:TileList id="scoreSheet" direction="vertical " 
dataProvider= "{qXMLList} " 
itemRenderer= "{bubbleRow} " visible="false"
rowCount="10" columnCount= "4" 
useRollOver= "false" click="userAnswerHa ndler(event) " 
mouseChildren= "{!useHighlight| |editing} " 
horizontalCenter= "0" verticalCenter= "0"/>

</mx:Application>

AnswerRow.mxml:

<?xml version="1.0" encoding="utf- 8"?>
<mx:HBox xmlns:mx="http://www.adobe. com/2006/ mxml" dataChange=" init
()" creationComplete= "finishInit( )"
implements=" mx.core.IFactory " >
<mx:Script>
<![CDATA[
import mx.controls. Alert;
[Bindable]
private var rIndex:int; //loop index
private var isWhole:Boolean; //this component is 
fully loaded
//factory variable to catch if editing
[Bindable]
public var isEditing:Boolean;

// method required by IFactory
public function newInstance( ):*{
return new AnswerRow();
}

private function init():void{
rIndex = data.childIndex( ) + 1;
callLater(setupBtns );
}
private function setupBtns(): void{
var i: int;
for (i=0; i<5; i++){
this[String. fromCharCode( i+97)
+'Btn'].styleName = '';
}
for (i = 0; i<data.selected. length(); i++){

selectBtn(this[ String.fromCharC ode(int
(data.selected[ i])+96)+' Btn']);
}
}
//handles visible selection of the selected button
private function selectBtn(theBtn: Button, 
toggle:Boolean= false):void{
if (isEditing){
//only one answer can be correct
for (var i:int=0; i<5; i++){
this[String. fromCharCode( i+97)
+'Btn'].styleName = '';
}
theBtn.styleName = 'selectedBtn' ;
} else {
//student can mark multiple answers
//toggle stylename
if (theBtn.styleName == 'selectedBtn' )
{
theBtn.styleName = '';
} else {
theBtn.styleName 
= 'selectedBtn' ;
}
}
}
private function finishInit() :void {
isWhole = true;
}
//changes selected in the data, sets the visible state
private function changeSelected( theBtn:Button, 
toggle:Boolean= false):void {
selectBtn(theBtn, toggle);
var i:int;
var selNum:int = theBtn.label. charCodeAt( ) - 
64;
trace("typeof selNum " + typeof selNum);
var miniXML:XML = XML
('<selected> '+selNum+ '</selected> ')
if (!isEditing) {
if (data.selected. length()> 0){
trace('select = 5: ' + data.
(descendants( 'selected' )==5));
if (data.
(selected==selNum) .length() <1){
//add the selected 
node to the data object
data.appendChild
(miniXML);
} else {
//remove the selected 
node from the data object
for 
(i=data.selected. length()- 1; i>=0; i--){
if 
(data.selected[ i] == selNum){

delete data.selected[ i];
}
}
}
} else {
//no children exist at 
all...add
data.appendChild( miniXML);
}
} else {
//editing
//delete all previously selected nodes
for (i=data.selected. length()- 1; i>0; 
i--){
delete data.selected[ i];
}
//check to see if this button is "on"
//if so, add it back
if (theBtn.styleName == 'selectedBtn' )
{
data.appendChild( miniXML);
}
}
}
]]>
</mx:Script>
<mx:Label text="{rIndex} " />
<mx:Button id="aBtn" label="A" click="changeSelect ed(aBtn, 
true)" width="25" height="15" />
<mx:Button id="bBtn" label="B" click="changeSelect ed(bBtn, 
true)" width="25" height="15" />
<mx:Button id="cBtn" label="C" click="changeSelect ed(cBtn, 
true)" width="25" height="15" />
<mx:Button id="dBtn" label="D" click="changeSelect ed(dBtn, 
true)" width="25" height="15" />
<mx:Button id="eBtn" label="E" click="changeSelect ed(eBtn, 
true)" width="25" height="15" />
</mx:HBox>

When I click on the question with an ID of 16 (the one that has no 
selected nodes to start with), everything works as expected. If I 
click one of the already selected nodes, then I just keep getting 
more and more selected nodes.

Thanks;

Amy


 


      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

Reply via email to