home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_07
/
DSS145_07.swf
/
scripts
/
dss145_07
/
Taureau.as
< prev
next >
Wrap
Text File
|
2012-07-18
|
9KB
|
316 lines
package dss145_07
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
import flash.utils.getTimer;
public class Taureau
{
public static const STOPPED:int = 0;
public static const RUNNING:int = 1;
public static const EJECT:int = 2;
public static const READY_TO_PICK:int = 3;
private var _movie:MovieClip;
public var state:int = 0;
private var speed:Number = 1;
private var _timer:Timer;
private var _lastTime:int = 0;
private var _actualTime:int = 0;
private var _metreSecondes:Number = 0;
private var _pixelSecondes:Number = 0;
private var fps:Number = 0;
private var _frameDuration:Number = 0;
private var equivalentUnMetreEnPixels:Number = 100;
private var distancePixelParFrame:Number = 10;
public var delaiDecrochage:Number = 2000;
public var delaiAcrochage:Number = 12000;
public var delayToClic:Number = 2000;
public var distanceSeuilPx:Number = 15;
private var frameToReach:int;
public var onRunning:Function;
private var pt:Point;
private var ptMouse:Point;
public var timeToPeakExceed:Boolean = false;
private var _lastFrameCalcul:Number = 1;
private var isOn:Boolean = false;
public var eject:Boolean = false;
public var readyToPick:Boolean = false;
public var isPicked:Boolean = false;
public var acrochageTime:Number;
private var decroche:Boolean = false;
private var _timeDecrochage:Number = 0;
private var _timeAcrochage:Number = 0;
private var _timeActual:Number = 0;
public function Taureau(param1:MovieClip)
{
this._timer = new Timer(20);
this.onRunning = function():void
{
};
this.pt = new Point();
this.ptMouse = new Point();
super();
this._movie = param1;
this._movie.gotoAndStop(1);
}
public function reset() : void
{
this._movie.gotoAndStop(1);
this.setState("E0");
}
public function run() : void
{
this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
this._timer.addEventListener(TimerEvent.TIMER,this.timerHandler);
this._timer.start();
this.isOn = true;
this.decroche = false;
this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
this.setState("E1");
this.state = RUNNING;
}
public function continueAcrochage() : void
{
this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
this._timer.addEventListener(TimerEvent.TIMER,this.timerHandler);
this._timer.start();
this.isOn = true;
this.decroche = false;
this._lastTime = this._timeAcrochage = this._timeDecrochage = getTimer();
this.setState("E1");
this.state = RUNNING;
}
public function stop() : void
{
this._timer.stop();
this._timer.removeEventListener(TimerEvent.TIMER,this.timerHandler);
this.state = STOPPED;
}
public function move() : void
{
this.frameToReach = this._movie.currentFrame + 1;
if(this.frameToReach > this._movie.totalFrames)
{
this._movie.gotoAndStop(this.frameToReach - this._movie.totalFrames);
}
else
{
this._movie.gotoAndStop(this.frameToReach);
}
}
private function timerHandler(param1:TimerEvent) : void
{
this._actualTime = getTimer();
if(this._actualTime - this._lastTime > this.frameDuration)
{
this._lastTime = this._actualTime;
this.frameToReach = this._movie.currentFrame + 1;
if(this.frameToReach > this._movie.totalFrames)
{
this._movie.gotoAndStop(this.frameToReach - this._movie.totalFrames);
}
else
{
this._movie.gotoAndStop(this.frameToReach);
}
}
if(this.isOn)
{
this._timeActual = getTimer();
this.acrochageTime = this._timeActual - this._timeAcrochage;
if(this.acrochageTime > this.delaiAcrochage)
{
if(this.acrochageTime - this.delaiAcrochage >= this.delayToClic)
{
this.stop();
this.timeToPeakExceed = true;
}
else
{
this._movie.TAUREAU.gotoAndStop("E2");
this.readyToPick = true;
}
}
else
{
this.readyToPick = false;
}
if(this._movie.TAUREAU.hitTestPoint(this._movie.stage.mouseX,this._movie.stage.mouseY,true))
{
if(this.decroche == true)
{
this.decroche = false;
}
}
else
{
if(this.decroche == false)
{
this.decroche = true;
this._timeDecrochage = getTimer();
}
if(this._timeActual - this._timeDecrochage > this.delaiDecrochage)
{
this.stop();
this.isOn = false;
this.eject = true;
}
}
}
param1.updateAfterEvent();
this.onRunning();
}
public function setState(param1:String) : void
{
this._movie.TAUREAU.gotoAndStop(param1);
}
public function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
{
this._movie.TAUREAU.addEventListener(param1,param2,param3,param4,param5);
}
public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
{
this._movie.TAUREAU.removeEventListener(param1,param2,param3);
}
public function hitTestPoint(param1:Number, param2:Number, param3:Boolean = false) : Boolean
{
return this._movie.hitTestPoint(param1,param2,param3);
}
public function get x() : Number
{
var _loc1_:Point = new Point(this._movie.TAUREAU.x,this._movie.TAUREAU.y);
_loc1_ = this._movie.localToGlobal(_loc1_);
_loc1_ = this._movie.parent.globalToLocal(_loc1_);
return _loc1_.x;
}
public function set x(param1:Number) : void
{
this._movie.TAUREAU.x = param1;
}
public function get y() : Number
{
var _loc1_:Point = new Point(this._movie.TAUREAU.x,this._movie.TAUREAU.y);
_loc1_ = this._movie.localToGlobal(_loc1_);
_loc1_ = this._movie.parent.globalToLocal(_loc1_);
return _loc1_.y;
}
public function set y(param1:Number) : void
{
this._movie.TAUREAU.y = param1;
}
private function perdu() : void
{
}
private function calcul() : void
{
this.fps = this._pixelSecondes / this.distancePixelParFrame;
this._frameDuration = 1000 / this.fps;
}
public function set speedMetreSecondes(param1:Number) : void
{
this._metreSecondes = param1;
this._pixelSecondes = this._metreSecondes * this.equivalentUnMetreEnPixels;
this.calcul();
}
public function set speedPixelSecondes(param1:Number) : void
{
this._pixelSecondes = param1;
this._metreSecondes = this._pixelSecondes / this.equivalentUnMetreEnPixels;
this.calcul();
}
public function get acrochageTimePourCent() : Number
{
return 100 * this.acrochageTime / this.delaiAcrochage;
}
public function get frameDuration() : Number
{
return this._frameDuration;
}
public function set frameDuration(param1:Number) : void
{
this._frameDuration = param1;
}
public function set depthIndex(param1:int) : void
{
if(this._movie.parent != null)
{
this._movie.parent.setChildIndex(this._movie,param1);
}
}
public function get depthIndex() : int
{
return this._movie.parent != null ? int(this._movie.parent.getChildIndex(this._movie)) : -1;
}
public function destroy() : void
{
if(this._movie.parent != null)
{
this._movie.parent.removeChild(this._movie);
}
}
}
}