Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to setup a click even in DataGrid?

New Here ,
Jan 06, 2013 Jan 06, 2013

Hi there!

I have a very simple DG that loads local xml data, then i am trying to add a click event to the items. on clicking a list item it should take to a web site. Here is the code. It is now working. Sure you can guide me, please.

--------------------------

import fl.data.DataProvider;

import fl.controls.dataGridClasses.DataGridColumn;

import fl.events.ListEvent;

mydg.move(15, 50);

mydg.setSize(530, 230);

var col_name:DataGridColumn = new DataGridColumn("titl");

col_name.headerText = "Title";

mydg.addColumn(col_name);

var col_job:DataGridColumn = new DataGridColumn("cat");

col_job.headerText = "category";

mydg.addColumn(col_job);

mydg.columns[0].width = 330;

mydg.columns[1].width = 200;

var leadData_xml:XML;

var dp:DataProvider = new DataProvider();

var urlRequest:URLRequest = new URLRequest("xleadata.xml");

var urlLoader:URLLoader = new URLLoader();

urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);

urlLoader.load(urlRequest);

function urlLoader_complete(evt:Event):void {

    leadData_xml = new XML(evt.target.data);

          //trace(leadData_xml.toXMLString());

          mydg.dataProvider = new DataProvider(leadData_xml);

          mydg.addEventListener(ListEvent.ITEM_CLICK, cHandler);

}

function cHandler(e:ListEvent):void{

          var leadpath:String = e.item.data;

          trace(leadpath.toString());

}

///////////////// xml /////////////////

<?xml version="1.0" encoding="UTF-8"?>

<leadata>

          <lead>

                    <titl>AS Examples</titl>

                    <cat>Code Samples</cat>

                    <lnk>http://actionscriptexamples.com/</lnk>

          </lead>

          <lead>

                    <titl>Flex Examples</titl>

                    <cat>Code Samples</cat>

                    <lnk>http://blog.flexexamples.com/</lnk>

          </lead>

          <lead>

                    <titl>GotoandLearn</titl>

                    <cat>Tutorials</cat>

                    <lnk>http://www.gotoandlearn.com/</lnk>

          </lead>

</leadata>

-----------------------------------------

Thanks

kristtee

TOPICS
ActionScript
522
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2013 Jan 06, 2013

use:

function cHandler(e:ListEvent):void{

  

navigateToURL(new URLRequest(e.item.lnk));

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 07, 2013 Jan 07, 2013
LATEST

Hi Kglad

Thank you appreciate your help. I added the code as you have told. When testing , it worked first time. then it doesnot work anymore. Also I tryied to open the lnk into a new tab in FFox / Crome/IE. it does not work anymore. I wonder what is happening? Please guide me.

Thanks

kristtee

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines