views:

54

answers:

3

I havent found quite what I want elsewhere or at least am not accomplished enough to adapt

I'm trying to create a project that shows radio stations with logo, listen button etc

The datasource is an xml file with child tags like 'name','image' and 'listen' for each parent, 'station'. I access this data via the main application with creationComplete="radioService.send()" I can then use it on the main app via dataProvider="{radioService.lastResult.stations.station}

However, I want to use the results to populate variables in the custom component in both the components themselves

hard coded examples

mx:Image source="Images/BBC5.gif" id="bbc5Logo" "/>

mx:LinkButton id="bbc5Listen" click="bbc5Listen_clickHandler(event)" />

and in the clickhandler

protected function bbc5Listen_clickHandler(event:MouseEvent):void {

var url:String = "http://www.bbc.co.uk/iplayer/console/bbc_radio_five_live"; var request:URLRequest = new URLRequest(url);

} Any help, much appreciated

A: 

I done something similar before though I am not sure of what look and feel you wish your app to have but it would be possible to create a Datagrid and bind the datasource to that grid. Then you can add fields to the datasource like ( img field and use the link in the XML by setting the xpath towards that field) , it would also be possible to create a button and place that in the row of the datagrid for listen.

Obviously this is a slightly different implementation but the same principle applys if you have created a custom component then make sure it makes use of DataSource and DataSource fields which will aquire the data from the right part of the XML. Then it would be possible to map that DataSource field to a String for example.

Hope this helps

Chris
New approach which might make more sense is to have the main application populate with custom components and apply values to their properties but I continue to have problems
ImAndy
New approach which might make more sense is to have the main application populate with custom components and apply values to their properties but I continue to have problems
ImAndy
A: 

Another approach could be to create Value Objects from your XML and bind your components to these objects, this way you would decouple your components from the XML , which can be handy if at some point in the future, you don't want to use XML, but JSON for instance.

Each Value Object would have the properties defined in your question , i.e , imageSource , id , url etc... and each component would be bound to one Value Object

Edit Have a look at this video training, it covers data retrieval from an XML , ArrayCollections of ValueObjets etc...
http://www.adobe.com/devnet/flex/videotraining.html

PatrickS
Thanks Guys. I'll follow up your suggestions
ImAndy
I've actually been trying another approach - again with problems
ImAndy
A: 

You can actually use Custom Events, where you can pass values from your main app to your custom component.

http://www.anujgakhar.com/2009/03/04/flex-passing-data-with-custom-events/

Vinothbabu