Código ActionScript :
package com.as3{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Bitmap;
public class Gallery extends MovieClip{
private var _xmlLoader:URLLoader;
private var _xmlPath:String = "data/xml/gallery.xml";
private var _xmlData:XML;
private var _thumbs:Array;
private var _ref:int = 0;
private var _imgContainer:MovieClip;
public function Gallery() {
_xmlLoader = new URLLoader();
_xmlLoader.addEventListener(Event.COMPLETE, onCompleteXMLLoadHandler);
_xmlLoader.load(new URLRequest(_xmlPath));
_thumbs = new Array();
_imgContainer = new MovieClip();
addChild(_imgContainer);
next_mc.buttonMode = true;
back_mc.buttonMode = true;
next_mc.addEventListener(MouseEvent.CLICK, onClickArrowHandler);
back_mc.addEventListener(MouseEvent.CLICK, onClickArrowHandler);
}
private function onCompleteXMLLoadHandler(event:Event):void {
_xmlData = new XML(event.target.data);
populateThumbs();
}
private function populateThumbs():void {
for (var i:int = 0; i < 5; i++) {
var temp:Loader = new Loader();
temp.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteThumbLoad);
temp.load(new URLRequest(_xmlData.item[i].thumb));
var thumb:MovieClip = new MovieClip();
addChild(thumb);
_thumbs.push(thumb);
}
}
private function onCompleteThumbLoad(event:Event):void {
var image:Bitmap = Bitmap(event.target.content);
image.smoothing = true;
MovieClip(_thumbs[_ref]).x = (_ref * 80) + 80;
MovieClip(_thumbs[_ref]).y = 350;
MovieClip(_thumbs[_ref]).addChild(image);
MovieClip(_thumbs[_ref]).buttonMode = true;
MovieClip(_thumbs[_ref]).addEventListener(MouseEvent.CLICK, onClickThumbHandler);
MovieClip(_thumbs[_ref]).id = _ref;
_ref++;
}
private function onClickThumbHandler(event:MouseEvent):void {
var temp:Loader = new Loader();
temp.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteImgLoad);
temp.load(new URLRequest(_xmlData.item[event.target.id].full));
}
private function onCompleteImgLoad(event:Event):void {
var image:Bitmap = Bitmap(event.target.content);
image.smoothing = true;
_imgContainer.addChild(image);
_imgContainer.x = (stage.stageWidth - image.width) / 2;
_imgContainer.y = 15;
}
private function onClickArrowHandler(event:Event):void {
}
}
} 