package {
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.*;
import flash.events.*;
import PolaroidMc;
public class Document extends MovieClip {
private var loader:Loader;
private var album:MovieClip;
private var fullPics:MovieClip;
private var tX:int;
private var tY:int;
private var pX:int;
private var pY:int;
private var currNum:int;
private var currentlyLoadedName:String;
//zmienne dla ruchu kolistego
private var centerX:int;
private var centerY:int;
private var radius = 50;
private var angleStep = .02;
private var twoPI = 2 * Math.PI;
private var currentAngle = 0;
private var currPhoto:*;
private var prevPhoto:*;
public function Document() {
tX = 140;
tY = 60;
pX = 120;
pY = 40;
currNum = 8;
currPhoto = null;
prevPhoto = null;
currentlyLoadedName = "woman-"+currNum;
loader = new Loader();
loader.load(new URLRequest("images/woman-"+currNum+"-thumb.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumbComplete);
}
private function onBigComplete(e:Event):void {
var angle:Number = (Math.random() * 100) / 6;
while (Math
.round(angle
) > 6
) { angle = (Math.random() * 100) / 6;
}
var mc:MovieClip = new PolaroidMc();
mc.addChild(e.target.content);
mc.drawBorder();
var iWidth = e.target.content.width;
var iHeight = e.target.content.height;
var newW = 430;
var newH = 430;
if(iWidth > iHeight) {
newH = iHeight * (newH / iWidth);
mc.x = tX;
mc.y = tY + 20;
}
else if(iWidth < iHeight) {
newW = iWidth * (newW / iHeight);
mc.x = tX + 100;
mc.y = tY;
}
mc.name = currentlyLoadedName;
mc.width = newW;
mc.height = newH;
tX -= 10;
tY -= 3;
if ((Math
.ceil(Math
.random
() * 100
)) % 2
== 0
) { mc.rotation -= angle;
} else {
mc.rotation += angle;
}
album_mc.addChild(mc);
currNum--;
if(currNum > 0) {
currentlyLoadedName = "woman-"+currNum;
loader = new Loader();
loader.load(new URLRequest("images/woman-"+(currNum)+"-thumb.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumbComplete);
}
}
private function onThumbComplete(e:Event):void {
var iWidth = e.target.content.width;
var iHeight = e.target.content.height;
var newW = 165;
var newH = 220;
if(iWidth > iHeight)
newH = iHeight * (newH / iWidth);
else if(iWidth < iHeight)
newW = iWidth * (newW / iHeight);
var mc_s:MovieClip = new MovieClip();
mc_s.addChild(e.target.content);
mc_s.name = currentlyLoadedName;
mc_s.x = pX;
mc_s.y = pY;
if(thumbs_mc.numChildren % 3 == 0) {
mc_s.x = pX;
mc_s.y = pY;
pY += 260;
pX = 120;
}
else {
if(iWidth > iHeight)
pX += 180;
else
pX += 150;
}
mc_s.width = newW;
mc_s.height = newH;
mc_s.addEventListener(MouseEvent.CLICK, onThumbClick);
thumbs_mc.addChild(mc_s);
loader = new Loader();
loader.load(new URLRequest("images/woman-"+(currNum)+".jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBigComplete);
}
private function onThumbClick(e:Event):void {
if(currPhoto != album_mc.getChildByName(e.target.name)) {
for(var i:int = 0; i < thumbs_mc.numChildren; ++i)
thumbs_mc.getChildAt(i).removeEventListener(MouseEvent.CLICK, onThumbClick);
if(currPhoto == null) {
currPhoto = album_mc.getChildByName(e.target.name);
centerX = currPhoto.x;
centerY = currPhoto.y;
currPhoto.addEventListener(Event.ENTER_FRAME, advanceCircleForwards);
}
else {
currPhoto = album_mc.getChildByName(e.target.name);
centerX = prevPhoto.x;
centerY = prevPhoto.y;
prevPhoto.addEventListener(Event.ENTER_FRAME, advanceCircleBackwards);
}
}
}
private function advanceCircleForwards(e:Event):void {
currentAngle += angleStep;
currPhoto.x = (centerX + Math.cos(currentAngle * twoPI) * radius) - radius;
currPhoto.y = centerY + Math.sin(currentAngle * twoPI) * radius;
if(currentAngle < .5 && currentAngle > .25)
album_mc.setChildIndex(currPhoto, album_mc.numChildren - 1);
if (currentAngle >= .5 ) {
prevPhoto = currPhoto;
for(var i:int = 0; i < thumbs_mc.numChildren; ++i)
thumbs_mc.getChildAt(i).addEventListener(MouseEvent.CLICK, onThumbClick);
currPhoto.removeEventListener(Event.ENTER_FRAME, advanceCircleForwards);
}
}
private function advanceCircleBackwards(e:Event):void {
currentAngle -= angleStep;
prevPhoto.x = (centerX + Math.cos(currentAngle * twoPI) * radius) + radius;
prevPhoto.y = centerY + Math.sin(currentAngle * twoPI) * radius;
if (currentAngle <= 0 ) {
centerX = currPhoto.x;
centerY = currPhoto.y;
currentAngle = 0;
prevPhoto.removeEventListener(Event.ENTER_FRAME, advanceCircleBackwards);
currPhoto.addEventListener(Event.ENTER_FRAME, advanceCircleForwards);
}
}
}
}