xml gallery
I have a gallery that malfunctions some of the time when you try to explore my website. it is some what complicated to explain so I will describe my set up with the assistance of my code.
SWF file contains this code on the hompage frame:
////BUTTONS//////
stop();
//-----Navigation Buttons ------------//
home_btn.addEventListener(MouseEvent.CLICK, homeclick);
function homeclick(event:MouseEvent):void
{
gotoAndStop(2);
if(img_holder.stage)
{
removeChild(img_holder);
}
}
port_btn.addEventListener(MouseEvent.CLICK, portclick);
function portclick(event:MouseEvent):void
{
gotoAndStop(3);
}
abou_btn.addEventListener(MouseEvent.CLICK, abouclick);
function abouclick(event:MouseEvent):void
{
gotoAndStop(8);
if(img_holder.stage)
{
removeChild(img_holder);
}
}
blog_btn.addEventListener(MouseEvent.CLICK, blogclick);
function blogclick(event:MouseEvent):void
{
gotoAndStop(9);
if(img_holder.stage)
{
removeChild(img_holder);
}
}
cont_btn.addEventListener(MouseEvent.CLICK, contclick);
function contclick(event:MouseEvent):void
{
gotoAndStop(10);
if(img_holder.stage)
{
removeChild(img_holder);
}
}
On my gallery/home page the code looks like:
/////gallery buttons/////////
gal1_btn.addEventListener(MouseEvent.CLICK, gal1click);
function gal1click(event:MouseEvent):void
{
gotoAndStop(4);
}
gal2_btn.addEventListener(MouseEvent.CLICK, gal2click);
function gal2click(event:MouseEvent):void
{
gotoAndStop(5);
}
gal3_btn.addEventListener(MouseEvent.CLICK, gal3click);
function gal3click(event:MouseEvent):void
{
gotoAndStop(6);
}
gal4_btn.addEventListener(MouseEvent.CLICK, gal4click);
function gal4click(event:MouseEvent):void
{
gotoAndStop(7);
}
once you've selected a gallery it takes you to that specific gallery.. i have four of them, but gal1 is the only one with as3 because i wanted to get the bugs sorted out before continuing with the other three. The as3 code lookes like this in gallery1:
var xml:XML = new XML();
var img_count:uint;
var loader:URLLoader = new URLLoader();
var img_holder:Sprite=new Sprite();
var sw:Number=stage.stageWidth;
addChild(img_holder);
function xmlloaded(e:Event):void
{
xml=XML(e.target.data);
img_count = xml.img.length()-1;
for (var i:uint = 0; i<img_count; i++)
{
var thumb:Sprite=new createThumb(img_holder,String(xml.img.@thumburl),String(xml.img.@mainurl));
thumb.x=130*i;
img_holder.addChild(thumb);
}
stage.addEventListener(Event.ENTER_FRAME,mousescroll);
}
function mousescroll(e:Event):void
{
var ihw:Number = (img_holder.width-sw+350)*-1;
var percent:Number = 175+(mouseX/sw)*(ihw);
img_holder.x=percent;
}
loader.load(new URLRequest('photogallery.xml'));
loader.addEventListener(Event.COMPLETE,xmlloaded);
this code calls to an outside xml file, which looks like this:
var img_holder:Sprite=new Sprite();
var thumb:Sprite=new createThumb(img_holder,'smallimage/file.png','largeimage/file.png');
thumb.x=205*i;
img_holder.addChild(thumb);
addChild(img_holder);
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.Bitmap;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLRequest;
public class createThumb extends Sprite {
private var arraytween:Array = new Array();
private var thumb_loader:Loader;
private var photo_loader:Loader;
private var thumb_url:String;
private var photo_url:String;
private var thumb_bit:Bitmap;
private var photo_bit:Bitmap;
private var mother:Sprite;
private var thumb_btn:Sprite;
public function createThumb(childof:Sprite,thumburl:String,photourl:String) {
mother=childof;
thumb_url=thumburl;
photo_url=photourl;
loadthumb();
}
private function loadthumb():void {
thumb_loader = new Loader();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,displaythumb);
}
private function displaythumb(e:Event):void {
thumb_btn = new Sprite();
thumb_bit= new Bitmap();
thumb_btn.y=(stage.stageHeight-thumb_btn.height)/1.25;
thumb_btn.graphics.beginFill(0x000000,0);
thumb_btn.graphics.drawRect(0,0,125,125);
thumb_btn.graphics.endFill();
thumb_bit=e.target.content as Bitmap;
thumb_bit.y=(stage.stageHeight-thumb_bit.height)/1.045;
thumb_btn.width=thumb_btn.height=thumb_bit.width=thumb_bit.height=125;
thumb_bit.smoothing=true;
addChild(thumb_bit);
addChild(thumb_btn);
thumb_btn.addEventListener(MouseEvent.CLICK,loadphoto);
}
private function loadphoto(e:Event):void {
arraytween.push(new Tween(mother,"y",Regular.easeOut,mother.y,0,.5,true));
photo_loader = new Loader();
photo_loader.load(new URLRequest(photo_url));
photo_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,displayphoto);
}
private function displayphoto(e:Event):void {
stage.addEventListener(MouseEvent.CLICK,closephoto);
photo_bit= new Bitmap();
photo_bit=e.target.content as Bitmap;
photo_bit.smoothing=true;
photo_bit.x=(192);
photo_bit.y=(110);
stage.addChild(photo_bit);
}
private function closephoto(e:Event):void
{
arraytween.push(new Tween(mother,"y",Strong.easeOut,mother.y,0,.5,true));
arraytween[arraytween.length-1].addEventListener(TweenEvent.MOTION_FINISH,cleartween);
photo_loader.unload();
if(photo_bit.stage)
{
stage.removeChild(photo_bit);
}
stage.removeEventListener(MouseEvent.CLICK,closephoto);
//if (photo_bit != null)
//{
// stage.removeChild(photo_bit);
//}
}
private function cleartween(e:TweenEvent):void
{
arraytween=[];
}
}
}
thats all of it.. my specific problem can be seen at www.bradleyferguson.com
play around with the 1st gallery which is located under portfolio and is in red.. you'll see what im talking about.