views:

878

answers:

1

Does anyone know if there is a simple way of catching the hovered link url in an AIR HTML control? Just like in a browser, I would like the url to be displayed in a status bar but I can't find any event that is raised on rollover of a link. Do you I need to inspect and perhaps manipulate the DOM myself for that?

+2  A: 

Assuming you're using mx:HTML or HTMLLoader, you'll probably have to write a little script of your own to wire the DOM objects up to the AIR container. Here's one way to do it -- there's probably a more elegant solution out there, but for purposes of illustration, it should suffice.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1024" height="768" xmlns:html="flash.html.*" horizontalScrollPolicy="off">

    <mx:Script>
     <![CDATA[

      private function container_complete(event:Event):void
      {
       addHTMLListeners();
      }

      private function addHTMLListeners():void
      {
       var links:Object = container.htmlLoader.window.document.getElementsByTagName("a");

       for (var i:int = 0; i < links.length; i++)
       {
        if (links[i].href != "")
        {
         var href:String = links[i].href;

         links[i].onmouseover = function():void { setStatus(this); };
         links[i].onmouseout = function():void { clearStatus() };
        }
       }
      }

      private function setStatus(o:Object):void
      {
       status = o.href;
      }

      private function clearStatus():void
      {
       status = "";
      }

     ]]>
    </mx:Script>

    <mx:HTML id="container" location="http://stackoverflow.com/users/32129" width="100%" height="100%" complete="container_complete(event)" />

</mx:WindowedApplication>

Hope it helps!

Christian Nunciato
Excellent, just what I was looking for. Thanks Christian!
Christophe Herreman
You are welcome sir!
Christian Nunciato