
Feed, care and play with your new desktop friend- the cyber pet. Keeps you company while you work.
Your new pet will let you know when he is hungry or thirsty. You can give him treats and make him do tricks.
This application uses Adobe Air 1.0 and was created in Flash CS3 using Actionscript 3. Cyber pet specifically utilizes the
NativeWindow class which allows the user to access the window of the application. The NativeWindow class
allows the user of Cyber Pet to drag the application window around the desktop, to maximize to fullScreen, minimize to the original and to close the
application. All other functions of the Cyber Pet are created with standard drag and drop, enter frame, and timer events.
I began by importing the following air classes:
import flash.display.NativeWindow;
The NativeWindow Class
provides an interface for creating and controlling native desktop windows.
import flash.display.NativeWindowDisplayState;
The NativeWindowDisplayState defines constants for the names of the native window display states.
I then added the following event listeners:
bkground.addEventListener(MouseEvent.MOUSE_DOWN, dragMovie);
closeWinBtn.addEventListener(MouseEvent.CLICK, closeDog);
maxBtn.addEventListener(MouseEvent.CLICK, fullScreen);
minBtn.addEventListener(MouseEvent.CLICK, fullScreen);
The dragMovie function used to drag the window around is similar to a standart AS3 drag and drop except it uses the
nativeWindow class and does not require a stopDrag.
private function dragMovie(e:MouseEvent) {
stage.nativeWindow.startMove();
}
The fullScreen function receives the mouse click event and closes the window:
private function closeDog(e:MouseEvent) {
stage.nativeWindow.close();
}
The fullScreen function receives the mouse click event and checks to see if the window is maximized. If it is not, it utilizes the
NativeWindowDisplayState class with the property Maximized and displays the window as such. If the screen is already
maximized it will display the screen as Minimized. Height, width x and y of the window are also set.
private var fullCheck:Boolean = false;
private var preFullX:Number;
private var preFullY:Number;
private var preFullW:Number;
private var preFullH:Number;
private var preFullType:String;
private var chromeEdge:Number;
private var chromeTop:Number;
private function fullScreen(e:MouseEvent) {
if (fullCheck) {
fullCheck = false;
if (preFullType == NativeWindowDisplayState.MAXIMIZED) {
} else {
stage.nativeWindow.x = preFullX;
stage.nativeWindow.y = preFullY;
stage.nativeWindow.width = preFullW;
stage.nativeWindow.height = preFullH;
}
} else {
preFullX = stage.nativeWindow.x;
preFullY = stage.nativeWindow.y;
preFullW = stage.nativeWindow.width;
preFullH = stage.nativeWindow.height;
preFullType = stage.nativeWindow.displayState;
fullCheck = true;
if (stage.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED) {
stage.nativeWindow.width = Capabilities.screenResolutionX;
} else {
stage.nativeWindow.width = Capabilities.screenResolutionX;
}
stage.nativeWindow.height = Capabilities.screenResolutionY + chromeTop + chromeEdge;
}
}
All other functions are done with standard flash functionality. Timers are set to make the dog hungry or thirsty every 30 min. He will then bark at you
until he is fed. Many other functions are possible with cyber pet but you get the general idea.