summer
01-11-2007, 06:47 PM
Hi!
My problem is I would like to display images in a dataGrid, but the url is not directly available from the XML so I have to run it through a regex first. But how do I do that?
this is how it looks:
<mx:DataGridColumn headerText="Image" dataField="url" itemRenderer="mx.controls.Image" />
and basically what i want to do is something like this
<mx:DataGridColumn headerText="Image" dataField="findUrl(url)" itemRenderer="mx.controls.Image" />
but that doesn't work.
I'm a noob at flex :eek:
Complete code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="startApp()"
width="751"
height="650"
alpha="1.0"
>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
private function startApp():void
{
do_output();
//setInterval(do_output,5000);
}
private function do_output():void
{
imageRequest.send();
}
private function findUrl(s:String):String
{
//var pattern1:RegExp = new RegExp("http://[.\w/&;]+.jpg", "i");
var pattern1:RegExp = /http:\/\/[.\w\/&;]+.jpg/;
var str:String = s;
var r:String = pattern1.exec(str);
output.htmlText = "<img src=\"" + r + "\">";
return r;
}
]]>
</mx:Script>
<mx:HTTPService
id="imageRequest"
url="http://api.flickr.com/services/feeds/photos_public.gne"
/>
<mx:Button id="hejsa" label="Get Data" click="imageRequest.send()" cornerRadius="6" y="55" x="60" width="95" height="37"/>
<mx:DataGrid change="findUrl(productGrid.selectedItem.content)" variableRowHeight="true" x="60" y="100" id="productGrid" dataProvider="{imageRequest.lastResult.feed.entry}" width="619" height="309" fontFamily="Verdana" color="#008040" borderColor="#ff8000" alpha="1" enabled="true" >
<mx:columns>
<mx:DataGridColumn headerText="Image" dataField="url" itemRenderer="mx.controls.Image" />
<mx:DataGridColumn headerText="Content" dataField="content" />
<mx:DataGridColumn headerText="Published" dataField="published" />
</mx:columns>
</mx:DataGrid>
<mx:TextArea text="hej" width="624" height="263" id="output" />
</mx:Application>
I hope someone can help me! :confused:
My problem is I would like to display images in a dataGrid, but the url is not directly available from the XML so I have to run it through a regex first. But how do I do that?
this is how it looks:
<mx:DataGridColumn headerText="Image" dataField="url" itemRenderer="mx.controls.Image" />
and basically what i want to do is something like this
<mx:DataGridColumn headerText="Image" dataField="findUrl(url)" itemRenderer="mx.controls.Image" />
but that doesn't work.
I'm a noob at flex :eek:
Complete code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="startApp()"
width="751"
height="650"
alpha="1.0"
>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
private function startApp():void
{
do_output();
//setInterval(do_output,5000);
}
private function do_output():void
{
imageRequest.send();
}
private function findUrl(s:String):String
{
//var pattern1:RegExp = new RegExp("http://[.\w/&;]+.jpg", "i");
var pattern1:RegExp = /http:\/\/[.\w\/&;]+.jpg/;
var str:String = s;
var r:String = pattern1.exec(str);
output.htmlText = "<img src=\"" + r + "\">";
return r;
}
]]>
</mx:Script>
<mx:HTTPService
id="imageRequest"
url="http://api.flickr.com/services/feeds/photos_public.gne"
/>
<mx:Button id="hejsa" label="Get Data" click="imageRequest.send()" cornerRadius="6" y="55" x="60" width="95" height="37"/>
<mx:DataGrid change="findUrl(productGrid.selectedItem.content)" variableRowHeight="true" x="60" y="100" id="productGrid" dataProvider="{imageRequest.lastResult.feed.entry}" width="619" height="309" fontFamily="Verdana" color="#008040" borderColor="#ff8000" alpha="1" enabled="true" >
<mx:columns>
<mx:DataGridColumn headerText="Image" dataField="url" itemRenderer="mx.controls.Image" />
<mx:DataGridColumn headerText="Content" dataField="content" />
<mx:DataGridColumn headerText="Published" dataField="published" />
</mx:columns>
</mx:DataGrid>
<mx:TextArea text="hej" width="624" height="263" id="output" />
</mx:Application>
I hope someone can help me! :confused: