Skip to content

Instantly share code, notes, and snippets.

@didierbrun
Created December 29, 2009 20:41
Show Gist options
  • Save didierbrun/265582 to your computer and use it in GitHub Desktop.
Save didierbrun/265582 to your computer and use it in GitHub Desktop.
/**
*
*
* Lunette
*
* @author Didier Brun
* @version 1.0
*
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class Lunette extends Sprite {
// ------------------------------------------------
//
// ---o properties
//
// ------------------------------------------------
public var tourelleh : TourelleHorizontale;
// ------------------------------------------------
//
// ---o constructor
//
// ------------------------------------------------
function Lunette(){
addEventListener(Event.ADDED_TO_STAGE, init);
}
// ------------------------------------------------
//
// ---o public methods
//
// ------------------------------------------------
// ------------------------------------------------
//
// ---o private methods
//
// ------------------------------------------------
/**
* init
*/
private function init(e:Event):void{
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
}
/**
* key down
*/
private function keyDown(e : KeyboardEvent) : void {
switch (e.keyCode){
case Keyboard.UP:
tourelleh.clic(1);
break;
case Keyboard.DOWN:
tourelleh.clic(-1);
break;
}
}
}
}
/**
*
*
* TourelleHorizontale
*
* @author Didier Brun
* @version 1.0
*
*/
package {
import aze.motion.eaze;
import flash.display.Sprite;
public class TourelleHorizontale extends Sprite {
// ------------------------------------------------
//
// ---o properties
//
// ------------------------------------------------
public static const MAX_VALUE:int=240;
public var bande:Sprite;
public var infos:Sprite;
public var yellow : Sprite;
private var _position:Number=0;
// ------------------------------------------------
//
// ---o constructor
//
// ------------------------------------------------
function TourelleHorizontale(){
yellow.alpha=0;
infos.alpha=0;
infos['label'].text = _position;
}
// ------------------------------------------------
//
// ---o public methods
//
// ------------------------------------------------
/**
* clic
*/
public function clic(v:Number):void {
// ajouter le clic à la position
_position+= v;
// la molette tourne, vérifier les dépassements
if (_position < 0)_position += MAX_VALUE;
if (_position>=MAX_VALUE)_position -= MAX_VALUE;
// modifier la position de la bande
bande.x = -_position*2+1;
// mettre à jour et faire apparaitre les infos
infos['label'].text=_position;
eaze(infos).to(.5,{alpha:1}).onComplete(hideInfos);
// afficher ou non le bloc jaune
if (_position>MAX_VALUE/2){
eaze(yellow).to(.5,{alpha:1});
}else{
eaze(yellow).to(.5,{alpha:0});
}
}
// ------------------------------------------------
//
// ---o private methods
//
// ------------------------------------------------
/**
* hide infoss
*/
private function hideInfos():void{
// attendre 2 secondes avant de masquer infos
eaze(infos).delay(2).to(.5,{alpha:0});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment