5 Replies - 1593 Views - Last Post: 16 February 2007 - 11:09 AM

#1 44corners  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 243
  • Joined: 22-February 06

back button problems after creating empty mc

Posted 30 January 2007 - 04:20 PM

I followed a tutorial at gotoandlearn.com for dynamically adding images into flash via xml. Everything worked fine. Then I modified the script (SLIGHTLY) so that actionscript generated the mc that the photos were being loaded into, but now the back button doesn't work. The only problem is the back button. Everythin else including images load in fine, next button works fine, etc.

Here's the working code:
//--------load in XML--------//
var x:XML = new XML();
x.ignoreWhite = true;//ignores white space in xml document

var urls:Array = new Array();//stores all urls for photos
var captions:Array = new Array();//holds captions read from xml
var currentImage:Number; //keeps track of which photo is currently being displayed (index number)

x.onload = function() {
	var photos:Array = this.firstChild.childNodes;	//firstChild = root element of xml document - childnodes returns array of all nested elements within there
	for (i=0;i<photos.length;i++) {					//iterates through photos to process them
		urls.push(photos[i].attributes.url);		//put url and caption into arrays - "push" tags onto end of array
		captions.push(photos[i].attributes.caption);
	}
	holder.loadMovie(urls[0]); //loads first pic
	caption.text = captions[0];//gives first element for when first go into movie
	currentImage = 0; //because first photo is displayed
}

x.load("folio.xml");

//--------Set up buttons--------//
previous.onRelease = function() { //prevoius button
	if(currentImage > 0) { //if first photo is being displayed don't want previous button to do anything
		currentImage--; //decrement by one (subtract one from who is on)
		holder.loadMovie(urls[currentImage]);//load new photo into holder
		caption.text = captions[currentImage];
	}
}

next.onRelease = function() { //prevoius button
	if(currentImage < urls.length-1) { //.length tell how many in xml - -1 for array index number
		currentImage++; //increment by one (subtract one from who is on)
		holder.loadMovie(urls[currentImage]);
		caption.text = captions[currentImage];
	}
}




Here's the code where the back button fails:

//--------load in XML--------//
var x:XML = new XML();
x.ignoreWhite = true;//ignores white space in xml document
x.load("folio.xml");

var urls:Array = new Array();//stores all urls for photos
var captions:Array = new Array();//holds captions read from xml
var currentImage:Number;//keeps track of which photo is currently being displayed (index number)

x.onload = function() {
	var photos:Array = this.firstChild.childNodes;	//firstChild = root element of xml document - childnodes returns array of all nested elements within there
	for (i=0; i<photos.length; i++) {		//iterates through photos to process them
		urls.push(photos[i].attributes.url);//put url and caption into arrays - "push" tags onto end of array
		captions.push(photos[i].attributes.caption);
	}
	_root.createEmptyMovieClip("holder", 1);//create the mc into which photos go
	holder._x = holder._y=220;//image position
	holder.loadMovie(urls[0]);	//loads first pic (index number 0)
	caption.text = captions[0];	//loads first caption to go with image
	currentImage = 0;	//because first photo is displayed
};


//--------Set up buttons--------//


next.onRelease = function() { //next button
	if(currentImage < urls.length-1) { //.length tell how many in xml - -1 for array index number
		currentImage++; //increment by one (subtract one from who is on)
		holder.loadMovie(urls[currentImage]);
		caption.text = captions[currentImage];
	}
}

previous.onRelease = function() { //prevoius button
	if(currentImage > 0) { //if first photo is being displayed don't want previous button to do anything
		currentImage--; //decrement by one (subtract one from who is on)
		holder.loadMovie(urls[currentImage]);//load new photo into holder
		caption.text = captions[currentImage];
	}
}


Why doesn't this work?

Is This A Good Question/Topic? 0
  • +

Replies To: back button problems after creating empty mc

#2 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: back button problems after creating empty mc

Posted 30 January 2007 - 04:28 PM

i think you are having problems with loadMovie ... if you check your debugger, you'll see why it's not working (ctrl+shift+enter i think)

the solution is to use MovieClipLoader class.. research it...


hth
Was This Post Helpful? 0
  • +
  • -

#3 44corners  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 243
  • Joined: 22-February 06

Re: back button problems after creating empty mc

Posted 30 January 2007 - 04:51 PM

"Debugger" - are you referring to the output panel?
Was This Post Helpful? 0
  • +
  • -

#4 44corners  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 243
  • Joined: 22-February 06

Re: back button problems after creating empty mc

Posted 31 January 2007 - 02:44 AM

I'm still stuck on this. I don't know what else you could mean when you say look at the debugger - Flash says the script (syntax) is written correctly and the output panel is showing no errors.
Was This Post Helpful? 0
  • +
  • -

#5 44corners  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 243
  • Joined: 22-February 06

Re: back button problems after creating empty mc

Posted 31 January 2007 - 08:11 AM

As it turns out I made a typo in the instance name of my previous button.

Thanks anyway.
Was This Post Helpful? 0
  • +
  • -

#6 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: back button problems after creating empty mc

Posted 16 February 2007 - 11:09 AM

typos suck.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1