Shaun Mccran

My digital playground

12
J
U
N
2009

Opening a new window from a flex / AIR application

I was sure I had done this before, somewhere but I couldn't find the code anywhere. So I've knocked together a really quick and simple example.

I want to be able to open a new site in a pop up from an AIR application. To do this I need to use the 'urlRequest' function to create a url request. Then insert that into a 'navigateToURL' method, specifying that you want a new window '_new'.

Here is the complete example.

view plain print about
1<?xml version="1.0" encoding="utf-8"?>
2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
3
4<mx:Script>
5    <![CDATA[
6
7     public function goToUrl(link:String):void
8     {
9        var urlRequest:URLRequest = new URLRequest('http://' + link);
10
        navigateToURL(urlRequest, "
_new");
11     }
12        
13    ]]>
14</mx:Script>
15    
16    <mx:Canvas x="10" y="10" width="321" height="146" backgroundColor="#FFFFFF">

17        <mx:Form x="10" y="52">

18            <mx:FormItem label="URL">

19                <mx:TextInput id="urlTxt"/>
20            </mx:FormItem>
21        </mx:Form>
22        <mx:Button x="10" y="114" label="Go to" click="goToUrl(urlTxt.text)"/>
23        <mx:Label x="10" y="10" text="New Window test" />
24    </mx:Canvas>
25    
26</mx:Application>

Works like this.

View demo.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top