Here is the meat of the project to start out with. I have been trying to have the individual tiles be populated by images loaded in XML however, I am getting a little stuck. help?:look: also, I was trying to create a double click function that would center and enlarge the image. Any help would be incredible.
//
var amt:Number;
//
function setQuality(thisSpeed:Number):Void {
if (thisSpeed == 1) {
amt = 15;
} else if (thisSpeed == 2) {
amt = 32;
} else {
amt = 45;
}
}
setQuality(_global.speed);
//
var degreesToRadians:Number = Math.PI/180;
var radiansToDegrees:Number = 180/Math.PI;
//
// a = a_point :: b = b_point
function myAngle(ax:Number, bx:Number, ay:Number, by:Number):Number {
var c:Number = Math.atan2((ay-by), (ax-bx))*radiansToDegrees;
return (c);
}
//
function createBackground():Void {
// the background
this.createEmptyMovieClip("bk", 1);
var bk:MovieClip = this["bk"];
var colors:Array = [0x121321, 0x6FA2AC];
var alphas:Array = [100, 100];
var ratios:Array = [0, 255];
var matrix:Object = {matrixType:"box", x:left, y:top, w:(right-left)+left, h:bottom-top, r:Math.PI/2.9};
bk.beginGradientFill("linear", colors, alphas, ratios, matrix);
bk.moveTo(left, top);
bk.lineTo(right, top);
bk.lineTo(right, bottom);
bk.lineTo(left, bottom);
bk.lineTo(left, top);
bk.endFill();
this.createEmptyMovieClip("ele", 2);
var ele:MovieClip = this["ele"];
this.createEmptyMovieClip("mask", 3);
var mask:MovieClip = this["mask"];
mask.beginFill(0x000000,100);
mask.moveTo(left, top);
mask.lineTo(right, top);
mask.lineTo(right, bottom);
mask.lineTo(left, bottom);
mask.lineTo(left, top);
mask.endFill();
ele.setMask(mask);
}
//
function clearAll():Void {
removeMovieClip("ele");
removeMovieClip("mask");
removeMovieClip("bk");
}
//
//
function setUp():Void {
createBackground();
var ele:MovieClip = this["ele"];
//
for (var i:Number = 0; i<amt; i++) {
ele.attachMovie("drag_object", "holder"+i, i+10);
//
var holder:MovieClip = ele["holder"+i];
holder._x = Math.floor(left+(right-left)/2);
holder._y = Math.floor(top+(bottom-top)/2);
holder.cenx = (right-left)/2;
holder.ceny = (bottom-top)/2;
holder.dragging = false;
//
holder.dragStop = function(div:Number):Void {
onMouseMove = undefined;
this.dragging = false;
this.lead.vel_x = this.lead.dif_x*this.lead.mass*div;
this.lead.vel_y = this.lead.dif_y*this.lead.mass*div;
this.follow.vel_x = this.lead.dif_x*this.follow.mass;
this.follow.vel_y = this.lead.dif_y*this.follow.mass;
this.clip.onEnterFrame = function():Void {
var myP:MovieClip = this._parent;
//
var posx:Number = this._x+myP.lead.vel_x;
if (posx<myP.cenx && posx>-myP.cenx) {
this._x = posx;
} else if (posx>=myP.cenx) {
this._x = myP.cenx;
myP.lead.vel_x *= -1;
} else {
this._x = -myP.cenx;
myP.lead.vel_x *= -1;
}
//
var posy:Number = this._y+myP.lead.vel_y;
if (posy<myP.ceny && posy>-myP.ceny) {
this._y = posy;
} else if (posy>=myP.ceny) {
this._y = myP.ceny;
myP.lead.vel_y *= -1;
} else {
this._y = -myP.ceny;
myP.lead.vel_y *= -1;
}
//
myP.lead._x = this._x;
myP.lead._y = this._y;
myP.lead.vel_x *= 0.85;
myP.lead.vel_y *= 0.85;
myP.follow.xTarg += myP.follow.vel_x;
myP.follow.yTarg += myP.follow.vel_y;
myP.follow.vel_x *= 0.78;
myP.follow.vel_y *= 0.78;
myP.lead.old_x = myP.lead._x;
myP.lead.old_y = myP.lead._y;
myP.follow._x += (myP.follow.xTarg-myP.follow._x)/5;
myP.follow._y += (myP.follow.yTarg-myP.follow._y)/5;
this._rotation = myAngle(myP.clip._x, myP.follow._x, myP.clip._y, myP.follow._y)+90;
if (Math.abs(myP.lead.vel_x)<0.05 && Math.abs(myP.lead.vel_y)<0.05 && Math.abs(myP.follow.vel_x)<0.1 && Math.abs(myP.follow.vel_y)<0.1) {
this.onEnterFrame = undefined;
}
};
this.lead.onEnterFrame = undefined;
this.follow.onEnterFrame = undefined;
stopDrag();
};
holder.dragStart = function():Void {
this.dragging = true;
this.clip.onEnterFrame = undefined;
this.clip.startDrag(false, -this.cenx, -this.ceny, this.cenx, this.ceny);
this.clip.offset_x = 0;
this.clip.offset_y = 0;
this.lead.onEnterFrame = function():Void {
var myP:MovieClip = this._parent;
this._x = myP.clip._x;
this._y = myP.clip._y;
if (this._x>myP.cenx-1 || this._x<-myP.cenx+1 || this._y<-myP.ceny+1 || this._y>myP.ceny-1) {
if (myP.dragging) {
myP.dragStop(0.8);
}
}
this.dif_x = this._x-this.old_x;
this.dif_y = this._y-this.old_y;
this.old_x = this._x;
this.old_y = this._y;
this.onMouseMove = function():Void {
this.xTarg += (_xmouse-this._x)/1.2;
this.yTarg += (_ymouse-this._y)/1.2;
this._parent.follow.xTarg += (this._x-this._parent.follow.xTarg)/17;
this._parent.follow.yTarg += (this._y+40-this._parent.follow.yTarg)/6;
updateAfterEvent();
};
};
this.follow.onEnterFrame = function():Void {
this._x += (this.xTarg-this._x)/5;
this._y += (this.yTarg-this._y)/5;
this._parent.clip._rotation = myAngle(this._parent.clip._x, this._x, this._parent.clip._y, this._y)+90;
this.dif_x = this._x-this.old_x;
this.dif_y = this._y-this.old_y;
this.old_x = this._x;
this.old_y = this._y;
};
};
holder.clip.onPress = function():Void {
/////////////////////////////////////////////////// remove temporary clip
if (ele.hint) {
ele.hint.removeMovieClip();
}
///////////////////////////////////////////////////
this._parent.swapDepths(this._parent._parent.getNextHighestDepth());
this._parent.dragStart();
};
holder.clip.onRelease = function():Void {
if (this._parent.dragging) {
this._parent.dragStop(1.0);
}
};
holder.clip.onReleaseOutside = function():Void {
if (this._parent.dragging) {
this._parent.dragStop(1.0);
}
};
holder.clip.useHandCursor = false;
holder.clip._x = Math.floor(Math.random()*750-375);
holder.clip._y = Math.floor(Math.random()*250-125);
var col:Color = new Color(holder.clip.body_mc);
var colTrans:Object = {ra:100, rb:Math.round(Math.random()*90-70), ga:100, gb:Math.round(Math.random()*100-90), ba:100, bb:Math.round(Math.random()*100-20)};
col.setTransform(colTrans);
//
holder.lead.mass = 1.2;
holder.lead._x = holder.clip._x;
holder.lead._y = holder.clip._y;
holder.lead.old_x = holder.lead._x;
holder.lead.old_y = holder.lead._y;
holder.lead.xTarg = holder.lead._x;
holder.lead.yTarg = holder.lead._y;
holder.lead.vel_x = 0;
holder.lead.vel_y = 0;
holder.lead.dif_x = 0;
holder.lead.dif_y = 0;
holder.lead._alpha = 20;
holder.lead._visible = false;
//
holder.follow.mass = 1.6;
holder.follow._x = holder.lead._x+Math.random()*200-100;
holder.follow._y = holder.lead._y+20;
holder.follow.xTarg = holder.lead._x;
holder.follow.yTarg = holder.lead._y+20;
holder.follow.targx = holder.follow._x;
holder.follow.targy = holder.lead._y+20;
holder.follow.dx = 0;
holder.follow.dy = 0;
holder.follow.vel_x = 0;
holder.follow.vel_y = 0;
holder.follow.dif_x = 0;
holder.follow.dif_y = 0;
holder.follow._alpha = 20;
holder.follow._visible = false;
//
holder.clip.offset_x = 0;
holder.clip.offset_y = 0;
holder.clip._rotation = myAngle(holder.clip._x, holder.follow._x, holder.clip._y, holder.follow._y)+90;
/////////////////////////////////////////////////// temporary clip
ele.attachMovie("hint", "hint", 50);
var hint:MovieClip = ele["hint"];
hint._x = Math.floor(left+70);
hint._y = Math.floor(bottom-22);
hint._txt.text = "click and drag objects";
}
}
setUp();
//
stop();