Ciao a tutti,
premesso che non sono una espertona di actionscript e che quello che vi so per postare è frutto di duro lavoro, di scoppiazzatura qua e là, e anche di un po di cu.. usp.. fortuna!
Sono riuscita a fare il cellrenered di alcuni dati che formatto in html in una datagrid...
ma ora, tutto ciò, vorrei che stasse in una datalist (perchè non voglio la riga di intestazone) e non ci riesco stauffa!!!
Codice PHP:
XML.prototype.ignoreWhite = true
import mx.services.WebService;
import mx.services.PendingCall;
import mx.controls.gridclasses.DataGridColumn;
amazonHtmlFunction = function (itemObj:Object, columnName:String) {
if (itemObj == undefined || columnName == undefined) {
return;
}
var url = "http://localhost/documents/HOME/"+itemObj.url;
var tit = itemObj.tit;
var descrizione = itemObj.descrizione;
var html:String;
switch (columnName) {
case "img" :
html = "<img src=\""+url+"\" vspace=\"2\" hspace=\"2\" width=\"100\">";
return html;
break;
case "desc" :
html = "[b]" + tit + "[/b]
" + descrizione;
return html;
break;
}
};
var xml_array = new Array();
var dp_array = new Array();
var my_ws:WebService = new WebService("http://localhost/WSmy.asmx?WSDL");
var pc:PendingCall = my_ws.prova();
pc.onResult = function(result) {
if (result != "err") {
var _xml:XML=new XML(result);
xml_array = _xml.firstChild.childNodes;
for (var i:Number = 0; i < xml_array.length; i++) {
dp_array.push({tit:xml_array[i].childNodes[1].toString(), descrizione:xml_array[i].childNodes[2].toString()})
}
amazon_grd.rowHeight = 75;
amazon_grd.dataProvider = dp_array;
}
}
// --- DataGrid columns ---
amazon_grd.columnNames = ["img","desc"];
var col:mx.controls.gridclasses.DataGridColumn;
//
col = amazon_grd.getColumnAt(0);
col.width = 200;
col.cellRenderer = "HtmlCellRenderer";
col["htmlFunction"] = amazonHtmlFunction;
col = amazon_grd.getColumnAt(1);
col.width = 400;
col.cellRenderer = "HtmlCellRenderer";
col["htmlFunction"] = amazonHtmlFunction;
import mx.core.UIComponent;
import mx.controls.TextArea;
import TextField.StyleSheet;
class HtmlCellRenderer extends UIComponent
{
static public var CssUrl:String; // Global: URL for CSS stylesheet
static public var style_sheet:StyleSheet = null;
var htmlComponent:TextField;
var owner; // The row that contains this cell
var listOwner : MovieClip; // the reference we receive to the list
var getCellIndex : Function; // the function we receive from the list
var getDataLabel : Function; // the function we receive from the list
var previousLabel:String = null; // for optimization
function HtmlCellRenderer()
{
}
function createChildren(Void) : Void
{
if (CssUrl != undefined && style_sheet == null)
{
style_sheet = new TextField.StyleSheet();
style_sheet.load(CssUrl);
}
if (htmlComponent == undefined)
{
createLabel("htmlComponent", 1);
}
htmlComponent.html = true;
htmlComponent.border = false;
htmlComponent.multiline = true;
htmlComponent.wordWrap = true;
htmlComponent.selectable = false;
htmlComponent.background = false;
htmlComponent.styleSheet = style_sheet;
size();
}
// note that setSize is implemented by UIComponent and calls size(), after setting
// __width and __height
function size(Void) : Void
{
htmlComponent.setSize(__width-2, __height-2);
}
function setValue(str:String, item:Object, sel:Boolean) : Void
{
// Ligne vide ou Header
if (item == undefined)
{
// Special case for headerRenderer
htmlComponent.htmlText = str;
previousLabel = null;
return;
}
var columnIndex = this["columnIndex"]; // private property (no access function)
var columnName = getDataLabel();
var htmlFunction : Function = listOwner.getColumnAt(columnIndex).htmlFunction;
if (htmlFunction != undefined)
{
var label = htmlFunction(item, columnName);
if (label != undefined)
{
// Important pour optimisation
// Empêche un flip-flop des images
if (label != previousLabel)
{
htmlComponent.htmlText = previousLabel = label;
}
}
else
{
htmlComponent.htmlText = "";
}
}
else
{
htmlComponent.htmlText = str;
}
}
function getPreferredHeight(Void) : Number
{
if (owner == undefined) return 18;
return owner.__height - 2;
}
//function getPreferredWidth :: only really necessary for menu
}
è una cosa assurda cercare di fare questo su un componente List invece che sulla DataGrid?
Immagino di no...
ma non riesco nemmeno trovare l'equivalente di import mx.controls.gridclasses.DataGridColumn
le DataGridColumn cosa diventano in un List???
un aiutiinoooo...??
confido in voi ;-)
(all'indirizzo http://philflash.inway.fr/dghtmlrd/dghtmlrd.html c'è l'esempio al quale ho fatto riferimento per la datagrid)