You are on page 1of 2

FLASH XML

1. Buat file dengan nama images.xml berikut isi filenya:


<images>
<image source="images/astro1.jpg" thumb="thumbnail/astro1.jpg"></image>
<image source="images/astro2.jpg" thumb="thumbnail/astro2.jpg"></image>
<image source="images/space3.jpg" thumb="thumbnail/space3.jpg"></image>
<image source="images/space4.jpg" thumb="thumbnail/space4.jpg"></image>
<image source="images/space5.jpg" thumb="thumbnail/space5.jpg"></image>
</images>


2. Buat file flash actionscript 3.0

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Loader;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var xml:XML;
var xmlList:XMLList;
var imageLoader:Loader;
var xmlLoader:URLLoader = new URLLoader();

xmlLoader.load(new URLRequest("images.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(e:Event):void{

xml = XML(e.target.data);
//trace(xml);
xmlList = xml.children();
//trace(xmlList);

for(var i:int = 0; i < xmlList.length(); i++){
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = 25;
imageLoader.y = i*94+15;
imageLoader.name = xmlList[i].attribute("source")
addChild(imageLoader);

imageLoader.addEventListener(MouseEvent.CLICK, showImages);
}
}

function showImages(e:MouseEvent):void{
imageLoader = new Loader();
imageLoader.load(new URLRequest(e.target.name));
imageLoader.x = 200;
imageLoader.y = 10;
var myTween = new Tween(imageLoader,'alpha',Regular.easeIn,0,1,1,true);
addChild(imageLoader);
}

You might also like