flashmo_graphic.visible = false;
link_title.text = "";
link_description.text = "";
loading_info.text = "cargando...";
var folder:String = "swf/thumbnails/";
var speed:Number = 3; // range from 1 to 10
var radius_x:Number = 350;
var radius_y:Number = 100;
var tn_border:Number = 5;
var tn_border_color:Number = 0xFFFFFF;
var dynamic_speed:Number = 0.00006;
var ratio:Number;
var i:Number;
var tn:Number = 0;
var current_no:Number = 0;
var total_items:Number;
var flashmo_xml:XML;
var flashmo_tn_list = new Array();
var mc:MovieClip = new MovieClip();
var thumbnail_group:MovieClip = new MovieClip();
this.addChild(thumbnail_group);
if( speed > 10 || speed < 1 ) speed = 5;
function load_gallery(xml_file:String):void
{
var xml_loader:URLLoader = new URLLoader();
xml_loader.load( new URLRequest( xml_file ) );
xml_loader.addEventListener(Event.COMPLETE, create_gallery);
}
function create_gallery(e:Event):void
{
flashmo_xml = new XML(e.target.data);
total_items = flashmo_xml.thumbnail.length();
for( i = 0; i < total_items; i++ )
{
flashmo_tn_list.push( {
filename: flashmo_xml.thumbnail[i].filename.toString(),
title: flashmo_xml.thumbnail[i].title.toString(),
description: flashmo_xml.thumbnail[i].description.toString(),
url: flashmo_xml.thumbnail[i].url.toString(),
target: flashmo_xml.thumbnail[i].target.toString()
} );
}
load_tn();
}
function load_tn():void
{
var pic_request:URLRequest = new URLRequest( folder + flashmo_tn_list[tn].filename );
var pic_loader:Loader = new Loader();
pic_loader.load(pic_request);
pic_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, tn_progress);
pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, tn_loaded);
tn++;
}
function tn_progress(e:ProgressEvent):void
{
loading_info.text = "Cargando " + tn + " de " + total_items;
}
function tn_loaded(e:Event):void
{
var flashmo_tn_bm:Bitmap = new Bitmap();
var flashmo_tn_mc:MovieClip = new MovieClip();
flashmo_tn_bm = Bitmap(e.target.content);
flashmo_tn_bm.smoothing = true;
flashmo_tn_bm.x = - flashmo_tn_bm.width * 0.5;
flashmo_tn_bm.y = - flashmo_tn_bm.height * 0.5;
var bg_width:Number = flashmo_tn_bm.width + tn_border * 2;
var bg_height:Number = flashmo_tn_bm.height + tn_border * 2;
if( tn_border > 0 )
{
flashmo_tn_mc.graphics.beginFill(tn_border_color);
flashmo_tn_mc.graphics.drawRect( - bg_width * 0.5, - bg_height * 0.5, bg_width, bg_height );
flashmo_tn_mc.graphics.endFill();
}
flashmo_tn_mc.addChild(flashmo_tn_bm);
flashmo_tn_mc.name = "flashmo_tn_" + thumbnail_group.numChildren;
flashmo_tn_mc.buttonMode = true;
flashmo_tn_mc.y = -900;
thumbnail_group.addChild( flashmo_tn_mc );
if( tn < total_items )
load_tn();
else
activate_carousel();
}
function activate_carousel():void
{
for( i = 0; i < total_items; i++ )
{
mc = MovieClip( thumbnail_group.getChildByName("flashmo_tn_" + i) );
mc.addEventListener( MouseEvent.MOUSE_OVER, tn_over );
mc.addEventListener( MouseEvent.MOUSE_OUT, tn_out );
mc.addEventListener( MouseEvent.CLICK, tn_click );
mc.addEventListener( Event.ENTER_FRAME, tn_update );
mc.angle = i * ( Math.PI * 2 / total_items );
}
stage.addEventListener( MouseEvent.MOUSE_MOVE, on_move );
stage.addEventListener( Event.ENTER_FRAME, on_update );
loading_info.text = "";
}
function tn_update(e:Event):void
{
mc = MovieClip(e.target);
mc.x = Math.cos(mc.angle) * radius_x;
mc.y = Math.sin(mc.angle) * radius_y;
ratio = ( mc.y + radius_y ) / ( radius_y * 2 );
if( ratio < 0.3 ) ratio = 0.3;
mc.scaleX = mc.scaleY = ratio;
mc.angle += dynamic_speed;
}
function tn_over(e:MouseEvent):void
{
mc = MovieClip(e.target);
current_no = parseInt(mc.name.slice(11,13));
link_title.text = flashmo_tn_list[current_no].title;
link_description.text = flashmo_tn_list[current_no].description;
}
function tn_out(e:MouseEvent):void
{
link_title.text = "";
link_description.text = "";
}
function tn_click(e:MouseEvent):void
{
mc = MovieClip(e.target);
current_no = parseInt(mc.name.slice(11,13));
navigateToURL( new URLRequest( flashmo_tn_list[current_no].url ),
flashmo_tn_list[current_no].target );
}
function on_move(e:MouseEvent):void
{
dynamic_speed = mouseX * speed * 0.00003;
}
function on_update(e:Event):void
{
sort_group(thumbnail_group);
}
function sort_group(group:MovieClip):void
{
var i:int;
var child_list:Array = new Array();
i = group.numChildren;
while(i--)
{
child_list[i] = group.getChildAt(i);
}
child_list.sortOn("y", Array.NUMERIC);
i = group.numChildren;
while(i--)
{
if( child_list[i] != group.getChildAt(i) )
{
group.setChildIndex(child_list[i], i);
}
}
}