3 Replies Latest reply on Dec 4, 2009 6:34 AM by lee704

    How to open a link by clicking on a DataGrid row

    lee704 Level 1

      I have a list of documents that are accessible over the internet.  The list is in an XML file which serves as the data source for a DataGrid.  What I cannot figure out is how to open the document selected in the DataGrid.  I think that I need to change something in the openDocument function (below) but I am not certain what I should change.  Any help would be appeciated.

       

      Sample file are below:

       

      Application

      viewDocuments.mxml

       

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

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

      layout="absolute"

      creationComplete="initApp();">

      <mx:Script>

      <![CDATA[

      import mx.collections.ArrayCollection;

      import mx.rpc.events.ResultEvent;

      import mx.core.Application;

       

      [Bindable]

      private var documents:ArrayCollection;

       

      private function initApp():void

      {

      this.srv.send();

      }

       

      private function onResult(evt:ResultEvent):void

      {

      this.documents=evt.result.data.document;

      }

       

      private function openDocument():void

      {

      var docURL:String;

      docURL=dgDocuments.selectedItem.url;

      navigateToURL(new URLRequest("http://cnn.com/"), "_blank");

      //Below does not work

      //navigateToURL(new URLRequest("docURL"), "_blank");

      }

      ]]>

      </mx:Script>

       

      <mx:HTTPService id="srv"

      url="documents.xml"

      resultFormat="object"

      result="onResult(event)"/>

       

      <mx:Canvas id="cViewDocumentsContainer"

      x="0"

      y="0"

      width="100%"

      height="100%">

       

       

      <mx:DataGrid id="dgDocuments"

      width="600"

      height="186"

      dataProvider="{documents}"

      x="15"

      y="74"

      doubleClickEnabled="true"

      doubleClick="openDocument();">

      <mx:columns>

      <mx:DataGridColumn headerText="DocID"

      dataField="doc_id"

      visible="true"/>

      <mx:DataGridColumn headerText="Name"

      dataField="name"

      visible="true"

      width="200"/>

      <mx:DataGridColumn headerText="Type"

      dataField="type"

      visible="true"

      width="90"/>

      <mx:DataGridColumn headerText="File Name"

      dataField="filename"

      visible="true"/>

      <mx:DataGridColumn headerText="Path"

      dataField="url"

      visible="true" width="200"/>

      </mx:columns>

      </mx:DataGrid>

      <mx:Text x="10"

      y="10"

      text="View Documents"

      fontSize="12"

      fontWeight="bold"/>

      <mx:Text x="15"

      y="48"

      text="Double-click on the document below you want to read. The document will open in a new window."/>

      </mx:Canvas>

      </mx:Application>

       

      Data

      documents.xml

       

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

      <data>

      <document>

      <doc_id>1</doc_id>

      <name>CNN</name>

      <type>URL</type>

      <filename>CNN.com</filename>

      <url>http://cnn.com/</url>

      </document>

      <document>

      <doc_id>2</doc_id>

      <name>Yahoo</name>

      <type>URL</type>

      <filename>Yahoo.com</filename>

      <url>http://yahoo.com/</url>

      </document>

      </data>

       

      Thanks!

      Lee