DAN ZEN EXPO - CODE EXHIBIT -
HUMMINGBIRD
package samples {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.net.URLRequest;
// see the HummingBird.as file located at the path below for instructions on installing classes
import com.danzen.effects.HummingBird;
// HUMMINGBIRD INTRODUCTION
// HummingBird is a simple class that moves a clip relative to the mouse
// if the clip has 3D in it then parallax will occur
// http://hummingbirdflash.wordpress.com - by inventor Dan Zen - http://www.danzen.com
// if you are using HummingBird for commercial purposes, you are welcome to donate to Dan Zen
// donations can be made to agency@danzen.com at http://www.paypal.com
// USING HUMMINGBIRD
// please make sure that com/danzen/effects/HummingBird is in a folder in your class path
// ADDING DEPTH WITH Z IN FLASH
// Currently (CS4) z is a little awkward
// everything seems to be relative to the origin when repositioning
// this could have something to do with the vanishing point or camera
// but I found I could never nest a 3D space without it readjusting to stage 0,0
// even if I brought a 3D space in through another swf
// so... make a holder MovieClip and make sure it is at the origin
// then put things inside it and under 3D POSITION AND VIEW set the z
// set the z of background objects at around 1000 and mid objects at 500
// leave the z of your forground objects at 0
// then resize the background objects to be the right size again (scale them up)
// once you have the arrangement how you like it... apply HummingBird to the holder
// HummingBird just moves the holder around relative to the mouse
// The parallax happens because of the z - yay
// CONSTRUCTOR
// HummingBird(obj:DisplayObject, shiftX:Number, shiftY:Number, shiftZ:Number, damping:Number):void
// constructor to start animating clip to mouse movement
// PARAMETERS:
// obj:DisplayObject
// a MovieClip for instance with clips inside arranged in Z property
// shiftX:Number
// how much it moves in the x
// shiftZ:Number
// how much it moves in the Y
// shiftY:Number
// how much it moves in the Z (up is closer down is farther)
// damping:Number
// how slowly it follows your mouse - 1 is fast 0 it does not move
// EVENTS
// no events
// METHODS
// dispose()
// stop tracking the mouse
// PROPERTIES
// no properties
public class DanZen extends MovieClip {
private var menus:Array;
private var icons:Array;
private var pre:MovieClip;
public function DanZen() {
// HummingBird class to make the holder float around
// for parallax, the holder has objects with z properties set
// object, shiftX, shiftY, shiftZ, damping
new HummingBird(holder, 30, 10, 18, .1);
// the rest has nothing to do with HummingBird ;-)
menus = [holder.p_inventor, holder.p_danzen, holder.p_cnma, holder.p_agencyzen, holder.p_sheridan];
for (var i:uint=0; i<menus.length; i++) {
menus[i].buttonMode = true;
menus[i].mouseChildren = false;
menus[i].addEventListener(MouseEvent.CLICK, clickMe);
}
pre = holder.p_site.site.thumbs;
icons = [pre.saveearth, pre.opartica, pre.spymail, pre.moustachemysteries, pre.teleporters, pre.hipcats];
for (var j:uint=0; j<icons.length; j++) {
icons[j].buttonMode = true;
icons[j].mouseChildren = false;
icons[j].addEventListener(MouseEvent.CLICK, clickMe);
}
}
private function clickMe(e:MouseEvent) {
if (e.target == holder.p_inventor) {navigateToURL(new URLRequest("http://www.danzen.com/inventor"));}
if (e.target == holder.p_danzen) {navigateToURL(new URLRequest("http://www.danzen.com"));}
if (e.target == holder.p_cnma) {navigateToURL(new URLRequest("http://www.cnma.ca/index_e/"));}
if (e.target == holder.p_agencyzen) {navigateToURL(new URLRequest("http://www.agencyzen.com"));}
if (e.target == holder.p_sheridan) {navigateToURL(new URLRequest("http://imm.sheridanc.on.ca"));}
if (e.target == pre.saveearth) {navigateToURL(new URLRequest("http://www.danzen.com/saveearth"));}
if (e.target == pre.opartica) {navigateToURL(new URLRequest("http://www.opartica.com"));}
if (e.target == pre.spymail) {navigateToURL(new URLRequest("http://www.spy-mail.com"));}
if (e.target == pre.moustachemysteries) {navigateToURL(new URLRequest("http://www.moustachemysteries.com"));}
if (e.target == pre.teleporters) {navigateToURL(new URLRequest("http://www.danzen.com/teleporters"));}
if (e.target == pre.hipcats) {navigateToURL(new URLRequest("http://www.hipcats.com"));}
}
}
}
package com.danzen.effects {
// HUMMINGBIRD INTRODUCTION
// HummingBird creates a parallax effect on a MovieClip or Sprite
// http://hummingbirdflash.wordpress.com - by inventor Dan Zen - http://www.danzen.com
// if you are using HummingBird for commercial purposes, you are welcome to donate to Dan Zen
// donations can be made to agency@danzen.com at http://www.paypal.com
// INSTALLING CLASSES
// suggested installation:
// create a "classes" folder on your hard drive - for example c:\classes
// add the classes folder to your Flash class path:
// Flash menu choose Edit > Preferences > ActionScript - ActionScript 3 Settings
// then use the + sign for the source path box to add the path to your classes folder
// put the provided com/danzen/ directory with its folders and files in the classes folder
// the readme has more information if you need it
// USING HUMMINGBIRD
// make a "holder" MovieClip for instance that has other MovieClips or TextFields, etc. inside it
// set the z properties of the MovieClips and TextFields
// in your document class make a new HummingBird Object
// and pass the holder MovieClip in as the first parameter
// you should see your content move around to your mouse with a parallax effect
// EVENTS
// no events
// METHODS
// dispose()
// stop tracking the mouse
// PROPERTIES
// shiftX, shiftY, shiftZ : Number
// how much you are shifting on these axes.
// can set in constructor
// damping:Number
// the damping - .1 is good .01 is slower and .001 is good for sliding sites
// can set in constructor
// randomize:Number
// randomizes motion
// simulates random clicking from top then middle then top, etc.
// randomly chooses x position
// 0 is no random motion, 1 is infrequent clicks and 10 is most frequent
// good for automatically animating your scene
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.display.MovieClip;
import flash.events.*;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.utils.Timer;
public class HummingBird extends MovieClip {
private var sW:Number;
private var sH:Number;
private var startX:Number;
private var startY:Number;
private var startZ:Number;
public var shiftX:Number;
public var shiftY:Number;
public var shiftZ:Number;
public var damping:Number;
private var mouseDownObject:DisplayObject;
private var holder:DisplayObject;
private var mouseCheck:Boolean = false;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var myRandomize:Number = 0;
private var myRandomCount:Number = 0;
private var mySpeedCount:Number = 0;
// CONSTRUCTOR
// HummingBird(obj:DisplayObject, shiftX:Number, shiftY:Number, shiftZ:Number, damping:Number, mouseDownObject:InteractiveObject):void
// constructor to start animating clip to mouse movement
// PARAMETERS:
// obj:DisplayObject
// a MovieClip for instance with clips inside arranged in Z property
// shiftX:Number
// how much it moves in the x
// shiftZ:Number
// how much it moves in the Y
// shiftY:Number
// how much it moves in the Z (up is closer down is farther)
// damping:Number
// how slowly it follows your mouse - 1 is fast 0 it does not move
// mouseDownObject:InteractiveObject
// if you want to click and drag to make motion pass in a MovieClip or Sprite
public function HummingBird(theObject:DisplayObject, theShiftX:Number=10, theShiftY:Number=10, theShiftZ:Number=10, theDamping:Number=.1, theMouseDownObject:InteractiveObject=null) {
trace ("hi from HummingBird 3a");
holder = theObject;
shiftX = theShiftX;
shiftY = theShiftY;
shiftZ = theShiftZ;
damping = theDamping;
mouseDownObject = theMouseDownObject;
var myTimer:Timer = new Timer(200);
myTimer.addEventListener(TimerEvent.TIMER, checkStage);
myTimer.start();
}
private function checkStage(e:TimerEvent) {
if (!holder.stage) {return;}
Timer(e.currentTarget).stop();
holder.stage.scaleMode = StageScaleMode.NO_SCALE;
holder.stage.align = StageAlign.TOP_LEFT;
sW = holder.stage.stageWidth;
sH = holder.stage.stageHeight;
startX = holder.x;
startY = holder.y;
startZ = holder.z;
holder.stage.addEventListener(Event.ENTER_FRAME, moveScene);
if (mouseDownObject) {
mouseDownObject.addEventListener(MouseEvent.MOUSE_DOWN, doMouseDown, false, 0, true);
mouseDownObject.stage.addEventListener(MouseEvent.MOUSE_UP, doMouseUp, false, 0, true);
}
}
private function doMouseDown(e:MouseEvent) {
lastMouseX = mouseX;
lastMouseY = mouseY;
mouseCheck = true;
}
private function doMouseUp(e:MouseEvent) {
mouseCheck = false;
}
private function moveScene(e:Event) {
var proxyDamping:Number;
if (myRandomize == 0) {
// mac mouse issue going to other windows!
if (mouseY > sH * 10 || mouseX > sW * 10) {return;}
if (mouseDownObject && isNaN(lastMouseX)) {return;}
if (!(mouseDownObject && mouseCheck == false)) {
// if mouse up needs to glide to last x and y during mouse down
if (isNaN(lastMouseX)) {
lastMouseX = sW/2;
lastMouseY = sH/2;
} else {
lastMouseX = mouseX;
lastMouseY = mouseY;
}
}
proxyDamping = damping;
} else { // automatically running with randomize going from 0 (off) to 1 (slow) to 10 (fast)
proxyDamping = .005*Math.pow(myRandomize,1.2);
if (mySpeedCount % Math.floor(600/Math.pow(myRandomize,1.3)) == 0) {
//if (Math.random()*300/myRandomize <= 1) {
myRandomCount++;
if (myRandomCount%2==0) {
if (mouseDownObject) {
lastMouseY = mouseDownObject.y + Math.random()*mouseDownObject.height/4;
} else {
lastMouseY = Math.random()*holder.stage.stageHeight/4;
}
} else {
if (mouseDownObject) {
lastMouseY = mouseDownObject.y + mouseDownObject.height*1/4 + Math.random()*mouseDownObject.height/4;
} else {
lastMouseY = holder.stage.stageHeight*1/4 + Math.random()*holder.stage.stageHeight/4;
}
}
if (mouseDownObject) {
lastMouseX = mouseDownObject.x + Math.random()*mouseDownObject.width;
} else {
lastMouseX = Math.random()*holder.stage.stageWidth;
}
}
mySpeedCount++;
}
var newX = startX + (lastMouseX - sW/2) / (sW/2) * shiftX;
var newY = startY + (lastMouseY - sH/2) / (sH/2) * shiftY;
var newZ = startZ + (lastMouseY - sH/2) / (sH/2) * shiftZ;
var diffX = newX - holder.x;
var diffY = newY - holder.y;
var diffZ = newZ - holder.z;
if (Math.abs(diffX) >= 2) {
holder.x = holder.x + diffX * proxyDamping;
}
if (Math.abs(diffY) >= 2) {
holder.y = holder.y + diffY * proxyDamping;
}
if (Math.abs(diffZ) >= 2) {
holder.z = holder.z + diffZ * proxyDamping;
}
}
public function set randomize(n:Number):void {
myRandomize = Math.max(Math.min(n,10),0);
trace (myRandomize)
}
public function get randomize():Number {
return myRandomize;
}
public function dispose() {
holder.stage.removeEventListener(Event.ENTER_FRAME, moveScene);
}
}
}