contact

Posts Tagged ‘Actionscript’

adding Mac OS X like Application Behaviour to your Air Application

Tuesday, March 31st, 2009

In Mac OS X when you close the window of an application the app usually keeps running in the dock. Wheter this is a good thing or not is totally different story, but for apps like mail and ical it certainly is since I want my mail app to keep checking for new mail without the window cluttering up my screen. So what if I want to add such behaviour to an Adobe Air Application.

 	var appIsPersistant:Boolean=false
 	var app=NativeApplication.nativeApplication
 	var window=stage.nativeWindow;

public function set appPersistant(b:Boolean):void{ // adding a simple property to your app b:Boolean whether its stays on or not
 appIsPersistant=b
 	if(b){
 		if(app!=null){
 			app.autoExit=false // preventing the app to exit if all windwows are closed
 			window.addEventListener(Event.CLOSING,hideWindow) // listening for the closing event of the main window
 			app.addEventListener(InvokeEvent.INVOKE,initWindow) // listening for the invoke event if the user clicks on the dock icon
 			app.addEventListener(Event.EXITING,appClose) // listening if the app should be terminated, to prevent the hiding of the window and allow termination
 		}
 	}else{
 		if(app!=null){
 		app.autoExit=true // if app is not persistant the app can close just as usual
 		}
 	}
 }
 public function appClose(e:Event):void{
 	window.removeEventListener(Event.CLOSING,hideWindow) // if the app should terminate with command + Q we have to remove the listener for the Closing event. Otherwise only the window will close but the app will not terminate
 }
 public function hideWindow(e:Event):void{
 	if(window.visible){ // if the window is visible the event behaviour is canceld and the window is hidden
 		e.preventDefault()
 		window.visible=false
 	}
 }
 function initWindow(e:Event=null):void{
 	window.activate() // if the user clicks on the dock icon the window commes back up
 }
 public function get appPersistant():Boolean{
 	return appIsPersistant // just the getter for the appPersistant propery
 }

by adding these few methods your app will exit just fine with command + Q but if you click the close button only the window will close and the app keeps running and comes back up if you click the dock icon

calculating the number of days between two dates

Sunday, November 9th, 2008

for a recent project I had to figure out how many days are between a given start and end date. My first very poor attempt was to split the dates and then get the monthes and then add up the days for each month. Very poor on performance.

The easy solution:

most modern programming languages offer Dates Objects that can handle timestamps, which makes our calculation very easy.

(Timestamp(endDate)-TimeStamp(startDate)) / 3600 / 24 = days

this will compute the amount of seconds between the start and end date, then divide by 3600 gives you get hours, divide by 24 and you have the number of days. This is especially nice since it automatically considers 29th of february.

note: if you use actionscript you have to again divide by 1000 since its timestamps are in milli seconds.

actionscript 3 screenshot

actionscript 3 screenshot

www.odem.eu

Tuesday, March 18th, 2008

I just finished the makeover of the web appearance of  the clothing company odem. Since their distribution is working via ebay, I am creating a flash app that is reading the ebay rss feed of their store and displays their catalog of products in their corporate layout. That way the catalog is automatically kept up to date.www.odem.eu  this is a screenshot of the old site.