Opening a new browser window by double clicking an Image control in Flex

by Peter deHaan on November 9, 2008

in ActionScript, Image

The following example shows how you can open a new browser window/tab by double clicking a Flex Image control by setting the doubleClickEnabled property to true and calling the navigateToURL() method

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/09/opening-a-new-browser-window-by-double-clicking-an-image-control-in-flex/ -->
<mx:Application name="Image_doubleClick_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import flash.net.navigateToURL;

            private function img_doubleClick(evt:MouseEvent):void {
                var src:String = evt.currentTarget.source;
                var urlReq:URLRequest = new URLRequest(src);
                navigateToURL(urlReq, "_blank");
            }
        ]]>
    </mx:Script>

    <mx:Image id="img1"
            source="http://www.helpexamples.com/flash/images/image1.jpg"
            doubleClickEnabled="true"
            doubleClick="img_doubleClick(event);" />

    <mx:Image id="img2"
            source="http://www.helpexamples.com/flash/images/image2.jpg"
            doubleClickEnabled="true"
            doubleClick="img_doubleClick(event);" />

</mx:Application>

{ 5 comments… read them below or add one }

1 amar shukla November 9, 2008 at 8:17 pm

It works only for IE , not for Mozilla or safari .

Reply

2 noj November 10, 2008 at 12:01 am

it works in chrome and mozilla :), not sure about safari.

you have a great blog there, even though the examples are simple, they save hours of debugging, and looking through the flex docs. keep up the good work.

Reply

3 Automotive CRM Expert November 11, 2008 at 5:08 pm

Safari? Who uses Safari anyways?

Reply

4 nappy155 February 19, 2009 at 5:48 pm

i recently completed my first paid full flex site…your blog has been a HUGE help in it’s development…..THANX

Reply

5 smyrin March 3, 2009 at 7:06 am

I have linked using a button and the img tag and they both work for all three browsers. On a side note, I did not use a mouseEvent to trigger the function. Instead I just passed a string to a function and used the string as the site variable of URLRequest object.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: