|
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.
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.
|
Rounding up to the nearest timed value - Ex every 15 minutes |
A watercooler moment threw up an interesting dilemma yesterday. I was talking to a colleague about a scheduled application that would run through a timed loop over the course of a day. It would chop off the top N records from a record set and perform an operation on them. Rather than having to manually run the task every 15 minutes, it would be much better to have it run automatically, at 00,15,30 and 45min markers.
So how to do this?
Initial thoughts wandered through various looping-over type conversations, and creating structures of the timed triggers etc.
First stab coding function looks a little something like this:
2function RoundUp(input){
3var roundval = 15;
4var result = 0;
5
6if(ArrayLen(arguments) GTE 2)
7roundval = arguments[2];
8if(roundval EQ 0)
9roundval = 1;
10
11if((input MOD roundval) NEQ 0)
12{
13result = input + (roundval - (input MOD roundval));
14}
15else
16{
17result = input;
18}
19return result;
20}
21</cfscript>
22
23<cfset variables.time = RoundUp(#timeformat(NOW(),"mm")#)>
24<cfoutput>variables.time = #variables.time#</cfoutput>
Which successfully returns a rounded up value to the nearest 15 minutes.
It is a bit long winded though and after some more thought and consultation with more team members another solution was reached.
Which does exactly the same thing! Maybe not as extensible, you can't exactly build it into a dynamic function, but considerably smaller.
|
Redirecting a URL using 301 or 302 |
If I want to redirect a URL I will usually try and do it on the server side, as this seems like the best fit solution to a redirect. It can be done server side, or in code, examples of both are below.
Whether it is an entire site redirect or a page move necessitating a URL redirect there are some small, but key differences in how to do it.
Differences in 301 or 302 redirects
The 302 redirect is a temporary redirect that indicates to browsers and search engines that it is not a permanent change. This is all well and good, but some engines will overlook this due to knowing that it is a temporary change. Google for instance will not index redirects of this type, effectively leaving your users pointed at the wrong URL.
The 301 redirect is a permanent redirect. It is much more search engine friendly, as they will not skip over it. They read it and cache the destination template as the end point, rather than using the redirect url, so saving your users that extra jump.
Implementing the redirect
In IIS:
- In internet services manager, right click on the file or folder you wish to redirect
- Select the radio titled "a redirection to a URL".
- Enter the redirection page
- Check "The exact url entered above" and the "A permanent redirection for this resource" (This makes it a 301 redirect)
- Click on 'Apply'
In code:
2<cfheader name="Location" value="http://www.redirect-url.com">
|
Transferring your contacts to the HTC Magic |
I recently changed my mobile to the HTC Magic. Its Vodafone's first Android powered mobile, full touch screen etc... You can read a full spec here.
I do not usually use Gmail, but the phone was directing me towards them on initialisation, so I thought I'd give it a shot.
Transferring the contacts from my N95 to the HTC Magic isn't possible through the Blu tooth connection, as the HTC's Blu tooth protocol does not support data transfer.
So first thing is to get the Nokia Software.
http://www.nokia.co.uk/get-support-and-software/product-support/nokia-n95/software
Install this and run the backup option. After you have backed up you can select an email client to interface with. I'm Windows through and through, so I sync'd my contacts with Microsoft Outlook.
Once in outlook select 'File' – 'Import and Export'. Depending on your version you may get different options here, but in 2007 its 'Export to a file'. Click next, then select 'Comma separated values (Windows). Next select your contacts (or more if you want) and press next. Your data will be exported as a CSV.
Once in outlook select 'File' – 'Import and Export'. Depending on your version you may get different options here, but in 2007 its 'Export to a file'. Click next, then select 'Comma separated values (Windows). Next select your contacts (or more if you want) and press next. Your data will be exported as a CSV.
So a bit long winded, but it works!