home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 161
/
MOBICLIC161.ISO
/
pc
/
DATA
/
DSS161
/
DSS161_02
/
DSS161_02.swf
/
scripts
/
dss161
/
DragDropSituation.as
< prev
next >
Wrap
Text File
|
2014-01-15
|
14KB
|
409 lines
package dss161
{
import com.milanpresse.engine.cursor.NativeCursor;
import com.milanpresse.tools.GlobalesFunctions;
import dss161.engineaddons.facades.GameEngine;
import dss161.engineaddons.gamesprotos.Actor;
import dss161.engineaddons.gamesprotos.actors.actorClip.ActorClip;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.ui.Mouse;
public dynamic class DragDropSituation extends Actor
{
private var dragMCPattern:String = "OBJ_##";
private var dragMCFirstNo:int = 1;
private var dragMCLastNo:int = 999;
private var targetMCPattern:String = "ZONE_##";
private var targetMCFirstNo:int = 1;
private var targetMCLastNo:int = 999;
public var limites:Rectangle = null;
public var typeCollision:String = "auto";
public var paramsCollision = null;
public var cursorPosMode:String = "0x0";
public var onDragRollOver:Object;
public var onDragRollOverOnTarget:Object;
public var onDragRollOut:Object;
public var onDragClick:Object;
public var onTargetsClick:Object;
public var onTargetsRollOver:Object;
public var onTargetsRollOut:Object;
public var onDrag:Function;
public var onDrop:Function;
public var container:ActorClip;
public var dragActors:Array;
public var targetActors:Array;
public var dragClips:Object;
public var targetClips:Object;
public var cursor;
public var cursorSize:Point;
public var onDragEvent:Function;
private var pt_temp:Point;
public function DragDropSituation(param1:Object)
{
var _loc2_:* = null;
var _loc3_:int = 0;
var _loc4_:int = 0;
var _loc5_:DisplayObject = null;
this.onDragRollOver = {
"label":"",
"noiseCode":""
};
this.onDragRollOverOnTarget = {
"label":"",
"noiseCode":""
};
this.onDragRollOut = {"label":""};
this.onDragClick = {"label":""};
this.onTargetsClick = {"label":""};
this.onTargetsRollOver = {
"label":"",
"noiseCode":""
};
this.onTargetsRollOut = {"label":""};
this.onDrag = function(param1:*):void
{
};
this.onDrop = function(param1:*):void
{
};
this.dragActors = [];
this.targetActors = [];
this.targetClips = {};
this.cursor = new NativeCursor.mainF();
this.onDragEvent = function(param1:*):void
{
};
super(game);
this.limites = param1.limites;
this.cursorSize = new Point(this.cursor.width,this.cursor.height);
for(_loc2_ in param1)
{
this[_loc2_] = param1[_loc2_];
}
if(param1.dragClips.clips != undefined)
{
_loc3_ = 0;
while(_loc3_ < param1.dragClips.clips.length)
{
this.dragActors.push(this.dragMCInit(param1.dragClips.clips[_loc3_],_loc3_));
_loc3_++;
}
}
else
{
_loc4_ = this.dragClips.numeros[0];
while(_loc4_ <= this.dragClips.numeros[1])
{
if((_loc5_ = this.container.getChildByName(this.dragClips.pattern.replace("##",GlobalesFunctions.gimme2digits(_loc4_)).replace("#",_loc4_))) != null)
{
this.dragActors.push(this.dragMCInit(_loc5_,_loc4_));
}
_loc4_++;
}
}
if(this.targetClips.clips != undefined)
{
_loc3_ = 0;
while(_loc3_ < this.targetClips.clips.length)
{
this.targetActors.push(this.targetMCInit(param1.targetClips.clips[_loc3_],_loc3_));
_loc3_++;
}
}
else if(this.targetClips.pattern != undefined)
{
_loc4_ = this.targetClips.numeros[0];
while(_loc4_ <= this.targetClips.numeros[1])
{
if((_loc5_ = this.container.getChildByName(this.targetClips.pattern.replace("##",GlobalesFunctions.gimme2digits(_loc4_)).replace("#",_loc4_))) != null)
{
this.targetActors.push(this.targetMCInit(_loc5_,_loc4_));
}
_loc4_++;
}
}
}
public static function create(param1:GameEngine, param2:*) : DragDropSituation
{
return new DragDropSituation(param2);
}
private function dragMCInit(param1:DisplayObject, param2:int) : ActorClip
{
var _loc4_:* = null;
var _loc3_:Object = {};
for(_loc4_ in this.dragClips.onRollOverState)
{
_loc3_[_loc4_] = this.dragClips.onRollOverState[_loc4_];
}
if(_loc3_.noiseCode != undefined)
{
_loc3_.noiseCode = _loc3_.noiseCode.replace("##",GlobalesFunctions.gimme2digits(param2)).replace("#",param2);
}
if(_loc3_.ibId != undefined)
{
_loc3_.ibId = _loc3_.ibId.replace("##",GlobalesFunctions.gimme2digits(param2)).replace("#",param2);
}
var _loc5_:ActorClip = addActor({
"mc":param1,
"no":param2,
"onRollOverState":_loc3_,
"onRollOutState":this.dragClips.onRollOutState,
"onClickState":this.dragClips.onClickState,
"dragEnabled":true,
"onClick":this.onClickHandler,
"onRollOver":this.onRollOverHandler,
"onRollOut":this.onRollOutHandler,
"onDrag":this.onDragHandler,
"onDrop":this.onDropHandler,
"enabled":true
});
_loc5_.dragDrop.dropTargets = this.targetActors;
_loc5_.setCollision(this.typeCollision,this.paramsCollision);
_loc5_.limitZone = this.limites == null ? null : this.limites;
return _loc5_;
}
public function getWindowSize() : Rectangle
{
var _loc1_:String = game.stage.scaleMode;
game.stage.scaleMode = StageScaleMode.NO_SCALE;
var _loc2_:Rectangle = new Rectangle(0,0,stage.stageWidth,stage.stageHeight);
game.stage.scaleMode = _loc1_;
return _loc2_;
}
private function onClickHandler(param1:ActorClip) : void
{
var _loc4_:DisplayObject = null;
var _loc5_:Point = null;
if(game.engine.pad != null)
{
game.engine.pad.activated = false;
}
Mouse.hide();
this.dragActorsDisable();
var _loc2_:Rectangle = this.getWindowSize();
var _loc3_:Number = Math.min(_loc2_.width / 800,_loc2_.height / 600);
this.cursor.scaleX = this.cursor.scaleY = game.stage.scaleMode == StageScaleMode.NO_SCALE ? 1 : 1 / _loc3_;
this.cursor.scaleX = this.cursor.scaleY = this.cursor.scaleY / param1.clip.scaleY;
switch(this.cursorPosMode)
{
case "none":
_loc4_ = param1.getChildByName("REP_CENTER2");
if(_loc4_ == null)
{
_loc4_ = param1.clip.addChild(new Sprite());
_loc4_.name = "REP_CENTER2";
}
_loc5_ = param1.clip.globalToLocal(new Point(game.stage.mouseX,game.stage.mouseY));
_loc4_.x = _loc5_.x;
_loc4_.y = _loc5_.y;
this.cursor.x = _loc4_.x - this.cursor.width / 2;
this.cursor.y = _loc4_.y - this.cursor.height / 2;
param1.repereDragName = "REP_CENTER2";
break;
case "0x0":
_loc4_ = param1.getChildByName("REP_CENTER");
if(_loc4_ == null)
{
this.cursor.x = -this.cursor.width / 2;
this.cursor.y = -this.cursor.height / 2;
}
else
{
this.cursor.x = _loc4_.x - this.cursor.width / 2;
this.cursor.y = _loc4_.y - this.cursor.height / 2;
}
param1.repereDragName = "REP_CENTER";
}
param1.clip.addChild(this.cursor);
param1.bringToFront();
this.onDragEvent({
"actor":param1,
"action":"dragClipClick"
});
}
private function onRollOverHandler(param1:ActorClip) : void
{
game.changeCursor("mainO");
this.onDragEvent({
"actor":param1,
"action":"dragClipRollOver",
"targetHited":param1.dragDrop.dropTarget
});
}
private function onRollOutHandler(param1:ActorClip) : void
{
game.changeCursor("auto");
this.onDragEvent({
"actor":param1,
"action":"dragClipRollOut",
"targetHited":param1.dragDrop.dropTarget
});
}
private function dragActorsDisable() : void
{
var _loc1_:int = 0;
while(_loc1_ < this.dragActors.length)
{
this.dragActors[_loc1_].enabled = false;
_loc1_++;
}
}
private function dragActorsEnable() : void
{
var _loc1_:int = 0;
while(_loc1_ < this.dragActors.length)
{
this.dragActors[_loc1_].enabled = this.dragActors[_loc1_].blocked == true ? false : true;
_loc1_++;
}
}
private function onDragHandler(param1:ActorClip) : void
{
param1.setToPos(game.stage.mouseX,game.stage.mouseY,param1.repereDragName);
var _loc2_:int = 0;
while(_loc2_ < param1.dragDrop.dropTargets.length)
{
if(param1.dragDrop.dropTargets[_loc2_] == param1.dragDrop.dropTarget)
{
if(this.targetClips.onDragOverState != undefined && this.targetClips.onDragOverState.label)
{
if(param1.dragDrop.dropTargets[_loc2_].currentLabel != this.targetClips.onDragOverState.label)
{
param1.dragDrop.dropTargets[_loc2_].gotoAndStop(this.targetClips.onDragOverState.label);
}
}
}
else if(this.targetClips.onDragOutState != undefined && this.targetClips.onDragOutState.label)
{
if(param1.dragDrop.dropTargets[_loc2_].currentLabel != this.targetClips.onDragOutState.label)
{
param1.dragDrop.dropTargets[_loc2_].gotoAndStop(this.targetClips.onDragOutState.label);
}
}
_loc2_++;
}
this.onDragEvent({
"actor":param1,
"action":"dragging",
"targetHited":param1.dragDrop.dropTarget
});
}
private function onDropHandler(param1:ActorClip) : void
{
param1.clip.removeChild(this.cursor);
game.ibHide();
if(game.engine.pad != null)
{
game.engine.pad.activated = true;
}
this.onDragEvent({
"actor":param1,
"action":"drop",
"targetHited":param1.dragDrop.dropTarget
});
if(param1.clip != null && param1.enabled && param1.clip.hitTestPoint(game.stage.mouseX,game.stage.mouseY,true))
{
game.changeCursor("auto");
Mouse.show();
}
else
{
game.changeCursor("auto");
Mouse.show();
}
this.dragActorsEnable();
}
private function onMouseShowEnterFrameHandler(param1:Event) : void
{
param1.currentTarget.removeEventListener(Event.ENTER_FRAME,this.onMouseShowEnterFrameHandler);
Mouse.show();
}
private function targetMCInit(param1:DisplayObject, param2:int) : ActorClip
{
return addActor({
"mc":param1,
"no":param2,
"onRollOverState":this.targetClips.onRollOverState,
"onRollOutState":this.targetClips.onRollOutState,
"onClickState":this.targetClips.onClickState,
"onClick":this.onTargetClickHandler,
"onRollOver":this.onTargetRollOverHandler,
"onRollOut":this.onTargetRollOutHandler,
"enabled":false
});
}
private function onTargetClickHandler(param1:ActorClip) : void
{
}
private function onTargetRollOverHandler(param1:ActorClip) : void
{
}
private function onTargetRollOutHandler(param1:ActorClip) : void
{
}
override protected function _destroy() : void
{
game.stage.removeEventListener(Event.ENTER_FRAME,this.onMouseShowEnterFrameHandler);
this.dragActors.length = 0;
this.targetActors.length = 0;
this.onDrag = null;
this.onDrop = null;
this.onDragEvent = null;
this.targetClips = null;
this.dragClips = null;
super._destroy();
}
}
}