0 Replies - 1245 Views - Last Post: 16 February 2012 - 09:46 PM

#1 Whack-A-Code  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-February 12

Flash and XML slideshow not working with links

Posted 16 February 2012 - 09:46 PM

Hi! Hopefully someone here can help, I've posted on a few forums to no avail.
The problem:
I used a tutorial to make a slideshow that uses XML to grab images so I don't have to re-make the swf for every change. It worked well and then I added an invisible overlay to link to the appropriate page for what slide is showing. And then it stops working. The swf loads, and I know that the links work because I'm sent to the default location, but the images no longer show and the link doesn't change. My only hunch is that it's a problem with relative/absolute links, but I've tried lots of combinations of them. Any info on where the error lies or a flash-based workaround would be great, as I've got temporary links below the slideshow, but I'm not satisfied with it. I really want to understand what I'm doing wrong. Please let me know if you need anything else.

website with the temp. solution: www.diamondraindesign.com

Problem code:

XML
<?xml version="1.0" encoding="utf-8"?>
<SLIDESHOW SPEED="2">
<IMAGE URL="slideshow/images/image1.jpeg" />
<IMAGE URL="slideshow/images/image2.jpeg" />
<IMAGE URL="slideshow/images/image3.jpeg" />
<IMAGE URL="slideshow/images/image4.jpeg" />
<IMAGE URL="slideshow/images/image5.jpeg" />
</SLIDESHOW>


SWF
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var my_speed:Number;
var my_total:Number;
var my_images:XMLList;

var my_loaders_array:Array = [];
var my_success_counter:Number = 0;
var my_playback_counter:Number = 0;

var my_slideshow:Sprite = new Sprite();
var my_image_slides:Sprite = new Sprite();
var my_preloader:TextField;

var my_timer:Timer;
/*cleanup*/var my_prev_tween:Tween;

var my_xml_loader:URLLoader = new URLLoader();
my_xml_loader.load(new URLRequest("http://www.diamondraindesign.com/slideshow/slideshow.xml"));
my_xml_loader.addEventListener(Event.COMPLETE, processXML);

function processXML (e:Event):void{
var my_xml:XML = new XML(e.target.data);
my_speed=my_xml.@SPEED; 
my_images=my_xml.IMAGE; 
my_total=my_images.length();
loadImages();
my_xml_loader.removeEventListener(Event.COMPLETE, processXML); 
my_xml_loader = null;
}

function loadImages():void{
for (var i:Number = 0; i < my_total; i++){ 

var my_url:String = my_images[i].@URL;
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest(my_url));
my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
my_loaders_array.push(my_loader);

my_preloader = new TextField();
my_preloader.text="Loading";
my_preloader.autoSize = TextFieldAutoSize.CENTER;
my_preloader.x = (stage.stageWidth - my_preloader.width)/2;
my_preloader.y = (stage.stageHeight - my_preloader.height)/2;
addChild(my_preloader);
} 
}

function onComplete(e:Event):void{
my_success_counter++;
if (my_success_counter == my_total){
startShow();
}
var my_loaderInfo:LoaderInfo = LoaderInfo(e.target); 
my_loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
}

function startShow():void{
removeChild(my_preloader);
my_preloader = null;
addChild(my_slideshow);
my_slideshow.addChild(my_image_slides);
nextImage();
my_timer = new Timer(my_speed*2000);
my_timer.addEventListener(TimerEvent.TIMER, timerListener);
my_timer.start();
}

function nextImage():void{
var my_image:Loader = Loader(my_loaders_array[my_playback_counter]);
my_image_slides.addChild(my_image);
my_image.x = (stage.stageWidth - my_image.width)/2;
my_image.y = (stage.stageHeight - my_image.height)/2;
new Tween(my_image,"x",Regular.easeInOut,640,0,1.5,true);
}

function timerListener (e:TimerEvent):void{
hidePrev();

my_playback_counter++;
if (my_playback_counter == my_total){
my_playback_counter =0;
}
nextImage();
}

//cleanup
function hidePrev():void{

var my_image:Loader=Loader(my_image_slides.getChildAt(0)); 
my_prev_tween = new Tween(my_image,"x",Regular.easeInOut,0,-640,1.5,true); 
my_prev_tween.addEventListener(TweenEvent.MOTION_FINISH, onSlideOut) 
}

function onSlideOut(e:TweenEvent):void{
my_image_slides.removeChildAt(0);
}

Link1.addEventListener(MouseEvent.CLICK, onclick);
function onclick(e:MouseEvent):void{
if (my_playback_counter == 0){
navigateToURL(new URLRequest("http://www.diamondraindesign.com/item/bear.html"), "_self")}
if (my_playback_counter == 1){
navigateToURL(new URLRequest("http://www.diamondraindesign.com/item/chromalux.html"), "_self")}
if (my_playback_counter == 2){
navigateToURL(new URLRequest("http://www.diamondraindesign.com/item/bachelorette.html"), "_self")}
if (my_playback_counter == 3){
navigateToURL(new URLRequest("http://www.diamondraindesign.com/item/lighter.html"), "_self")}
if (my_playback_counter == 4){
navigateToURL(new URLRequest("http://www.diamondraindesign.com/item/wineglass.html"), "_self")}
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1