Skip to main content
Inspiring
January 3, 2013
Question

Surely this is possible dataGrid html link..but suspicious absence on forum and net.

  • January 3, 2013
  • 1 reply
  • 746 views

Hi,

Flash CS5 AS3

Having googled what I thought would have many instances of how its done, I have gotten nowhere, as have others with no replies to their postings.

Google shows nothing for as3;  flex3 forum has something but we are not using flex.

Is it possible to have a dataGrid and text for websites in cells that when clicked on go to that URL ?

Has Adobe overlooked the ability to create a hyperlink from a url in a cell ?

My situation. We have a dataGrid populated from a csv file. col1 has bus service number, nothing shows for that. col2 to 6 have settlement names and display MC's, col7 and col8 have url's which we want as hyperlinks, one goes to a timetable the other to a very detailed map.

Currently we have it that click on row outputs data from all cells in that row. Sttmnt names are output less gaps and apostrophes and code appends _Layer2 or _Layer3 depending on where they are in the map display hierarchy. Output tab also shows it identifying the col1 data which are service numbers, but there doesnt seem to be a need to disable that as its not causing any problems despite there being no matching MC's !

We also see the two url's output. They are however stripped of // gaps and full stops 

We dont want any websites being launched until user deliberately clicks the cell in col7 or col8.

How is this done ? i.e what is the code to make a hyperlink from a cell ?

In with this we also need to tell the code to ignore col7 and 8 on click that shows up the sttmnts and appends _Layer2 or _Layer3 yet accept a click when made in col7 or col8 and not to strip out the characters and gaps and not to append _Layer2 or _Layer3.

Just what should this code below be to accomplish this ?

our code thus far:-

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.DataGrid;
import fl.events.ListEvent

makeAllVisibleF(false);

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("BusMapHyperlinks_txtMatchMCv3.csv"));
var dg:DataGrid

//---------------------------------------------------------------------------------------------------

function completeF(e:Event):void{
    var dataS:String = e.target.data;
    var dataA:Array = dataS.split("\n").join("").split("\r");
    var dpA:Array = [];
    var itemA:Array;
var r:RegExp = /\W/g;
    for(var i:int=0;i<dataA.length;i++){
        itemA = dataA.split(",");

         dpA.push({"col1":itemA[0],"col2":itemA[1],"col3":itemA[2],"col4":itemA[3],"col5":itemA[4],"col6":itemA[5],"col7":itemA[6],"col8":itemA[7]});
}

var dp:DataProvider = new DataProvider(dpA);
    dg.columns = ["col1","col2","col3","col4","col5","col6","col7","col8"]
dg.columns[0].width = 57;
    dg.columns[1].width = 182;
    dg.columns[2].width = 143;
    dg.columns[3].width = 90;
    dg.columns[4].width = 110;   
dg.columns[5].width = 65;   
dg.columns[6].width = 62;   
dg.columns[7].width = 30;
    dg.dataProvider = dp;
}

dg.addEventListener(ListEvent.ITEM_CLICK,dgClickF);
function dgClickF(e:ListEvent):void{
trace(e.columnIndex, e.rowIndex);

}

dg.addEventListener(ListEvent.ITEM_CLICK,ShowSymbols);

function ShowSymbols(e:ListEvent):void{
makeAllVisibleF(false);
var r:RegExp = /\W/g;
for(var s:String in e.item){
if(e.item){
var clipName :String = String(e.item).replace(r,"")+currentLevel;
trace(clipName)
if(Map_Collection[clipName]){
Map_Collection[clipName].visible=true;
}
trace(s,e.item)
trace(currentLevel)


}

}

}

function makeAllVisibleF(b:Boolean):void{


Map_Collection.MitresGate_Level2.visible=b;
Map_Collection.MitresGate_Level3.visible=b;

and many more names !!!

Envirographics

This topic has been closed for replies.

1 reply

sinious
Legend
January 3, 2013

List-esque components such as List, DataGrid, etc can use a CellRenderer to display contents in any custom fashion you like. You really should learn how to make your own cell renderer for your component so it displays your content properly and acts properly based upon any circumstances you want.

Here's an Adobe link going over the concept. It's pretty important for you to learn to effectively use components and it will get you what you need:

http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fd4.html

Inspiring
January 4, 2013

Hi,

Thanks for the advice, will do, sounds interesting and useful.

There seems to be a lot on dataGrids and xml but little on dataGrids and csv which is blinding us a bit.

We arrived at the following solution after a lucky find with yet more googling, that seems to work, not sure if its the most suitable but here it is:-

dg.addEventListener(ListEvent.ITEM_CLICK,dgClickF);

function dgClickF(e:ListEvent):void{

//trace(e.columnIndex, e.rowIndex)

//trace("Focus has left row: " +e.rowIndex + " col: " + e.columnIndex)

if (e.columnIndex == 6 || e.columnIndex == 7){

var cellData = e.target.columns[e.columnIndex].itemToLabel(e.target.getItemAt(e.rowIndex));

//trace(cellData)

var url : String = cellData;

var targetURL:URLRequest = new URLRequest(url);

navigateToURL(targetURL,"_blank")};

}

Placed it in before the ITEM_CLICK code.

Envirographics

sinious
Legend
January 5, 2013

Converting data between formats is a very common thing. CSV is just text that needs to be split to make it a useful format, XML is already in an unserialized useful format. You can use normal String functions with either for your data.

Glad you found your solution nontheless. Do have a look at cell rendering if you get a chance. The concept isn't just for a single component and it extends well beyond flash components into many other languages components as well.

Good luck!