---- Frame 1 ----

var loadFromURL = "http://www.hs.fi/altparty08/feed/";
var musicURL:String = "ambient.mp3";
var musicOn:Boolean = true;
var gridSpread:Number = 6;

import Uutinen;
var loader:URLLoader = new URLLoader(); 
loader.addEventListener(Event.COMPLETE, loadXML); 
var timer:Timer = new Timer(10);
var counter:Number = 0;
var world:MovieClip = new MovieClip();
var underWorld:MovieClip = new MovieClip();

var xml:XML;
var li:XMLList;
var imageList:XMLList;
var imageListIsot:XMLList;
var uutiset:Array = new Array();
var imgCount:int = 0;
var target:int = 0;
var oldTarget:int = 0;
var lastPhase:Number = 0;
var phase:Number = 0;
var sinPhase:Number = 0;
var snd:Sound
if(musicOn)
 snd = new Sound(new URLRequest("ambient.mp3"));  
var newsGrid:Array = new Array();
var topicsList:XMLList;
var topics:Array = new Array();

function createUnderWorld()
{
	underWorld.graphics.lineStyle(1, 0x222222);
	underWorld.graphics.moveTo(0,0);
	var lineAmount:int = 800;
	for(var i:int = 0; i < lineAmount; i++)
	{
		var x_:int = Math.random()*20000-10000;
		var y_:int = Math.random()*20000-10000;
		
		var x2_:int = x_+ Math.random()*500-250;
		var y2_:int = y_+ Math.random()*500-250;
		underWorld.graphics.moveTo(x_, y_);
		underWorld.graphics.lineTo(x_, y_);
		underWorld.graphics.lineTo(x2_, y2_);
	}

	addChild(underWorld);
}


function loadXML(e:Event):void
{


	xml = new XML(e.target.data);
	li = xml.uutinen;
	topicsList = xml.uutinen.otsikko1;
	var i:int = 0;
	trace(topicsList);
	
	while(true)
	{	
		imageList = li[i].kuva;
		imageListIsot = li[i].kuva.iso_url;
		
		if(imageListIsot.length() > 0)
		{
			var uutinen:Uutinen = new Uutinen(li[i].otsikko1, li[i].paivitetty, li[i].teksti, li[i].kirjoittaja);
			
			trace(imageList.length());
			
			for( var f in imageList)
			{
				if(f > 0)
					break;
				//trace("'" + imageList[f] + "'");
				uutinen.addKuva(imageList[f].iso_url, imageList[f].iso_kuvateksti, imageList[f].kuvaaja);
				imgCount++;
			}
		
			
			uutiset.push(uutinen);
			
			world.addChild(uutinen.getMc());
			
		}
				
		
		if(i > li.length()-3)
			break;
		i++;
	}
	
	var newsCount:int = uutiset.length;
	
	// Randomize place for news
	var amount:int = uutiset.length;
	var gridSide:int = Math.sqrt(amount*gridSpread);
	var  grid = new Array(gridSide*gridSide);
	// Align images in begining
	var multiplier:Number = (Math.PI*2)/amount;
	var radius:Number = 1000;
	for(var t:int = 0; t < gridSide*gridSide; t++)
	{
		grid[t] = 0;
	}
	t = 0;
	var index:int;
	for(var it in uutiset)
	{
		do
		{
			index = Math.random()*gridSide*gridSide;
			
		}while(grid[index] != 0)
		
		trace("----");
		trace(index);
		grid[index] = 1;
		newsGrid.push(index);
		uutiset[it].x = radius*Math.floor(index/gridSide);// Math.sin(multiplier*it)*radius;
		uutiset[it].y = ((index/gridSide)-Math.floor(index/gridSide))*gridSide*radius; //Math.cos(multiplier*it)*radius;
		
		t++;
		
	}
	target = Math.random()*uutiset.length;
	oldTarget = Math.random()*uutiset.length;
	addChild(world);
	/*
	// Tausta topicit
	var g:int = 0;
	while( g < 1)
	{
		var caption:String = topicsList[Math.floor(Math.random()*topicsList.length())];
		var tan:TextField = new TextField();
		tan.condenseWhite = true;
		tan.textColor = 0xcccccc;
		tan.multiline = false;
		tan.wordWrap = false;
		tan.height = 250;
		tan.width = 3000;
		tan.y = 334;
		tan.htmlText = '<font size="24"><b>'+caption+"</b></font>";
		tan.scaleY = 4;
		tan.antiAliasType = "normal";
		topics.push(tan);
		world.addChild(tan);
		g++;
	}
	
	trace("fffffff");
	trace(topics);
*/
	
}

loader.load(new URLRequest(loadFromURL));
//createUnderWorld();
if(musicOn)
	snd.play();
	
	
	
---- Frame 2 ----


for(var i in uutiset)
{
	//uutiset[i].x = Math.sin(i*counter)*200;
	//uutiset[i].y = Math.cos(i*counter)*200;

	//uutiset[i].update(Math.sin(counter)*(uutiset.length)*0.5*600, Math.cos(counter)*0.5*600, Math.sin(counter*4)*0.5+0.7);
	uutiset[i].update(0,0, 1);
	
}

function newTarget()
{
	oldTarget = target;
	do
	{
		var r:int = Math.random()*uutiset.length;
		target = r;
		
	}while(target == oldTarget)
	
	
}
if(uutiset.length > 0)
{
	var phase2:Number = 0;
	var sinPhase2:Number = 0;
	phase += 0.006;//Math.sin(counter)*0.5+0.5;
	sinPhase += Math.sin(phase*Math.PI/1.8+Math.PI*0.5)+1;
	
	sinPhase2 = sinPhase;
	phase2 = phase;
	if(phase > 1)
	{
		phase2 = 1;
		sinPhase2 = 260;
		if(phase > 1.6)
		{
			phase = 0;
			sinPhase = 0;
			newTarget();
			phase2 = 0;
			sinPhase2 = 0;			
		}
	}	
	
	if(counter > 25.25)
	{
		gotoAndStop(4);
	}
	var sp = sinPhase2/260;


	var scl:Number = Math.sin(phase2*Math.PI*2+0.5*Math.PI)*0.3+0.8;
	var x_ = uutiset[target].getX()*sp+uutiset[oldTarget].getX()*(1.0-sp); 
	var y_ = uutiset[target].getY()*sp+uutiset[oldTarget].getY()*(1.0-sp);
	
	world.x = -x_*scl+Math.sin(counter*1.7)*50;
	world.y = -y_*scl+Math.cos(counter*1.6+45)*60; 
	world.scaleX = scl;
	world.scaleY = scl;
	
	underWorld.x = world.x*0.3;
	underWorld.y = world.y*0.3;
	underWorld.scaleX = scl*0.9;
	underWorld.scaleY = scl*0.9;	
	
	
}

counter+=0.01;


---- Frame 3 ----


gotoAndPlay(2);



+ 
Kuva.as
Pic.as
Uutinen.as