PDA

View Full Version : Flex 3 XML button label


andrew001
02-13-2009, 05:00 AM
Hi, I am trying to make a small personal project, and I am having trouble trying label a button via XML.

I have it all loading ok and everything, but I'm just missing something.

I am trying to place the "projectname" from the XML onto the button.

I've spend 4.5 hours researching this issue .. I have come close to a few solutions, but not one addresses it fully. Any help would be great, either a link or anything. thanks

Here is my current state of the project, which works.

MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="testData.send()">

<mx:Script>
<![CDATA[
import mx.controls.Label;
import mx.rpc.events.ResultEvent;

//XML List for loaded XML file. Must be bindable!
[Bindable]private var testInfo:XMLList;

private function xmlHandler(evt:ResultEvent):void{
//Sets testInfo's root as the student. Everything else referenced in respect to this.
testInfo = evt.result.dept;
}

private function changeData(dataSet:String):void{
//Determine which set should be loaded
switch (dataSet){
case ('set1'):
//Set URL target to Test Data 1
testData.url ="assets/test-data.xml";
break;
case ('set2'):
//Set URL target to Test Data 2
testData.url ="assets/test-data2.xml";
break;
default:
//If somehow it's neither, just leave it be
break;
}
//Send out new URL Request to refresh chart
testData.send();
}



]]>
</mx:Script>

<!--Effect for when chart data changes-->
<mx:SeriesInterpolate id="changeEffect" duration="2000"/>

<!--Loads the url an XML file and then sends it to the xmlHandler function in E4X format-->
<mx:HTTPService url="assets/test-data.xml" id="testData" result="xmlHandler(event)" resultFormat="e4x"/>

<!--Contains page components. Design only-->
<mx:VBox horizontalAlign="center" width="684">

<!--Panel effects design only-->
<mx:Panel horizontalAlign="center" title="Project Completion Chart" width="684">

<!--The Chart 'testChart'-->
<mx:ColumnChart dataProvider="{testInfo}" id="testChart" showDataTips="true" width="662">
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider="{testInfo}" categoryField="name"/>

</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries showDataEffect="{changeEffect}" xField="name" yField="score" displayName="Percent complete"/>
</mx:series>

</mx:ColumnChart>

<!--Display Controls-->
<mx:HBox height="30" horizontalAlign="center">
<mx:Button label="Data Set 1" click="changeData('set1')"/>
<mx:Button label="Data Set 2" click="changeData('set2')"/>
</mx:HBox>

</mx:Panel>

<!--Legend for Chart Data-->
<mx:Legend dataProvider="{testChart}"/>

</mx:VBox>

</mx:Application>

and my XML looks like:

<?xml version="1.0" encoding="utf-8"?>
<scores>
<project>
<projectname>myproject</projectname>
</project>
<dept>
<name>Mydept</name>
<score>56</score>
</dept>
</scores>