Jump to content

dynamic slideshow issue...


Greywacke
 Share

Recommended Posts

hi there,i have created the following actionscript to load the images and slideshow info from an xml document and it is located on frame 1 in one of the layers:

import flash.events.Event;import flash.net.URLLoader;import flash.net.URLRequest;import flash.display.Loader;import flash.utils.Timer;import flash.events.TimerEvent;import flash.display.Sprite;var imagesXML:XML;var xmlLoader:URLLoader = new URLLoader();var imageLoader = new Array();var imageHolder = new Array();var imageTimer:Timer;var n:uint;xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);xmlLoader.load(new URLRequest("img.xml"));function xmlLoaded(e:Event):void {	imagesXML = new XML(xmlLoader.data);	n = imagesXML.pic.length() - 1;	trace((uint(n)+1) + " images detected");	for (var i:uint = 0; i < imagesXML.pic.length(); i++) {		imageLoader[i] = new Loader();		imageHolder[i] = new Sprite();		imageLoader[i].contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);		imageLoader[i].load(new URLRequest(imagesXML.pic[i].@path));		imageLoader[i].x = 0;		imageLoader[i].y = 0;		imageLoader[i].width = 378;		imageLoader[i].height = 231;		imageHolder[i].addChild(imageLoader[i]);		imageLoader[i].visible = true;		imageHolder[i].x = 13;		imageHolder[i].y = 0;		imageHolder[i].width = 378;		imageHolder[i].height = 231;		addChild(imageHolder[i]);		imageHolder[i].visible = true;		setChildIndex(imageHolder[i],i+1);		trace(imagesXML.pic[i].@path + " loaded");	}	imageTimer = new Timer(uint(imagesXML.delay[0].@len)*1000);	trace(imagesXML.delay[0].@len + " seconds");	imageTimer.addEventListener(TimerEvent.TIMER, nextImage);}function showImage(e:Event = null) {	nextImage();	imageTimer.start();}function nextImage(e:TimerEvent = null):void {	//loader_mc.visible = false;	if (n >= imageHolder.count) { n = 0; } else { n++; }	for (var i:uint = 0; i < imageLoader.length; i++) {		if (i == n) { imageHolder[i].visible = true; }		else { imageHolder[i].visible = false; }	}}stop();

the xml that is loaded is as follows:

<pics>	<delay len="5"/>	<pic path="000.jpg"/>	<pic path="001.jpg"/>	<pic path="002.jpg"/>	<pic path="003.jpg"/>	<pic path="004.jpg"/>	<pic path="005.jpg"/>	<pic path="006.jpg"/>	<pic path="007.jpg"/>	<pic path="008.jpg"/>	<pic path="009.jpg"/>	<pic path="010.jpg"/>	<pic path="011.jpg"/>	<pic path="012.jpg"/>	<pic path="013.jpg"/>	<pic path="014.jpg"/>	<pic path="015.jpg"/></pics>

and the trace output is as follows:

16 images:	 000.jpg	 001.jpg	 002.jpg	 003.jpg	 004.jpg	 005.jpg	 006.jpg	 007.jpg	 008.jpg	 009.jpg	 010.jpg	 011.jpg	 012.jpg	 013.jpg	 014.jpg	 015.jpg5 seconds delayTypeError: Error #1010: A term is undefined and has no properties.	at slideshow_fla::MainTimeline/nextImage()	at slideshow_fla::MainTimeline/xmlLoaded()	at flash.events::EventDispatcher/dispatchEventFunction()	at flash.events::EventDispatcher/dispatchEvent()	at flash.net::URLLoader/onComplete()

can anyone see what i am missing here? where does my clarity need to focus? this needs to be completed soon! :)

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

sighs... somebody please help here? :Si have updated the code as follows - but now there are no errors and the following is traced:

import flash.events.Event;import flash.net.URLLoader;import flash.net.URLRequest;import flash.display.Loader;import flash.utils.Timer;import flash.events.TimerEvent;import flash.display.Sprite;var imagesXML:XML;var xmlLoader:URLLoader = new URLLoader();var imageLoader = new Array();var imageHolder = new Array();var imageTimer:Timer;var n:uint;xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);xmlLoader.load(new URLRequest("img.xml"));function xmlLoaded(e:Event):void {    imagesXML = new XML(xmlLoader.data);    n = imagesXML.pic.length() - 1;    trace((uint(n)+1) + " images detected");    for (var i:uint = 0; i < imagesXML.pic.length(); i++) {        imageLoader[i] = new Loader();		imageLoader[i].x = 0;		imageLoader[i].y = 0;		imageLoader[i].width = 378;		imageLoader[i].height = 231;		imageHolder[i] = new Sprite();        imageHolder[i].x = 13;        imageHolder[i].y = 0;		imageHolder[i].width = 378;		imageHolder[i].height = 231;		if (i == n) {			imageLoader[i].contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);		}        imageLoader[i].load(new URLRequest(imagesXML.pic[i].@path));		imageLoader[i].visible = true;		addChild(imageHolder[i]);        imageHolder[i].addChild(imageLoader[i]);        imageHolder[i].visible = true;		setChildIndex(imageHolder[i],i+2);        trace(imagesXML.pic[i].@path + " loaded");    }    imageTimer = new Timer(uint(imagesXML.delay[0].@len)*1000);    trace(imagesXML.delay[0].@len + " second interval");    imageTimer.addEventListener(TimerEvent.TIMER, nextImage);}function showImage(e:Event = null) {	imageTimer.start();	nextImage();}function nextImage(e:TimerEvent = null):void {	loader_mc.visible = false;    if (n >= imageHolder.count) { n = 0; } else { n++; }    for (var i:uint = 0; i < imageHolder.length; i++) {        if (i == n) { imageHolder[i].visible = true; } else { imageHolder[i].visible = false; }    }}stop();

16 images detected000.jpg loaded001.jpg loaded002.jpg loaded003.jpg loaded004.jpg loaded005.jpg loaded006.jpg loaded007.jpg loaded008.jpg loaded009.jpg loaded010.jpg loaded011.jpg loaded012.jpg loaded013.jpg loaded014.jpg loaded015.jpg loaded5 seconds interval

what's more is that it refuses to display any images! 0oi am in dire straits here, could somebody please lend me their clarity?

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

ok, after some research into loading bitmap data from a lloader into a sprite, i came up with the following code.

import flash.events.Event;import flash.net.URLLoader;import flash.net.URLRequest;import flash.display.Loader;import flash.utils.Timer;import flash.events.TimerEvent;import flash.display.Sprite;import flash.display.Bitmap;import flash.display.BitmapData;var imagesXML:XML;var xmlLoader:URLLoader = new URLLoader();var imageLoader:Loader = new Loader();imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);var imageHolder = new Array();var imageTimer:Timer;var img = new Array();var delay:uint;var n:uint;var d:uint;xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);xmlLoader.load(new URLRequest("img.xml"));function xmlLoaded(e:Event = null):void {    imagesXML = new XML(xmlLoader.data);    n = imagesXML.pic.length() - 1;    trace((uint(n)+1) + " images detected");    for (var i:uint = 0; i < imagesXML.pic.length(); i++) {		img[i] = imagesXML.pic[i].@path;        trace(img[i] + " noted");    }	imageLoader.load(new URLRequest(img[d]));	delay = uint(imagesXML.delay[0].@len);    imageTimer = new Timer(delay*1000);    trace(delay + " seconds interval");    imageTimer.addEventListener(TimerEvent.TIMER, nextImage);}function showImage(e:Event = null):void {	var tempBitmap:Bitmap = e.target.content;	var tempBitmapData:BitmapData = tempBitmap.bitmapData;	imageHolder[d] = new Sprite();	var loadBitmap:Bitmap = new Bitmap(tempBitmapData);	imageHolder[d].addChild(loadBitmap);	trace(img[d] + " loaded");	d++;	if (d == img.length) {		imageTimer.start();		nextImage();	} else {		imageLoader.load(new URLRequest(img[d]));	}}function nextImage(e:TimerEvent = null):void {    if (n >= imageHolder.count) { n = 0; loader_mc.visible = false; } else { n++; }    for (var i:uint = 0; i < imageHolder.length; i++) {        if (i == n) { imageHolder[i].visible = true; } else { imageHolder[i].visible = false; }    }}stop();

however - it now spits out the following in output:

16 images detected000.jpg noted001.jpg noted002.jpg noted003.jpg noted004.jpg noted005.jpg noted006.jpg noted007.jpg noted008.jpg noted009.jpg noted010.jpg noted011.jpg noted012.jpg noted013.jpg noted014.jpg noted015.jpg noted5 seconds interval000.jpg loaded001.jpg loaded002.jpg loaded003.jpg loaded004.jpg loaded005.jpg loaded006.jpg loaded007.jpg loaded008.jpg loaded009.jpg loaded010.jpg loaded011.jpg loaded012.jpg loaded013.jpg loaded014.jpg loaded015.jpg loaded

no compiler errors nor errors in output :/

Link to comment
Share on other sites

it loads the first image and stops there, nonregard of the timer object to change them... :)View "Slideshow"but loads the other images a few times over in the background... why oh why will the sprites not swop visibility? 0o

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

woohooo!!! issue has now been RESOLVED :)success at last... hehe perseverance does pay off!!! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...