Solved

Actionscript 2 looping through xml nodes to pull according to button selection

Posted on 2009-03-30
2
1,012 Views
Last Modified: 2013-11-11
I have eight INFO buttons that once you click pulls up a popup/Movie clip with a picture, title, and description being pulled from an xml file. My next button doesn't seem to work either.

I want to be able to tell which xml nodes to pull based on which INFO button is pressed.

sample work: http://www.smooth-ness.com/flash.html

Select "Terrace Options" Then at the bottom the "INFO" button. There will be an info button by all items listed.
function loadXML(loaded) {
 
if (loaded) {
 
xmlNode = this.firstChild;
image = [];
titlehere = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
 
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
titlehere[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
 
}
firstImage();
 
} else {
 
content = "file not loaded!";
 
}
 
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
/////////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
 
if (Key.getCode() == Key.LEFT) {
 
prevImage();
 
} else if (Key.getCode() == Key.RIGHT) {
 
nextImage();
 
}
 
};
Key.addListener(listen);
previous_btn.onRelease = function() {
 
prevImage();
 
};
next_btn.onRelease = function() {
trace(clicked);
nextImage();
 
};
/////////////////////////////////////
p = 0;
this.onEnterFrame = function() {
 
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
 
preloader.preload_bar._xscale = 100*loaded/filesize;
 
} else {
 
preloader._visible = false;
if (picture._alpha<100) {
 
picture._alpha += 10;
 
}
 
}
 
};
function nextImage() {
 
if (p<(total-1)) {
 
p++;
if (loaded == filesize) {
 
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
title_txt.text = titlehere[p];
 
picture_num();
 
}
 
}
 
}
function prevImage() {
 
if (p>0) {
 
p--;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
title_txt.text = titlehere[p];
 
picture_num();
 
}
 
}
function firstImage() {
 
if (loaded == filesize) {
 
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
title_txt.text = titlehere[1];
picture_num();
 
}
 
}
function picture_num() {
 
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
 
}

Open in new window

0
Comment
Question by:smoothmonster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 24026282
your code seems to be assuming a normal increment, i'm assuming this is not the case. as the user may not press them in order.
so you don't really want a next / back options rather just click and activate.

so easiest way it to give your buttons names like btn1 btn2 etc. then pull the number from that button name you can use substring (check help file) - then parse that into your arrays (-1 if you're using 1 index) instead of using that p counter.

ie.


btn1.onRelease = function() {
	var num:Number = this._name.substr(3,1);
	trace(num);
	doImage(num);
}
 
function doImage(which:Number) {
	//assuming you're using 1 index.
	var num:Number = which - 1;
	picture.loadMovie(image[num], 1);
	desct_txt.text = description[num];
}

Open in new window

0
 

Author Closing Comment

by:smoothmonster
ID: 31564538
Thanks blue-genie, I needed a place to start and this gets me on the right path. Thank you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question