Created
January 4, 2010 18:40
-
-
Save jasonmelgoza/268726 to your computer and use it in GitHub Desktop.
Small Flash (AS3) Gallery driven with XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fl.controls.ProgressBar; | |
import fl.controls.Button; | |
import fl.containers.UILoader; | |
import flash.text.TextField; | |
import flash.text.TextFieldType; | |
import flash.events.MouseEvent; | |
import flash.ui.Mouse; | |
/*Load style*/ | |
var style:StyleSheet = new StyleSheet(); | |
var p:Object = new Object(); | |
p.fontWeight = "normal"; | |
p.fontSize = 14; | |
p.fontFamily = "Arial"; | |
p.color = "#292929"; | |
p.textAlign = "left"; | |
p.textIndent = 0; | |
p.leading = 4.5; | |
var h1:Object = new Object(); | |
h1.fontWeight = "bold"; | |
h1.fontSize = 28; | |
h1.fontFamily = "Arial"; | |
h1.color = "#34486C"; | |
h1.textAlign = "left"; | |
h1.textIndent = 0; | |
var h3:Object = new Object(); | |
h3.fontWeight = "normal"; | |
h3.fontSize = 18; | |
h3.fontFamily = "Arial"; | |
h3.color = "#333333"; | |
h3.textAlign = "left"; | |
h3.textIndent = 0; | |
var a:Object = new Object(); | |
a.color = "#034486"; | |
style.setStyle("p", p); | |
style.setStyle("a", a); | |
style.setStyle("h1", h1); | |
style.setStyle("h3", h3); | |
/*Loads TextFields*/ | |
var head:TextField = new TextField(); | |
head.width = 600; | |
head.height = 40; | |
head.x = 0; | |
head.y = 455; | |
head.multiline = true; | |
head.wordWrap = true; | |
head.styleSheet = style; | |
head.condenseWhite = true; | |
head.selectable = false; | |
addChild(head); | |
var subhead:TextField = new TextField(); | |
subhead.width = 600; | |
subhead.height = 40; | |
subhead.x = 0; | |
subhead.y = 46; | |
subhead.multiline = true; | |
subhead.wordWrap = true; | |
subhead.styleSheet = style; | |
subhead.condenseWhite = true; | |
subhead.selectable = false; | |
//un-comment the line below to display the sub-head | |
//addChild(subhead); | |
var tf:TextField = new TextField(); | |
tf.width = 540; | |
tf.height = 300; | |
tf.x = 0; | |
tf.y = 490; | |
tf.multiline = true; | |
tf.wordWrap = true; | |
tf.styleSheet = style; | |
tf.condenseWhite = true; | |
tf.selectable = true; | |
addChild(tf); | |
/*Load XML*/ | |
var loader:URLLoader = new URLLoader(); | |
loader.addEventListener(Event.COMPLETE, onLoaded); | |
var xml:XML; | |
function onLoaded(e:Event):void { | |
xml = new XML(e.target.data); | |
//load text and additional data | |
head.text = xml.item.title[0]; | |
subhead.text = xml.item.subhead[0]; | |
tf.text = xml.item.description[0]; | |
} | |
//load actual xml, this could also be a url to xml file | |
loader.load(new URLRequest("text.xml")); | |
// | |
import fl.controls.ProgressBar; | |
import fl.transitions.Tween; | |
import fl.transitions.easing.*; | |
import fl.transitions.TweenEvent; | |
import flash.text.TextField; | |
import flash.text.TextFieldType; | |
var columns:Number; | |
var my_x:Number; | |
var my_y:Number; | |
var my_thumb_width:Number; | |
var my_thumb_height:Number; | |
var my_images:XMLList; | |
/*var my_credit:XMLList;1*/ | |
var my_total:Number; | |
var container_mc:MovieClip; | |
var preloaders_mc:MovieClip; | |
var full_mc:MovieClip; | |
var x_counter:Number = 0; | |
var y_counter:Number = 0; | |
var my_tweens:Array = []; | |
var container_mc_tween:Tween; | |
var full_tween:Tween; | |
var myXMLLoader:URLLoader = new URLLoader(); | |
/*Load style*/ | |
var credit_style:StyleSheet = new StyleSheet(); | |
var my_credit:TextField = new TextField(); | |
var h4:Object = new Object(); | |
h4.fontWeight = "normal"; | |
h4.fontSize = 14; | |
h4.fontFamily = "Arial"; | |
h4.color = "#333333"; | |
h4.textAlign = "center"; | |
h4.textIndent = 0; | |
credit_style.setStyle("h4", h4); | |
function createContainer():void { | |
container_mc = new MovieClip(); | |
container_mc.x = my_x; | |
container_mc.y = my_y; | |
addChild(container_mc); | |
container_mc.addEventListener(MouseEvent.CLICK, callFull); | |
container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver); | |
container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut); | |
container_mc.buttonMode = true; | |
preloaders_mc = new MovieClip(); | |
preloaders_mc.x = container_mc.x; | |
preloaders_mc.y = container_mc.y; | |
addChild(preloaders_mc); | |
} | |
function callThumbs():void { | |
for (var i:Number = 0; i < my_total; i++) { | |
var thumb_url = my_images[i].@THUMB; | |
var thumb_loader = new Loader(); | |
thumb_loader.load(new URLRequest(thumb_url)); | |
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); | |
thumb_loader.name = i; | |
thumb_loader.x = (my_thumb_width+10)*x_counter; | |
thumb_loader.y = (my_thumb_height+10)*y_counter; | |
if (x_counter+1 < columns) { | |
x_counter++; | |
} else { | |
x_counter = 0; | |
y_counter++; | |
} | |
var preloader_pb:ProgressBar = new ProgressBar(); | |
preloader_pb.source = thumb_loader.contentLoaderInfo; | |
preloader_pb.x = thumb_loader.x; | |
preloader_pb.y = thumb_loader.y; | |
preloader_pb.width = my_thumb_width; | |
preloader_pb.height = my_thumb_height; | |
preloaders_mc.addChild(preloader_pb); | |
preloader_pb.addEventListener(Event.COMPLETE, donePb); | |
} | |
} | |
function thumbLoaded(e:Event):void { | |
var my_thumb:Loader = Loader(e.target.loader); | |
container_mc.addChild(my_thumb); | |
my_tweens[Number(my_thumb.name)]=new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true); | |
my_thumb.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded); | |
} | |
function callFull(e:MouseEvent):void { | |
var full_loader:Loader = new Loader(); | |
var full_url = my_images[e.target.name].@FULL; | |
full_loader.load(new URLRequest(full_url)); | |
full_loader.contentLoaderInfo.addEventListener(Event.INIT, fullLoaded); | |
var full_pb:ProgressBar = new ProgressBar(); | |
full_pb.source = full_loader.contentLoaderInfo; | |
full_pb.x = 0; | |
full_pb.y = 200; | |
preloaders_mc.addChild(full_pb); | |
full_pb.width = 540; | |
full_pb.addEventListener(Event.COMPLETE, donePb); | |
container_mc.removeEventListener(MouseEvent.CLICK, callFull); | |
container_mc.buttonMode = false; | |
container_mc.removeEventListener(MouseEvent.MOUSE_OVER, onOver); | |
container_mc.removeEventListener(MouseEvent.MOUSE_OUT, onOut); | |
container_mc_tween = new Tween(container_mc, "alpha", Strong.easeIn, 1,0.1,0.1, true); | |
} | |
function fullLoaded(e:Event):void { | |
full_mc = new MovieClip(); | |
full_mc.buttonMode = true; | |
addChild(full_mc); | |
var my_loader:Loader = Loader(e.target.loader); | |
full_mc.addChild(my_loader); | |
full_tween = new Tween(my_loader, "alpha", Strong.easeIn, 0,1,0.5, true); | |
my_loader.x = (stage.stageWidth - my_loader.width)/2; | |
my_loader.y = (stage.stageHeight - my_loader.height)/2; | |
my_loader.addEventListener(MouseEvent.CLICK,removeFull); | |
my_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, fullLoaded); | |
/*my_credit.htmlText = "Photo Credit"*/ | |
/*my_credit.width = 300; | |
my_credit.height = 20; | |
my_credit.x = 700; | |
my_credit.y = 555; | |
my_credit.multiline = false; | |
my_credit.wordWrap = true; | |
my_credit.selectable = true; | |
my_credit.styleSheet = credit_style; | |
my_credit.condenseWhite = true; | |
addChild(my_credit);*/ | |
} | |
function removeFull(e:MouseEvent):void { | |
var my_loader:Loader = Loader (e.currentTarget); | |
full_tween = new Tween(my_loader, "alpha", Strong.easeOut, 1,0,0.5, true); | |
full_tween.addEventListener(TweenEvent.MOTION_FINISH, tweenFinished); | |
/* removeChild(my_credit)*/ | |
container_mc_tween = new Tween(container_mc, "alpha", Strong.easeOut, 0.5,1,0.5, true); | |
} | |
function donePb(e:Event):void { | |
var my_pb:ProgressBar = ProgressBar(e.target); | |
preloaders_mc.removeChild(my_pb); | |
my_pb.removeEventListener(Event.COMPLETE, donePb); | |
} | |
function tweenFinished(e:TweenEvent):void { | |
var my_loader:Loader = Loader (e.target.obj); | |
my_loader.unload(); | |
full_mc.removeChild(my_loader);// This line was removeChid(my_loader), just add full_mc before it. | |
removeChild(full_mc); | |
full_mc = null; | |
container_mc.addEventListener(MouseEvent.CLICK, callFull); | |
container_mc.buttonMode = true; | |
container_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver); | |
container_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut); | |
var my_tween:Tween = Tween(e.target); | |
my_tween.removeEventListener(TweenEvent.MOTION_FINISH, tweenFinished); | |
} | |
function onOver(e:MouseEvent):void { | |
var my_thumb:Loader = Loader(e.target); | |
my_thumb.alpha = 0.5; | |
} | |
function onOut(e:MouseEvent):void { | |
var my_thumb:Loader = Loader (e.target); | |
my_thumb.alpha = 1; | |
} | |
function processXML(e:Event):void { | |
var myXML:XML = new XML(e.target.data); | |
columns = myXML.@COLUMNS; | |
my_x = myXML.@XPOSITION; | |
my_y = myXML.@YPOSITION; | |
my_thumb_width = myXML.@WIDTH; | |
my_thumb_height = myXML.@HEIGHT; | |
my_images = myXML.IMAGE; | |
my_total = my_images.length(); | |
/* my_credit.htmlText = myXML.IMAGE.CREDIT[0];*/ | |
createContainer(); | |
callThumbs(); | |
myXMLLoader.removeEventListener(Event.COMPLETE, processXML); | |
myXMLLoader = null; | |
} | |
myXMLLoader.load(new URLRequest("gallery.xml")); | |
myXMLLoader.addEventListener(Event.COMPLETE, processXML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<GALLERY COLUMNS="5" XPOSITION="0" YPOSITION="0" WIDTH="100" HEIGHT="100"> | |
<IMAGE FULL="path to full image" THUMB="path to thumb nail" /> | |
<IMAGE FULL="path to full image" THUMB="path to thumb nail" /> | |
<IMAGE FULL="path to full image" THUMB="path to thumb nail" /> | |
<IMAGE FULL="path to full image" THUMB="path to thumb nail" /> | |
<IMAGE FULL="path to full image" THUMB="path to thumb nail" /> | |
</GALLERY> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="swf"> | |
<object height="620" width="600"> | |
<param name="movie" value="path_to_gallery.swf"/> | |
<a><embed height="620" width="600" src="path_to_gallery.swf"/></a> | |
</object> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<channel> | |
<title>Gallery Name (These four lines are not displayed they're just meta data that could be used by a cms)</title> | |
<link>http://samplepage.html</link> | |
<description>Gallery of something</description> | |
<pub_date>2009-12-31</pub_date> | |
<item> | |
<title><h1>This is a title or headline</h1></title> | |
<link></link> | |
<subhead><h3>This is subhead or this could be used as a byline</h3></subhead> | |
<description> | |
<p>Sample body text <b><u><a href="http://blog.jmelgoza.com">with a link</a></u></b>. Have Fun!</p> | |
</description> | |
<lead_image> | |
</lead_image> | |
</item> | |
</channel> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment